installJRMC 56 KB

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