installJRMC 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785
  1. #!/usr/bin/env bash
  2. # Install JRiver Media Center and associated services
  3. # See installJRMC --help or printHelp() below
  4. #
  5. # Copyright (c) 2021-2023 Bryan C. Roessler
  6. # This software is released under the Apache License.
  7. # https://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # TODO (v1.1)
  10. # 1. Interactive mode
  11. # 2. Additional containerization (createrepo and rpmbuild)
  12. # 3. Tests
  13. #
  14. # BUGS
  15. # 1. No createrepo on Mint
  16. shopt -s extglob
  17. declare -g SCRIPTVERSION="1.0-dev"
  18. declare -g SCRIPTDIR=; SCRIPTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  19. declare -g OUTPUTDIR="$SCRIPTDIR/output"
  20. declare -g BOARDURL="https://yabb.jriver.com/interact/index.php/board,76.0.html" # MC30
  21. declare -g DEBIANBASE="buster"
  22. declare -g MCVERSION_HARDCODE="${MCVERSION:-"30.0.72"}" # Hardcoded fallback
  23. declare -g CREATEREPO_WEBROOT="/var/www/jriver"
  24. declare -g USER="${SUDO_USER:-$USER}"
  25. declare -g HOME; HOME=$(getent passwd "$USER" | cut -d: -f6)
  26. printHelp() {
  27. debug "Running: ${FUNCNAME[0]}"
  28. cat <<-'EOF'
  29. USAGE:
  30. installJRMC [[OPTION] [VALUE]]...
  31. If no options (excluding -d or --debug) are provided installJRMC defaults to '--install repo'.
  32. OPTIONS
  33. --install, -i repo|local
  34. repo: Install MC from repository, updates are handled by the system package manager
  35. local: Build and install MC package locally from official source release
  36. --build[=suse|fedora|centos]
  37. Build RPM from source DEB but do not install
  38. Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
  39. --compat
  40. Build/install MC locally without minimum dependency version requirements
  41. --mcversion VERSION
  42. Specify the MC version, ex. "30.0.72" (default: latest version)
  43. --arch VERSION
  44. Specify the MC architecture, ex. "amd64", "arm64", etc (default: host architecture)
  45. --outputdir PATH
  46. Generate rpmbuild output in this directory (default: ./output)
  47. --restorefile RESTOREFILE
  48. Restore file location for automatic license registration
  49. --betapass PASSWORD
  50. Enter beta team password for access to beta builds
  51. --service, -s SERVICE
  52. See SERVICES section below for a list of possible services to install
  53. --service-type user|system
  54. Starts services at boot (system) or at user login (user) (default: per service, see SERVICES)
  55. --container, -c CONTAINER (TODO: Under construction)
  56. See CONTAINERS section below for a list of possible services to install
  57. --createrepo[=suse|fedora|centos]
  58. Build rpm, copy to webroot, and run createrepo.
  59. Use in conjunction with --build=TARGET for crossbuilding repos
  60. Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
  61. --createrepo-webroot PATH
  62. Specify the webroot directory to install the repo (default: /var/www/jriver)
  63. --createrepo-user USER
  64. Specify the web server user if it differs from $USER
  65. --uninstall, -u
  66. Uninstall JRiver MC, remove services, containers, and firewall rules (does not remove library files)
  67. --yes, -y
  68. Always assume yes for questions
  69. --version, -v
  70. Print this script version and exit
  71. --debug, -d
  72. Print debug output
  73. --help, -h
  74. Print help dialog and exit
  75. SERVICES
  76. jriver-mediaserver (default --service-type=user)
  77. Enable and start a mediaserver systemd service (requires an existing X server)
  78. jriver-mediacenter (user)
  79. Enable and start a mediacenter systemd service (requires an existing X server)
  80. jriver-x11vnc (user)
  81. Enable and start x11vnc for the local desktop (requires an existing X server)
  82. Usually combined with jriver-mediaserver or jriver-mediacenter services
  83. --vncpass and --display are optional (see below)
  84. jriver-xvnc (system)
  85. Enable and start a new Xvnc session running JRiver Media Center
  86. --vncpass PASSWORD
  87. Set the vnc password for x11vnc/Xvnc access. If no password is set, installJRMC
  88. will either use existing password stored in $HOME/.vnc/jrmc_passwd or use no password
  89. --display DISPLAY
  90. Display to use for x11vnc/Xvnc (default: The current display (x11vnc) or the
  91. current display incremented by 1 (Xvnc))
  92. jriver-createrepo (system)
  93. Install hourly service to build latest MC RPM and run createrepo
  94. CONTAINERS (TODO: Under construction)
  95. mediacenter-xvnc
  96. createrepo
  97. EOF
  98. }
  99. # Helpers
  100. debug() { (( DEBUG )) && echo "Debug: $*"; }
  101. err() { echo "Error: $*" >&2; }
  102. askOk() {
  103. declare response
  104. (( YES_SWITCH )) && return 0
  105. read -r -p "$* [y/N]: " response
  106. [[ "${response,,}" =~ ^(yes|y)$ ]]
  107. }
  108. execute() {
  109. if debug "$*"; then
  110. eval "$*"
  111. else
  112. eval "$* &>/dev/null"
  113. fi
  114. }
  115. #######################################
  116. # Parses user input and sets sensible defaults
  117. #######################################
  118. parseInput() {
  119. debug "Running: ${FUNCNAME[0]}"
  120. declare -g BUILD_SWITCH REPO_INSTALL_SWITCH COMPAT_SWITCH TEST_SWITCH
  121. declare -g LOCAL_INSTALL_SWITCH CREATEREPO_SWITCH UNINSTALL_SWITCH YES_SWITCH
  122. declare -g USER_VERSION_SWITCH USER_ARCH
  123. declare -g OUTPUTDIR RESTOREFILE BETAPASS SERVICE_TYPE
  124. declare -g VNCPASS USER_DISPLAY CREATEREPO_WEBROOT
  125. declare -ga SERVICES CONTAINERS
  126. declare long_opts short_opts input
  127. # Allow some environment variables to override and set sane fallbacks
  128. declare -g TARGET=${TARGET:-$ID}
  129. declare -g CREATEREPO_USER="${CREATEREPO_USER:-$USER}"
  130. if [[ $# -eq 0 ]] || [[ $# -eq 1 && " $1 " =~ ^( --debug | -d )$ ]]; then
  131. REPO_INSTALL_SWITCH=1
  132. elif [[ $# -eq 1 && " $1 " =~ ^( --compat )$ ]]; then
  133. BUILD_SWITCH=1
  134. LOCAL_INSTALL_SWITCH=1
  135. fi
  136. long_opts="install:,build::,outputdir:,mcversion:,restorefile:,betapass:,"
  137. long_opts+="service-type:,service:,services:,version,debug,help,uninstall,"
  138. long_opts+="createrepo::,createrepo-webroot:,createrepo-user:,"
  139. long_opts+="vncpass:,display:,container:,tests,compat,arch:,yes"
  140. short_opts="+i:vb::dhus:c:"
  141. # Redeclare DEBUG and catch permanently with getopt
  142. declare -g DEBUG=0
  143. if input=$(getopt -o $short_opts -l $long_opts -- "$@"); then
  144. eval set -- "$input"
  145. while true; do
  146. case "$1" in
  147. --install|-i)
  148. shift
  149. case "$1" in
  150. local|rpm)
  151. BUILD_SWITCH=1
  152. LOCAL_INSTALL_SWITCH=1
  153. ;;
  154. repo|remote)
  155. REPO_INSTALL_SWITCH=1
  156. ;;
  157. esac
  158. ;;
  159. --build|-b)
  160. BUILD_SWITCH=1
  161. shift && TARGET="$1"
  162. ;;
  163. --outputdir)
  164. shift && OUTPUTDIR="$1"
  165. ;;
  166. --mcversion)
  167. shift
  168. MCVERSION="$1"
  169. USER_VERSION_SWITCH=1
  170. ;;
  171. --arch)
  172. shift
  173. USER_ARCH="$1"
  174. ;;
  175. --restorefile)
  176. shift && RESTOREFILE="$1"
  177. ;;
  178. --betapass)
  179. shift && BETAPASS="$1"
  180. ;;
  181. --service-type)
  182. shift && SERVICE_TYPE="$1"
  183. ;;
  184. --service|-s|--services)
  185. shift && SERVICES+=("$1")
  186. ;;
  187. --createrepo)
  188. BUILD_SWITCH=1
  189. CREATEREPO_SWITCH=1
  190. shift && TARGET="$1"
  191. ;;
  192. --createrepo-webroot)
  193. shift && CREATEREPO_WEBROOT="$1"
  194. ;;
  195. --createrepo-user)
  196. shift && CREATEREPO_USER="$1"
  197. ;;
  198. --vncpass)
  199. shift && VNCPASS="$1"
  200. ;;
  201. --display)
  202. shift && USER_DISPLAY="$1"
  203. ;;
  204. --compat)
  205. COMPAT_SWITCH=1
  206. ;;
  207. --container|-c)
  208. shift && CONTAINERS+=("$1")
  209. ;;
  210. --yes|-y)
  211. YES_SWITCH=1
  212. ;;
  213. --version|-v)
  214. echo "Version: $SCRIPTVERSION"
  215. exit 0
  216. ;;
  217. --debug|-d)
  218. DEBUG=1
  219. ;;
  220. --help|-h)
  221. printHelp
  222. exit
  223. ;;
  224. --uninstall|-u)
  225. UNINSTALL_SWITCH=1
  226. ;;
  227. --tests)
  228. TEST_SWITCH=1
  229. ;;
  230. --)
  231. shift
  232. break
  233. ;;
  234. esac
  235. shift
  236. done
  237. else
  238. err "Incorrect options provided"
  239. printHelp && exit 1
  240. fi
  241. }
  242. #######################################
  243. # Perform OS detection and fallback
  244. # Generate OS-specific functions
  245. #######################################
  246. init() {
  247. debug "Running: ${FUNCNAME[0]}"
  248. declare -g ID RPM_MGR ARCH
  249. declare -ga PKG_INSTALL PKG_REMOVE PKG_UPDATE
  250. echo "Starting installJRMC"
  251. (( DEBUG )) || echo "To enable debugging output, use --debug or -d"
  252. if [[ -e "/etc/os-release" ]]; then
  253. source "/etc/os-release"
  254. else
  255. err "/etc/os-release not found"
  256. err "Your OS is unsupported"
  257. printHelp
  258. exit 1
  259. fi
  260. # Detect architecture and translate to MC convention
  261. # Also catch user input in getopt
  262. ARCH=$(uname -m)
  263. case "$ARCH" in
  264. x86_64)
  265. ARCH="amd64"
  266. ;;
  267. esac
  268. debug "Detected host platform: $ID $VERSION_ID $ARCH"
  269. # normalize ID and set distro-specific vars
  270. case "$ID" in
  271. debian|arch)
  272. ;;
  273. centos|fedora)
  274. if hash dnf &>/dev/null; then
  275. RPM_MGR="dnf"
  276. elif hash yum &>/dev/null; then
  277. RPM_MGR="yum"
  278. fi
  279. ;;
  280. rhel)
  281. ID="centos"
  282. ;;
  283. linuxmint|neon|*ubuntu*)
  284. ID="ubuntu"
  285. ;;
  286. *suse*)
  287. ID="suse"
  288. ;;
  289. raspbian)
  290. ID="debian"
  291. ;;
  292. *)
  293. err "Autodetecting distro, this is unreliable and --compat may be required"
  294. if hash dnf &>/dev/null; then
  295. ID="fedora"
  296. RPM_MGR="dnf"
  297. elif hash yum &>/dev/null; then
  298. ID="centos"
  299. RPM_MGR="yum"
  300. COMPAT_SWITCH=1
  301. elif hash apt-get &>/dev/null; then
  302. ID="ubuntu"
  303. elif hash pacman &>/dev/null; then
  304. ID="arch"
  305. else
  306. err "OS detection failed!"
  307. askOk "Continue with manual installation?" || exit 1
  308. ID="unknown"
  309. REPO_INSTALL_SWITCH=0
  310. BUILD_SWITCH=1
  311. LOCAL_INSTALL_SWITCH=1
  312. fi
  313. esac
  314. [[ $ID != "unknown" ]] && debug "Using host platform: $ID $VERSION_ID"
  315. # Abstract distro-specific package manager commands
  316. case "$ID" in
  317. fedora|centos)
  318. PKG_INSTALL=(sudo "$RPM_MGR" install -y)
  319. PKG_REMOVE=(sudo "$RPM_MGR" remove -y)
  320. PKG_UPDATE=(sudo "$RPM_MGR" makecache)
  321. PKG_QUERY(){ rpm -q "$@"; }
  322. PKG_INSTALL_LOCAL(){ installMCRPM; }
  323. ;;
  324. debian|ubuntu)
  325. PKG_INSTALL=(sudo apt-get -f install -y -q0)
  326. PKG_REMOVE=(sudo apt-get remove --auto-remove -y -q0)
  327. PKG_UPDATE=(sudo apt-get update -y -q0)
  328. PKG_QUERY(){ dpkg -s "$@"; }
  329. PKG_INSTALL_LOCAL(){ installMCDEB; }
  330. ;;
  331. suse)
  332. PKG_INSTALL=(sudo zypper --non-interactive -q install --force --no-confirm)
  333. PKG_REMOVE=(sudo zypper --non-interactive -q remove --clean-deps)
  334. PKG_UPDATE=(sudo zypper --non-interactive -q refresh jriver)
  335. PKG_QUERY(){ rpm -q "$@"; }
  336. PKG_INSTALL_LOCAL(){ installMCRPM; }
  337. ;;
  338. arch)
  339. PKG_INSTALL=(sudo pacman -Sy --noconfirm)
  340. PKG_REMOVE=(sudo pacman -Rs --noconfirm)
  341. PKG_UPDATE=(sudo pacman -Syy)
  342. PKG_QUERY(){ sudo pacman -Qs "$@"; }
  343. PKG_INSTALL_LOCAL(){ installMCARCH; }
  344. ;;
  345. unknown)
  346. PKG_INSTALL_LOCAL(){ installMCGENERIC; }
  347. esac
  348. }
  349. #######################################
  350. # Uses several methods to determine the latest JRiver MC version
  351. # TODO but how to determine build distro `$DEBIANBASE=buster`?
  352. #######################################
  353. setMCVersion() {
  354. debug "Running: ${FUNCNAME[0]}"
  355. declare -g MCVERSION_SOURCE MVERSION MCPKG MCRPM
  356. declare cnt
  357. # User input
  358. if (( USER_VERSION_SWITCH )) &&
  359. [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  360. MCVERSION_SOURCE="user input"
  361. # Containerized package manager
  362. elif installPackage --silent buildah &&
  363. cnt=$(buildah from --quiet debian:$DEBIANBASE-slim) &>/dev/null &&
  364. buildah run "$cnt" -- bash -c \
  365. "echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $DEBIANBASE main' > /etc/apt/sources.list 2>&1" &>/dev/null &&
  366. buildah run "$cnt" -- bash -c \
  367. "apt update --allow-insecure-repositories &>/dev/null" &>/dev/null &&
  368. MCVERSION=$(buildah run "$cnt" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) &>/dev/null &&
  369. [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  370. MCVERSION_SOURCE="containerized package manager"
  371. buildah rm "$cnt" &>/dev/null
  372. # Webscrape
  373. elif installPackage wget && MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1) &&
  374. [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  375. MCVERSION_SOURCE="webscrape"
  376. # Hardcoded
  377. else
  378. declare -g MCVERSION="$MCVERSION_HARDCODE"
  379. MCVERSION_SOURCE="hardcoded or MCVERSION env"
  380. err "Warning! Using hardcoded version number"
  381. fi
  382. MVERSION="${MCVERSION%%.*}"
  383. MCPKG="mediacenter$MVERSION"
  384. MCRPM="$OUTPUTDIR/RPMS/x86_64/mediacenter$MVERSION-$MCVERSION.x86_64.rpm"
  385. if [[ "$MCVERSION_SOURCE" == "user input" ]]; then
  386. # Append explicit package version when user provides --mcversion
  387. case "$ID" in
  388. fedora|centos|suse)
  389. MCPKG+="-$MCVERSION"
  390. ;;
  391. debian|ubuntu)
  392. MCPKG+="=$MCVERSION"
  393. ;;
  394. esac
  395. fi
  396. echo "Using MC version $MCVERSION determined by $MCVERSION_SOURCE"
  397. [[ "$MCVERSION_SOURCE" == "user input" ]] || echo "To override, use --mcversion"
  398. debug "MVERSION: $MVERSION, MCVERSION: $MCVERSION, MCPKG: $MCPKG, MCRPM: $MCRPM"
  399. }
  400. #######################################
  401. # Installs a package using the system package manager
  402. # Arguments:
  403. # One or more package names
  404. # Options:
  405. # --no-install-check: Do not check if package is already installed
  406. # --no-gpg-check: Disable GPG checks for RPM based distros
  407. # --allow-downgrades: Useful for installing specific MC versions
  408. # --silent, -s: Do not print errors (useful for optional packages)
  409. #######################################
  410. installPackage() {
  411. debug "Running: ${FUNCNAME[0]}" "$@"
  412. declare -a pkg_array install_flags
  413. declare long_opts input pkg
  414. declare no_install_check allow_downgrades silent refresh no_gpg_check
  415. declare -A pkg_aliases
  416. long_opts="no-install-check,allow-downgrades,no-gpg-check,refresh,silent"
  417. if input=$(getopt -o +s -l "$long_opts" -- "$@"); then
  418. eval set -- "$input"
  419. while true; do
  420. case "$1" in
  421. --no-install-check)
  422. no_install_check=1
  423. ;;
  424. --allow-downgrades)
  425. allow_downgrades=1
  426. ;;
  427. --no-gpg-check)
  428. no_gpg_check=1
  429. ;;
  430. --refresh)
  431. refresh=1
  432. ;;
  433. --silent|-s)
  434. silent=1
  435. ;;
  436. --)
  437. shift
  438. break
  439. ;;
  440. esac
  441. shift
  442. done
  443. else
  444. err "Incorrect options provided"
  445. exit 1
  446. fi
  447. # Package aliases
  448. case "$ID" in
  449. debian|ubuntu)
  450. pkg_aliases["rpm-build"]="rpm"
  451. pkg_aliases["createrepo_c"]="createrepo"
  452. pkg_aliases["tigervnc-server"]="tigervnc-standalone-server"
  453. ;;
  454. esac
  455. # Filter installed packages
  456. for pkg in "$@"; do
  457. if [[ -v pkg_aliases[$pkg] ]]; then
  458. pkg=${pkg_aliases[$pkg]}
  459. fi
  460. if (( no_install_check )) ||
  461. ! (hash "$pkg" &>/dev/null ||
  462. PKG_QUERY "$pkg" &>/dev/null); then
  463. pkg_array+=("$pkg")
  464. else
  465. debug "$pkg already installed, skipping installation"
  466. fi
  467. done
  468. # Generate distro-specific install flags
  469. case "$ID" in
  470. debian|ubuntu)
  471. (( allow_downgrades )) && install_flags+=(--allow-downgrades)
  472. ;;
  473. fedora|centos)
  474. (( allow_downgrades )) && install_flags+=(--allowerasing)
  475. (( no_gpg_check )) && install_flags+=(--nogpgcheck)
  476. (( refresh )) && install_flags+=(--refresh)
  477. ;;
  478. suse)
  479. (( no_gpg_check )) && install_flags+=(--allow-unsigned-rpm)
  480. ;;
  481. esac
  482. # Install packages from package array
  483. if [[ ${#pkg_array[@]} -ge 1 ]]; then
  484. if ! execute "${PKG_INSTALL[*]} ${install_flags[*]} ${pkg_array[*]}"; then
  485. (( silent )) || err "Failed to install ${pkg_array[*]}. Attempting to continue"
  486. return 1
  487. fi
  488. fi
  489. return 0
  490. }
  491. #######################################
  492. # Installs JRiver Media Center from a remote repository
  493. #######################################
  494. installMCFromRepo() {
  495. debug "Running: ${FUNCNAME[0]}"
  496. case "$ID" in
  497. fedora|centos)
  498. sudo bash -c "cat <<-EOF > /etc/yum.repos.d/jriver.repo
  499. [jriver]
  500. name=JRiver Media Center repo by BryanC
  501. baseurl=https://repos.bryanroessler.com/jriver
  502. gpgcheck=0
  503. EOF"
  504. ;;
  505. debian|ubuntu)
  506. declare repo_dir="/etc/apt/sources.list.d"
  507. [[ -d $repo_dir ]] || execute "sudo mkdir -p $repo_dir"
  508. sudo rm -rf "$repo_dir"/mediacenter*.list
  509. installPackage wget
  510. sudo bash -c "cat <<-EOF > $repo_dir/jriver.list
  511. deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $DEBIANBASE main
  512. EOF"
  513. wget -qO- "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" |
  514. sudo tee /etc/apt/trusted.gpg.d/jriver.asc &>/dev/null
  515. ;;
  516. *)
  517. err "An MC repository for $ID is not yet available"
  518. err "Try using --install local to install MC on $ID"
  519. return 1
  520. ;;
  521. esac
  522. if ! execute "${PKG_UPDATE[@]}"; then
  523. err "Package update failed!"
  524. return 1
  525. fi
  526. # Install mesa-va-drivers-freeworld separately from the RPM using dnf swap
  527. installMesa
  528. if ! execute installPackage \
  529. --no-install-check \
  530. --allow-downgrades \
  531. --no-gpg-check \
  532. "$MCPKG"; then
  533. err "Package install failed!"
  534. return 1
  535. fi
  536. }
  537. #######################################
  538. # Acquires the source DEB package from JRiver
  539. #######################################
  540. acquireDeb() {
  541. debug "Running: ${FUNCNAME[0]}"
  542. declare -g MCDEB="$OUTPUTDIR/SOURCES/MediaCenter-$MCVERSION-${USER_ARCH:-$ARCH}.deb"
  543. debug "MCDEB=$MCDEB"
  544. # If necessary, create SOURCES dir
  545. [[ -d "$OUTPUTDIR/SOURCES" ]] || execute "mkdir -p $OUTPUTDIR/SOURCES"
  546. # If deb file already exists, skip download
  547. if [[ -f "$MCDEB" ]]; then
  548. echo "Using existing DEB: $MCDEB"
  549. return 0
  550. fi
  551. if [[ -v BETAPASS ]] &&
  552. echo "Checking beta repo for DEB package" && wget -q -O "$MCDEB" \
  553. "https://files.jriver.com/mediacenter/channels/v$MVERSION/beta/$BETAPASS/MediaCenter-$MCVERSION-${USER_ARCH:-$ARCH}.deb"; then
  554. echo "Found!"
  555. elif echo "Checking latest repo for DEB package" && wget -q -O "$MCDEB" \
  556. "https://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-${USER_ARCH:-$ARCH}.deb"; then
  557. echo "Found!"
  558. elif echo "Checking test repo for DEB package" && wget -q -O "$MCDEB" \
  559. "https://files.jriver.com/mediacenter/test/MediaCenter-$MCVERSION-${USER_ARCH:-$ARCH}.deb"; then
  560. echo "Found!"
  561. else
  562. err "Cannot find DEB file"
  563. exit 1
  564. fi
  565. if [[ -f "$MCDEB" ]]; then
  566. echo "Downloaded MC $MCVERSION DEB to $MCDEB"
  567. else
  568. err "Downloaded DEB file missing or corrupted"
  569. exit 1
  570. fi
  571. }
  572. #######################################
  573. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  574. #######################################
  575. buildRPM() {
  576. debug "Running: ${FUNCNAME[0]}"
  577. declare i rpmbuild_cmd
  578. declare -a requires recommends
  579. # skip rebuilding the rpm if it already exists
  580. if [[ -f "$MCRPM" ]]; then
  581. echo "$MCRPM already exists. Skipping build step"
  582. return 0
  583. fi
  584. [[ -d "$OUTPUTDIR/SPECS" ]] || mkdir -p "$OUTPUTDIR/SPECS"
  585. # Load deb dependencies into array
  586. IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MCDEB" Depends)"
  587. IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MCDEB" Recommends)"
  588. # Clean up formatting
  589. requires=("${requires[@]%%|*}")
  590. requires=("${requires[@]/?:/}")
  591. requires=("${requires[@]# }")
  592. requires=("${requires[@]% }")
  593. requires=("${requires[@]//\(/}")
  594. requires=("${requires[@]//)/}")
  595. recommends=("${recommends[@]%%|*}")
  596. recommends=("${recommends[@]/?:/}")
  597. recommends=("${recommends[@]# }")
  598. recommends=("${recommends[@]% }")
  599. recommends=("${recommends[@]//\(/}")
  600. recommends=("${recommends[@]//)/}")
  601. # Translate package names
  602. case "$TARGET" in
  603. fedora|centos)
  604. requires=("${requires[@]/libc6/glibc}")
  605. requires=("${requires[@]/libasound2/alsa-lib}")
  606. requires=("${requires[@]/libuuid1/libuuid}")
  607. requires=("${requires[@]/libx11-6/libX11}")
  608. requires=("${requires[@]/libxext6/libXext}")
  609. requires=("${requires[@]/libxcb1/libxcb}")
  610. requires=("${requires[@]/libxdmcp6/libXdmcp}")
  611. requires=("${requires[@]/libstdc++6/libstdc++}")
  612. requires=("${requires[@]/libgtk-3-0/gtk3}")
  613. requires=("${requires[@]/libgl1/mesa-libGL}")
  614. requires=("${requires[@]/libpango-1.0-0/pango}")
  615. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  616. requires=("${requires[@]/libpangox-1.0-0/pango}")
  617. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  618. requires=("${requires[@]/libnss3/nss}")
  619. requires=("${requires[@]/libnspr4/nspr}")
  620. requires=("${requires[@]/libgomp1/libgomp}")
  621. requires=("${requires[@]/libfribidi0/fribidi}")
  622. requires=("${requires[@]/libfontconfig1/fontconfig}")
  623. requires=("${requires[@]/libfreetype6/freetype}")
  624. requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
  625. requires=("${requires[@]/libgbm1/mesa-libgbm}")
  626. requires=("${requires[@]/libva2/libva}")
  627. requires=("${requires[@]/libepoxy0/libepoxy}")
  628. requires=("${requires[@]/liblcms2-2/lcms2}")
  629. requires=("${requires[@]/libvulkan1/vulkan-loader}")
  630. requires=("${requires[@]/libepoxy0/libepoxy}")
  631. requires=("${requires[@]/python/python3}")
  632. recommends+=(mesa-va-drivers-freeworld)
  633. ;;
  634. suse)
  635. requires=("${requires[@]/libc6/glibc}")
  636. requires=("${requires[@]/libasound2/alsa-lib}")
  637. requires=("${requires[@]/libx11-6/libX11-6}")
  638. requires=("${requires[@]/libxext6/libXext6}")
  639. requires=("${requires[@]/libxdmcp6/libXdmcp6}")
  640. requires=("${requires[@]/libgtk-3-0/gtk3}")
  641. requires=("${requires[@]/libgl1/Mesa-libGL1}")
  642. requires=("${requires[@]/libpango-1.0-0/pango}")
  643. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  644. requires=("${requires[@]/libpangox-1.0-0/pango}")
  645. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  646. requires=("${requires[@]/libnss3/mozilla-nss}")
  647. requires=("${requires[@]/libnspr4/mozilla-nspr}")
  648. requires=("${requires[@]/libfribidi0/fribidi}")
  649. requires=("${requires[@]/libfontconfig1/fontconfig}")
  650. requires=("${requires[@]/libfreetype6*/freetype}") # Remove minimum version specifier
  651. requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
  652. for i in "${!requires[@]}"; do
  653. [[ "${requires[$i]}" == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
  654. done
  655. recommends+=(libvulkan_intel)
  656. recommends+=(libvulkan_radeon)
  657. ;;
  658. esac
  659. # Convert array to newline delim'd string (for heredoc)
  660. printf -v requires "Requires: %s\n" "${requires[@]}"
  661. printf -v recommends "Recommends: %s\n" "${recommends[@]}"
  662. # Strip last newline
  663. requires="${requires%?}"
  664. recommends="${recommends%?}"
  665. if (( COMPAT_SWITCH )); then
  666. # Strip minimum versions
  667. requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
  668. fi
  669. # Create spec file
  670. cat <<-EOF > "$OUTPUTDIR/SPECS/mediacenter.spec"
  671. Name: mediacenter$MVERSION
  672. Version: $MCVERSION
  673. Release: 1
  674. Summary: JRiver Media Center
  675. Group: Applications/Media
  676. Source0: http://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-${USER_ARCH:-$ARCH}.deb
  677. BuildArch: x86_64
  678. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
  679. AutoReq: 0
  680. $requires
  681. $recommends
  682. Conflicts: MediaCenter
  683. Provides: mediacenter$MVERSION
  684. License: Copyright 1998-2023, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  685. URL: http://www.jriver.com/
  686. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  687. %description
  688. Media Center is more than a world class player.
  689. %global __os_install_post %{nil}
  690. %prep
  691. %build
  692. %install
  693. dpkg -x %{S:0} %{buildroot}
  694. %post -p /sbin/ldconfig
  695. %postun -p /sbin/ldconfig
  696. %files
  697. %{_bindir}/mediacenter$MVERSION
  698. %{_libdir}/jriver
  699. %{_datadir}
  700. %exclude %{_datadir}/applications/media_center_packageinstaller_$MVERSION.desktop
  701. /etc/security/limits.d/*
  702. EOF
  703. # Run rpmbuild
  704. echo "Building MC $MCVERSION RPM, this may take awhile"
  705. rpmbuild_cmd=(
  706. rpmbuild
  707. --define=\"%_topdir "$OUTPUTDIR"\"
  708. --define=\"%_libdir /usr/lib\"
  709. -bb
  710. "$OUTPUTDIR/SPECS/mediacenter.spec"
  711. )
  712. if execute "${rpmbuild_cmd[*]}" && [[ -f "$MCRPM" ]] ; then
  713. echo "Build successful. The RPM file is located at: $MCRPM"
  714. else
  715. err "Build failed"
  716. # For automation, let's remove the source DEB and reaquire it on next
  717. # run after failure in case it is corrupted or buggy
  718. [[ -f "$MCDEB" ]] && echo "Removing source DEB" && rm -f "$MCDEB"
  719. exit 1
  720. fi
  721. }
  722. #######################################
  723. # Installs Media Center DEB package and optional compatability fixes
  724. #######################################
  725. installMCDEB() {
  726. debug "Running: ${FUNCNAME[0]}"
  727. if (( COMPAT_SWITCH )); then
  728. declare extract_dir && extract_dir="$(mktemp -d)"
  729. pushd "$extract_dir" &>/dev/null || return
  730. ar x "$MCDEB"
  731. tar -xJf "control.tar.xz"
  732. # Remove minimum version specifiers from control file
  733. sed -i 's/ ([^)]*)//g' "control"
  734. sed -i 's/([^)]*)//g' "control" # TODO MC DEB package error
  735. [[ "$ID" == "ubuntu" && "${VERSION_ID%.*}" -le 16 ]] &&
  736. sed -i 's/libva2/libva1/g' "control"
  737. tar -cJf "control.tar.xz" "control" "postinst"
  738. declare -g MCDEB="${MCDEB/.deb/.compat.deb}"
  739. ar rcs "$MCDEB" "debian-binary" "control.tar.xz" "data.tar.xz"
  740. popd &>/dev/null || return
  741. rm -rf "$extract_dir"
  742. fi
  743. execute installPackage \
  744. --no-install-check \
  745. --no-gpg-check \
  746. --allow-downgrades \
  747. "$MCDEB"
  748. }
  749. #######################################
  750. # Installs Media Center RPM package
  751. #######################################
  752. installMCRPM() {
  753. debug "Running: ${FUNCNAME[0]}"
  754. # Install mesa-va-freeworld separately from the RPM for dnf swap
  755. installMesa
  756. installPackage --no-install-check --no-gpg-check --allow-downgrades "$MCRPM"
  757. }
  758. #######################################
  759. # Installs Media Center manually
  760. #######################################
  761. installMCGENERIC() {
  762. debug "Running: ${FUNCNAME[0]}"
  763. echo "Using raw installation method!"
  764. declare extract_dir && extract_dir="$(mktemp -d)"
  765. pushd "$extract_dir" &>/dev/null || return
  766. ar x "$MCDEB"
  767. tar xvf "control.tar.gz"
  768. echo "You must install the following dependencies manually:"
  769. cat control
  770. tar xvf "data.tar.gz"
  771. pushd data &>/dev/null || return
  772. # Add list of files to log for uninstall
  773. find . -mindepth 1 >> "$SCRIPTDIR/.uninstall"
  774. # Manually install files
  775. sudo cp -a ./etc/* /etc/
  776. sudo cp -a ./usr/* /usr/
  777. popd -1 &>/dev/null || return
  778. popd &>/dev/null || return
  779. }
  780. #######################################
  781. # Installs mesa-va-drivers-freeworld
  782. #######################################
  783. installMesa() {
  784. debug "Running: ${FUNCNAME[0]}"
  785. # Currently only necessary in Fedora/CentOS
  786. case "$ID" in
  787. fedora|centos)
  788. if ! PKG_QUERY mesa-va-drivers-freeworld &>/dev/null; then
  789. if PKG_QUERY mesa-va-drivers &>/dev/null; then
  790. if ! execute sudo dnf swap -y \
  791. mesa-va-drivers \
  792. mesa-va-drivers-freeworld; then
  793. err "Package swap failed!"
  794. return 1
  795. fi
  796. else
  797. execute "${PKG_INSTALL[@]}" mesa-va-drivers-freeworld
  798. fi
  799. fi
  800. ;;
  801. esac
  802. }
  803. #######################################
  804. # Installs local Media Center PKGBUILD
  805. #######################################
  806. installMCARCH() {
  807. debug "Running: ${FUNCNAME[0]}"
  808. [[ -d "$OUTPUTDIR/PKGBUILD" ]] || mkdir -p "$OUTPUTDIR/PKGBUILD"
  809. cat <<-EOF > "$OUTPUTDIR/PKGBUILD/mediacenter.pkgbuild"
  810. pkgname=mediacenter$MVERSION
  811. pkgver=$MCVERSION
  812. pkgrel=1
  813. pkgdesc="The Most Comprehensive Media Software"
  814. arch=('x86_64')
  815. url="http://www.jriver.com/"
  816. license=('custom')
  817. depends=('alsa-lib' 'gcc-libs' 'libx11' 'libxext' 'libxcb' 'libxau' 'libxdmcp' 'util-linux' 'libxext' 'gtk3')
  818. optdepends=(
  819. 'mesa-libgl: nouveau video support'
  820. 'nvidia-libgl: nvidia video support'
  821. 'nvidia-utils: nvidia vulkan support'
  822. 'vulkan-intel: intel vulkan support'
  823. 'vulkan-radeon: amd vulkan support'
  824. 'vorbis-tools: ogg vorbis support'
  825. 'musepack-tools: musepack support'
  826. )
  827. source=("http://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-${USER_ARCH:-$ARCH}.deb")
  828. package() {
  829. cd "\$srcdir"
  830. bsdtar xf data.tar.xz -C "\$pkgdir"
  831. }
  832. EOF
  833. pushd "$OUTPUTDIR/PKGBUILD" &>/dev/null || return
  834. if ! execute makepkg \
  835. --install \
  836. --syncdeps \
  837. --clean \
  838. --cleanbuild \
  839. --skipinteg \
  840. --force \
  841. --noconfirm \
  842. -p mediacenter.pkgbuild; then
  843. echo "makepkg failed"
  844. exit 1
  845. fi
  846. popd &>/dev/null || return
  847. }
  848. #######################################
  849. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  850. #######################################
  851. runCreaterepo() {
  852. debug "Running: ${FUNCNAME[0]}"
  853. declare -a cr_cmd
  854. installPackage createrepo_c
  855. # If the webroot does not exist, create it
  856. if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then
  857. if ! execute "sudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT"; then
  858. if ! ( execute "sudo mkdir -p $CREATEREPO_WEBROOT" &&
  859. execute "sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT" ); then
  860. err "Could not create the createrepo-webroot path!"
  861. err "Make sure that the webroot $CREATEREPO_WEBROOT is writeable by user $CREATEREPO_USER"
  862. err "Or change the repo ownership with --createrepo-user"
  863. return 1
  864. fi
  865. fi
  866. fi
  867. # Copy built rpms to webroot
  868. if ! ( execute "sudo cp -nf $MCRPM $CREATEREPO_WEBROOT" &&
  869. execute "sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT" ); then
  870. err "Could not copy $MCRPM to $CREATEREPO_WEBROOT"
  871. return 1
  872. fi
  873. # Run createrepo
  874. cr_cmd=(sudo -u "$CREATEREPO_USER" createrepo -q "$CREATEREPO_WEBROOT")
  875. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=(--update)
  876. if ! execute "${cr_cmd[*]}"; then
  877. cr_cmd=(sudo createrepo -q "$CREATEREPO_WEBROOT")
  878. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=(--update)
  879. if ! (execute "${cr_cmd[*]}" &&
  880. execute "sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"); then
  881. err "createrepo failed"
  882. return 1
  883. fi
  884. fi
  885. }
  886. #######################################
  887. # Symlink certificates if they do not exist in default location
  888. #######################################
  889. symlinkCerts() {
  890. debug "Running: ${FUNCNAME[0]}"
  891. declare mc_cert_link="/usr/lib/jriver/MC$MVERSION/ca-certificates.crt"
  892. declare target_cert f
  893. declare -a source_certs=(
  894. "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
  895. "/var/lib/ca-certificates/ca-bundle.pem")
  896. target_cert=$(readlink -f "$mc_cert_link")
  897. [[ -f $target_cert ]] && return 0
  898. for f in "${source_certs[@]}"; do
  899. if [[ -f "$f" ]]; then
  900. if ! execute ln -fs "$f" "$mc_cert_link"; then
  901. err "Symlinking certificate failed"
  902. return 1
  903. fi
  904. break
  905. fi
  906. done
  907. }
  908. #######################################
  909. # Restore the mjr license file from RESTOREFILE or other common locations
  910. #######################################
  911. restoreLicense() {
  912. debug "Running: ${FUNCNAME[0]}"
  913. declare f newest
  914. # Glob mjr files from common directories
  915. shopt -s nullglob
  916. declare -a mjrfiles=(
  917. "$SCRIPTDIR"/*.mjr
  918. "$OUTPUTDIR"/*.mjr
  919. "$HOME"/[dD]ownloads/*.mjr
  920. "$HOME"/[dD]ocuments/*.mjr
  921. )
  922. shopt -u nullglob
  923. debug "mjrfiles=(${mjrfiles[*]})"
  924. # Sort globbed files by time, newest first
  925. newest=${mjrfiles[0]}
  926. for f in "${mjrfiles[@]}"; do
  927. if [[ -f $f && $f -nt $newest ]]; then
  928. newest=$f
  929. fi
  930. done
  931. debug "Latest mjrfile: $newest"
  932. for f in "$RESTOREFILE" "$newest"; do
  933. if [[ -f "$f" ]]; then
  934. if "mediacenter$MVERSION" "/RestoreFromFile" "$f"; then
  935. return 0
  936. fi
  937. fi
  938. done
  939. }
  940. #######################################
  941. # Opens ports using the system firewall tool
  942. # Arguments:
  943. # 1. Service name
  944. # 2. List of ports in firewall-cmd format
  945. #######################################
  946. openFirewall() {
  947. debug "Running: ${FUNCNAME[0]}" "$@"
  948. declare port
  949. declare service="$1"
  950. shift
  951. declare -a f_ports=("$@") # for firewall-cmd
  952. declare u_ports="$*"
  953. declare u_ports="${u_ports// /|}" # concatenate
  954. u_ports="${u_ports//-/\:}" # for ufw
  955. if hash firewall-cmd 2>/dev/null; then
  956. if ! sudo firewall-cmd --get-services | grep -q "$service"; then
  957. execute "sudo firewall-cmd --permanent --new-service=$service"
  958. execute "sudo firewall-cmd --permanent --service=$service --set-description=$service installed by installJRMC"
  959. execute "sudo firewall-cmd --permanent --service=$service --set-short=$service"
  960. for port in "${f_ports[@]}"; do
  961. execute "sudo firewall-cmd --permanent --service=$service --add-port=$port"
  962. done
  963. execute "sudo firewall-cmd --add-service $service --permanent"
  964. execute "sudo firewall-cmd --reload"
  965. fi
  966. elif hash ufw 2>/dev/null; then
  967. sudo bash -c "cat <<-EOF > /etc/ufw/applications.d/$service
  968. [$service]
  969. title=$service
  970. description=$service installed by installJRMC
  971. ports=$u_ports
  972. EOF"
  973. execute "sudo ufw app update $service"
  974. execute "sudo ufw allow $service"
  975. else
  976. err "Please install firewall-cmd or ufw to open firewall ports"
  977. return 1
  978. fi
  979. }
  980. #######################################
  981. # Create the xvnc or x11vnc password file
  982. # Arguments:
  983. # Service type (xvnc, x11vnc)
  984. #######################################
  985. setVNCPass() {
  986. debug "Running: ${FUNCNAME[0]}"
  987. declare vncpassfile="$HOME/.vnc/jrmc_passwd"
  988. [[ -d "${vncpassfile%/*}" ]] || execute "mkdir -p ${vncpassfile%/*}"
  989. if [[ -f "$vncpassfile" ]]; then
  990. if [[ ! -v VNCPASS ]]; then
  991. err "Refusing to overwrite existing $vncpassfile with an empty password"
  992. err "Remove existing $vncpassfile or use --vncpass ''"
  993. return 1
  994. else
  995. rm -f "$vncpassfile"
  996. fi
  997. fi
  998. if [[ -v VNCPASS ]]; then
  999. if [[ $1 == "xvnc" ]]; then
  1000. execute "echo $VNCPASS | vncpasswd -f > $vncpassfile"
  1001. elif [[ $1 == "x11vnc" ]]; then
  1002. execute "x11vnc -storepasswd $VNCPASS $vncpassfile"
  1003. fi
  1004. return $?
  1005. else
  1006. declare -g NOVNCAUTH=1
  1007. fi
  1008. }
  1009. #######################################
  1010. # Set display and port variables
  1011. #######################################
  1012. setDisplay() {
  1013. debug "Running: ${FUNCNAME[0]}"
  1014. declare -g DISPLAY DISPLAYNUM NEXT_DISPLAY NEXT_DISPLAYNUM
  1015. # Check USER_DISPLAY, else environment DISPLAY, else set to :0
  1016. DISPLAY="${USER_DISPLAY:-${DISPLAY:-0}}"
  1017. DISPLAYNUM="${DISPLAY#*:}" # strip prefix
  1018. DISPLAYNUM="${DISPLAYNUM%%.*}" # strip suffix
  1019. NEXT_DISPLAYNUM=$(( DISPLAYNUM + 1 ))
  1020. NEXT_DISPLAY=":$NEXT_DISPLAYNUM"
  1021. }
  1022. #######################################
  1023. # Create associated service variables based on service name
  1024. # Arguments
  1025. # Pre-defined service name
  1026. #######################################
  1027. setServiceVars() {
  1028. debug "Running: ${FUNCNAME[0]}" "$*"
  1029. declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME
  1030. declare -g USER_STRING DISPLAY_STRING GRAPHICAL_TARGET
  1031. declare -g RELOAD ENABLE DISABLE IS_ENABLED IS_ACTIVE
  1032. declare -a systemctl_prefix
  1033. declare service_name="$1"
  1034. declare service_type="${2:-${SERVICE_TYPE:-system}}"
  1035. declare service_dir="/usr/lib/systemd/$service_type"
  1036. if [[ "$USER" == "root" && "$service_type" == "user" ]]; then
  1037. err "Trying to install user service as root"
  1038. err "Use --service-type service and/or execute installJRMC as non-root user"
  1039. return 1
  1040. fi
  1041. if [[ "$service_type" == "system" ]]; then
  1042. systemctl_prefix=(sudo systemctl)
  1043. GRAPHICAL_TARGET="graphical.target"
  1044. elif [[ "$service_type" == "user" ]]; then
  1045. systemctl_prefix=(systemctl --user)
  1046. GRAPHICAL_TARGET="default.target"
  1047. fi
  1048. # systemctl commands
  1049. RELOAD="${systemctl_prefix[*]} daemon-reload"
  1050. ENABLE="${systemctl_prefix[*]} enable --now"
  1051. DISABLE="${systemctl_prefix[*]} disable --now"
  1052. IS_ENABLED="${systemctl_prefix[*]} is-enabled -q"
  1053. IS_ACTIVE="${systemctl_prefix[*]} is-active -q"
  1054. [[ -d "$service_dir" ]] || execute "sudo mkdir -p $service_dir"
  1055. # TODO Ubuntu needs these in the service file, fedora (and others?) do not
  1056. case "$ID" in
  1057. ubuntu|debian)
  1058. DISPLAY_STRING="Environment=DISPLAY=$DISPLAY"
  1059. DISPLAY_STRING+=$'\n'"Environment=XAUTHORITY=$XAUTHORITY"
  1060. ;;
  1061. *)
  1062. DISPLAY_STRING=""
  1063. ;;
  1064. esac
  1065. if [[ "$SERVICE_TYPE" == "system" && "$USER" != "root" ]]; then
  1066. SERVICE_FNAME="$service_dir/$service_name@.service"
  1067. TIMER_FNAME="$service_dir/$service_name@.timer"
  1068. SERVICE_NAME="$service_name@$USER.service"
  1069. TIMER_NAME="$service_name@$USER.timer"
  1070. USER_STRING="User=%I"
  1071. else
  1072. SERVICE_NAME="$service_name.service"
  1073. TIMER_NAME="$service_name.timer"
  1074. SERVICE_FNAME="$service_dir/$SERVICE_NAME"
  1075. TIMER_FNAME="$service_dir/${TIMER_NAME}"
  1076. USER_STRING=""
  1077. fi
  1078. }
  1079. #######################################
  1080. # Starts and enables (at startup) a JRiver Media Center service
  1081. # Arguments:
  1082. # Passes arguments as startup options to /usr/bin/mediacenter??
  1083. #######################################
  1084. service_jriver-mediacenter() {
  1085. debug "Running: ${FUNCNAME[0]}"
  1086. setServiceVars "${FUNCNAME[0]##*_}" "user"
  1087. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1088. [Unit]
  1089. Description=JRiver Media Center $MVERSION
  1090. After=$GRAPHICAL_TARGET
  1091. [Service]
  1092. $USER_STRING
  1093. $DISPLAY_STRING
  1094. Type=simple
  1095. Environment=DISPLAY=$DISPLAY
  1096. Environment=XAUTHORITY=$XAUTHORITY
  1097. ExecStart=/usr/bin/mediacenter$MVERSION $*
  1098. Restart=always
  1099. RestartSec=10
  1100. KillSignal=SIGHUP
  1101. TimeoutStopSec=30
  1102. [Install]
  1103. WantedBy=$GRAPHICAL_TARGET
  1104. EOF"
  1105. execute "$RELOAD" &&
  1106. execute "$ENABLE $SERVICE_NAME" &&
  1107. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1108. }
  1109. #######################################
  1110. # Starts and enables (at startup) a JRiver Media Server service
  1111. #######################################
  1112. service_jriver-mediaserver() {
  1113. debug "Running: ${FUNCNAME[0]}"
  1114. setServiceVars "${FUNCNAME[0]##*_}" "user"
  1115. service_jriver-mediacenter "/MediaServer"
  1116. }
  1117. #######################################
  1118. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  1119. # TODO https://github.com/TigerVNC/tigervnc/blob/master/unix/vncserver/HOWTO.md
  1120. #######################################
  1121. service_jriver-xvnc() {
  1122. debug "Running: ${FUNCNAME[0]}"
  1123. setServiceVars "${FUNCNAME[0]##*_}" "system"
  1124. setDisplay
  1125. declare -a start_cmd
  1126. declare -g PORT=$(( NEXT_DISPLAYNUM + 5900 ))
  1127. installPackage tigervnc-server
  1128. setVNCPass xvnc
  1129. if [[ $# -eq 1 && $1 == "increment" ]]; then
  1130. NEXT_DISPLAYNUM=$(( NEXT_DISPLAYNUM + 1 ))
  1131. DISPLAY=":$NEXT_DISPLAYNUM"
  1132. PORT=$(( NEXT_DISPLAYNUM + 5900 ))
  1133. fi
  1134. start_cmd=(
  1135. /usr/bin/vncserver "$NEXT_DISPLAY"
  1136. -geometry 1440x900
  1137. -alwaysshared
  1138. -autokill
  1139. -xstartup "/usr/bin/mediacenter$MVERSION"
  1140. )
  1141. if (( NOVNCAUTH )); then
  1142. start_cmd+=(
  1143. -name "jriver$NEXT_DISPLAY"
  1144. -SecurityTypes None
  1145. )
  1146. else
  1147. start_cmd+=(
  1148. -rfbauth "$HOME/.vnc/jrmc_passwd"
  1149. )
  1150. fi
  1151. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1152. [Unit]
  1153. Description=Remote desktop service (VNC)
  1154. After=multi-user.target
  1155. [Service]
  1156. Type=forking
  1157. $USER_STRING
  1158. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
  1159. ExecStart=${start_cmd[*]}
  1160. ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
  1161. Restart=always
  1162. [Install]
  1163. WantedBy=multi-user.target
  1164. EOF"
  1165. execute "$RELOAD"
  1166. if ! execute "$ENABLE $SERVICE_NAME"; then
  1167. err "vncserver failed to start on DISPLAY $NEXT_DISPLAY"
  1168. err "Incrementing DISPLAY and retrying"
  1169. service_jriver-xvnc increment
  1170. return
  1171. fi
  1172. echo "Xvnc running on localhost:$PORT"
  1173. openFirewall "jriver-xvnc" "$PORT/tcp"
  1174. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1175. }
  1176. #######################################
  1177. # Starts and enables (at startup) x11vnc screen sharing for the local desktop
  1178. #######################################
  1179. service_jriver-x11vnc() {
  1180. debug "Running: ${FUNCNAME[0]}"
  1181. setServiceVars "${FUNCNAME[0]##*_}" "user"
  1182. setDisplay
  1183. declare -a start_cmd
  1184. declare -g PORT=$(( DISPLAYNUM + 5900 ))
  1185. installPackage x11vnc
  1186. setVNCPass x11vnc
  1187. # If .Xauthority file is missing, generate a dummy for x11vnc -auth guess
  1188. if [[ ! -f "$HOME/.Xauthority" ]]; then
  1189. [[ "$XDG_SESSION_TYPE" == "wayland" ]] &&
  1190. askOk "Unsupported Wayland session detected for x11vnc, continue?" || return 1
  1191. touch "$HOME/.Xauthority"
  1192. xauth generate "$DISPLAY" . trusted
  1193. xauth add "$HOST$DISPLAY" . "$(xxd -l 16 -p /dev/urandom)"
  1194. fi
  1195. start_cmd=(
  1196. /usr/bin/x11vnc
  1197. -display "$DISPLAY"
  1198. -noscr
  1199. -auth guess
  1200. -forever
  1201. -bg
  1202. )
  1203. if (( NOVNCAUTH )); then
  1204. start_cmd+=(-nopw)
  1205. else
  1206. start_cmd+=(-rfbauth "$HOME/.vnc/jrmc_passwd")
  1207. fi
  1208. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1209. [Unit]
  1210. Description=x11vnc
  1211. After=$GRAPHICAL_TARGET
  1212. [Service]
  1213. $USER_STRING
  1214. Type=forking
  1215. Environment=DISPLAY=$DISPLAY
  1216. ExecStart=${start_cmd[*]}
  1217. Restart=always
  1218. RestartSec=10
  1219. [Install]
  1220. WantedBy=$GRAPHICAL_TARGET
  1221. EOF"
  1222. execute "$RELOAD" &&
  1223. execute "$ENABLE" "$SERVICE_NAME" &&
  1224. echo "x11vnc running on localhost:$PORT" &&
  1225. openFirewall "jriver-x11vnc" "$PORT/tcp"
  1226. }
  1227. #######################################
  1228. # Starts and enables (at startup) an hourly service to build the latest version of
  1229. # JRiver Media Center RPM from the source DEB and create/update an RPM repository
  1230. #######################################
  1231. service_jriver-createrepo() {
  1232. debug "Running: ${FUNCNAME[0]}"
  1233. if [[ "$CREATEREPO_USER" != "$USER" ]]; then
  1234. USER="root" setServiceVars "${FUNCNAME[0]##*_}" "system"
  1235. else
  1236. setServiceVars "${FUNCNAME[0]##*_}" "system"
  1237. fi
  1238. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1239. [Unit]
  1240. Description=Builds JRiver Media Center RPM, moves it to the repo dir, and runs createrepo
  1241. [Service]
  1242. $USER_STRING
  1243. ExecStart=$SCRIPTDIR/installJRMC --outputdir $OUTPUTDIR --createrepo=$TARGET --createrepo-webroot $CREATEREPO_WEBROOT --createrepo-user $CREATEREPO_USER
  1244. [Install]
  1245. WantedBy=multi-user.target
  1246. EOF"
  1247. sudo bash -c "cat <<-EOF > $TIMER_FNAME
  1248. [Unit]
  1249. Description=Run JRiver MC rpmbuild hourly
  1250. [Timer]
  1251. OnCalendar=hourly
  1252. Persistent=true
  1253. [Install]
  1254. WantedBy=timers.target
  1255. EOF"
  1256. execute "$RELOAD" &&
  1257. execute "$ENABLE" "$TIMER_NAME"
  1258. }
  1259. #######################################
  1260. # CONTAINERS
  1261. #######################################
  1262. # container_jriver-createrepo() {
  1263. # :
  1264. # }
  1265. # container_jriver-xvnc() {
  1266. # :
  1267. # }
  1268. # container_jriver-mediacenter() {
  1269. # installPackage buildah podman
  1270. # if ! CNT=$(buildah from debian:$DEBIANBASE-slim); then
  1271. # echo "Bad base image for container, skipping"
  1272. # return 1
  1273. # fi
  1274. # brc() { buildah run "$CNT" bash -c "$*"; }
  1275. # brc "add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg"
  1276. # # Install JRiver
  1277. # brc "
  1278. # add-pkg ca-certificates gnupg &&
  1279. # add-pkg --virtual build-dependencies wget &&
  1280. # wget -qO- http://dist.jriver.com/mediacenter@jriver.com.gpg.key | tee /etc/apt/trusted.gpg.d/jriver.asc &&
  1281. # wget -O /etc/apt/sources.list.d/mediacenter${MVERSION}.list http://dist.jriver.com/latest/mediacenter/mediacenter${MVERSION}.list &&
  1282. # apt update &&
  1283. # add-pkg mediacenter${MVERSION} &&
  1284. # del-pkg build-dependencies
  1285. # "
  1286. # buildah config "$CNT" \
  1287. # --author "bryanroessler@gmail.com" \
  1288. # --label maintainer="$MAINTAINER" \
  1289. # --env TZ="$TZ" \
  1290. # --workingdir /app \
  1291. # --cmd "mediacenter$MVERSION"
  1292. # # EXPOSE 5800 5900 52100 52101 52199 1900/udp
  1293. # podman_create_cmd=(
  1294. # podman create
  1295. # --name "mediacenter$MVERSION"
  1296. # )
  1297. # podman_create_cmd+=(-v "$HOME/.jriver:/root/.jriver")
  1298. # podman_create_cmd+=(-v "$DOWNLOAD_ROOT:/downloads:z")
  1299. # podman_create_cmd+=(-v "$MONITOR_ROOT/nzbs:/nzbs")
  1300. # podman_create_cmd+=(-p "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1301. # # mkcdirs() {
  1302. # # declare dir
  1303. # # for dir in "$@"; do
  1304. # # if [[ ! -d "$dir" ]]; then
  1305. # # if ! mkdir -p "$dir"; then
  1306. # # err "Could not create directory $dir, check your permissions"
  1307. # # fi
  1308. # # fi
  1309. # # if ! chcon -t container_file_t -R "$dir"; then
  1310. # # err "Could not set container_file_t attribute for $dir, check your permissions"
  1311. # # fi
  1312. # # done
  1313. # # }
  1314. # # mkcdirs "$HOME/.jriver"
  1315. # brc sh -s <<-EOF
  1316. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &>/dev/null
  1317. # EOF
  1318. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list"
  1319. # brc apt update -y -q0
  1320. # brc add-pkg "mediacenter$MVERSION"
  1321. # brc del-pkg .build-deps
  1322. # }
  1323. #######################################
  1324. # Detects if MC is installed on btrfs and disables CoW
  1325. #######################################
  1326. disableCoW() {
  1327. debug "Running: ${FUNCNAME[0]}"
  1328. declare dir
  1329. declare mc_system_path="/usr/lib/jriver"
  1330. declare mc_user_path="$HOME/.jriver"
  1331. [[ -d "$mc_user_path" ]] || mkdir -p "$mc_user_path"
  1332. for dir in "$mc_system_path" "$mc_user_path"; do
  1333. [[ -d "$dir" ]] || return
  1334. if [[ $(stat -f -c %T "$dir") == "btrfs" ]] &&
  1335. ! lsattr -d "$dir" | cut -f1 -d" " | grep -q C; then
  1336. echo "Disabling Btrfs CoW for $dir"
  1337. execute "sudo chattr +C $dir"
  1338. fi
  1339. done
  1340. }
  1341. #######################################
  1342. # Migrate major versions
  1343. #######################################
  1344. migrateLibrary() {
  1345. debug "Running: ${FUNCNAME[0]}"
  1346. declare mc_user_path="$HOME/.jriver"
  1347. declare current_config_path="$mc_user_path/Media Center $MVERSION"
  1348. declare previous_config_path="$mc_user_path/Media Center $(( MVERSION - 1 ))"
  1349. if [[ ! -d "$current_config_path" ]] &&
  1350. [[ -d "$previous_config_path" ]] &&
  1351. mkdir -p "$current_config_path"; then
  1352. echo "Migrating $previous_config_path to $current_config_path"
  1353. cp -fa "$previous_config_path"/* "$current_config_path"
  1354. fi
  1355. }
  1356. #######################################
  1357. # Completely uninstalls MC, services, and firewall rules
  1358. #######################################
  1359. uninstall() {
  1360. debug "Running: ${FUNCNAME[0]}"
  1361. declare service unit f i
  1362. echo "Stopping and removing all Media Center services"
  1363. for service in $(compgen -A "function" "service"); do
  1364. service="${service##service_}"
  1365. for i in user system; do
  1366. setServiceVars "$service" "$i";
  1367. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1368. if execute "$IS_ACTIVE $unit" ||
  1369. execute "$IS_ENABLED $unit"; then
  1370. execute "$DISABLE $unit"
  1371. fi
  1372. done
  1373. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1374. [[ -f "$f" ]] &&
  1375. execute "sudo rm -f $f"
  1376. done
  1377. execute "$RELOAD"
  1378. done
  1379. for f in /etc/systemd/system/jriver-*; do
  1380. execute "sudo rm -f $f"
  1381. done
  1382. done
  1383. echo "Removing repo files"
  1384. sudo rm -rf \
  1385. "/etc/yum.repos.d/jriver.repo" \
  1386. /etc/apt/sources.list.d/{jriver,mediacenter}*.list # also remove legacy repo files
  1387. if [[ "$ID" == "suse" ]]; then
  1388. execute "sudo zypper rr jriver"
  1389. fi
  1390. echo "Removing firewall rules"
  1391. if hash firewall-cmd 2>/dev/null; then
  1392. execute "sudo firewall-cmd --permanent --remove-service=jriver"
  1393. execute "sudo firewall-cmd --permanent --delete-service=jriver"
  1394. execute "sudo firewall-cmd --reload"
  1395. elif hash ufw 2>/dev/null; then
  1396. execute "sudo ufw delete allow jriver"
  1397. [[ -f "/etc/ufw/applications.d/jriver" ]] &&
  1398. execute "sudo rm -f /etc/ufw/applications.d/jriver"
  1399. fi
  1400. echo "Uninstalling JRiver Media Center package"
  1401. if execute "${PKG_REMOVE[@]}" "$MCPKG"; then
  1402. echo "JRiver Media Center has been completely uninstalled"
  1403. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1404. elif [[ $? -eq 100 ]]; then
  1405. err "JRiver Media Center package '$MCPKG' is not present and was not uninstalled"
  1406. else
  1407. err "Could not remove Media Center package"
  1408. fi
  1409. if [[ -f "$SCRIPTDIR/.uninstall" ]]; then
  1410. echo "Removing files from .uninstall log"
  1411. while read -r p; do
  1412. [[ -d $p ]] && sudo rm -rf "$p"
  1413. done < "$SCRIPTDIR/.uninstall"
  1414. mv "$SCRIPTDIR/.uninstall" "$SCRIPTDIR/.uninstall.bk"
  1415. fi
  1416. }
  1417. tests() {
  1418. # To test on Mint/16.04: sudo apt install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1419. : # TODO
  1420. }
  1421. main() {
  1422. debug "Running: ${FUNCNAME[0]} $*"
  1423. init
  1424. parseInput "$@"
  1425. debug "Debugging on"
  1426. debug "installJRMC version: $SCRIPTVERSION"
  1427. if ((TEST_SWITCH)); then
  1428. echo "Running tests, all other options are skipped"
  1429. tests
  1430. exit
  1431. fi
  1432. setMCVersion
  1433. if (( UNINSTALL_SWITCH )); then
  1434. if askOk "Do you really want to uninstall JRiver Media Center?"; then
  1435. uninstall
  1436. else
  1437. echo "Uninstall canceled"
  1438. fi
  1439. exit
  1440. fi
  1441. # Install external repos
  1442. case "$ID" in
  1443. ubuntu)
  1444. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  1445. echo "Adding universe repository"
  1446. if ! execute "sudo add-apt-repository -y universe"; then
  1447. err "Adding universe repository failed"
  1448. fi
  1449. fi
  1450. ;;
  1451. centos)
  1452. if ! hash dpkg &>/dev/null; then
  1453. echo "Adding EPEL repository"
  1454. installPackage epel-release
  1455. fi
  1456. if ! PKG_QUERY rpmfusion-free-release &>/dev/null; then
  1457. installPackage --no-install-check \
  1458. "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1459. fi
  1460. ;;
  1461. fedora)
  1462. if ! PKG_QUERY rpmfusion-free-release &>/dev/null; then
  1463. installPackage --no-install-check \
  1464. "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1465. fi
  1466. ;;
  1467. esac
  1468. if (( REPO_INSTALL_SWITCH )); then
  1469. echo "Installing JRiver Media Center from remote repository"
  1470. if installMCFromRepo; then
  1471. echo "JRiver Media Center installed successfully from repo"
  1472. symlinkCerts
  1473. migrateLibrary
  1474. restoreLicense
  1475. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1476. disableCoW
  1477. else
  1478. err "JRiver Media Center installation from repo failed"
  1479. return 1
  1480. fi
  1481. fi
  1482. if (( BUILD_SWITCH )) && [[ $ID != "arch" ]]; then
  1483. installPackage "wget"
  1484. acquireDeb
  1485. if [[ "$TARGET" =~ (centos|fedora|suse) ]]; then
  1486. installPackage "dpkg" "rpm-build"
  1487. buildRPM
  1488. fi
  1489. fi
  1490. if (( LOCAL_INSTALL_SWITCH )); then
  1491. if PKG_INSTALL_LOCAL; then
  1492. echo "JRiver Media Center installed successfully from local package"
  1493. else
  1494. err "JRiver Media Center local package installation failed"
  1495. return 1
  1496. fi
  1497. symlinkCerts
  1498. migrateLibrary
  1499. restoreLicense
  1500. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1501. disableCoW
  1502. fi
  1503. if (( CREATEREPO_SWITCH )); then
  1504. if runCreaterepo; then
  1505. echo "Successfully updated repo"
  1506. else
  1507. err "Repo creation failed"
  1508. fi
  1509. fi
  1510. if [[ "${#SERVICES[@]}" -gt 0 ]]; then
  1511. declare service
  1512. for service in "${SERVICES[@]}"; do
  1513. if ! "service_$service"; then
  1514. if [[ $? -eq 127 ]]; then
  1515. err "Service $service does not exist, check service name"
  1516. else
  1517. err "Failed to create service: $service"
  1518. fi
  1519. fi
  1520. done
  1521. fi
  1522. # for _container in "${CONTAINERS[@]}"; do
  1523. # if ! "_container_$_container"; then
  1524. # if [[ $? -eq 127 ]]; then
  1525. # err "Container $_container does not exist, check container name"
  1526. # else
  1527. # err "Failed to create container: $_container"
  1528. # fi
  1529. # fi
  1530. # done
  1531. }
  1532. # Roughly turn debugging on, reparse in getInput() with getopt
  1533. [[ " $* " =~ ( --debug | -d ) ]] && declare -g DEBUG=1
  1534. main "$@"