installJRMC 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  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 "Starting installJRMC..."
  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. # Filter installed packages
  410. for pkg in "$@"; do
  411. if [[ -v pkg_aliases[$pkg] ]]; then
  412. pkg=${pkg_aliases[$pkg]}
  413. fi
  414. if (( skip_check_installed )) || ! (hash "$pkg" &>/dev/null || pkg_query "$pkg" &>/dev/null); then
  415. pkg_array+=("$pkg")
  416. else
  417. debug "$pkg already installed, skipping installation"
  418. fi
  419. done
  420. # Generate distro-specific install flags
  421. case "$ID" in
  422. debian|ubuntu)
  423. (( allow_downgrades )) && install_flags+=(--allow-downgrades)
  424. ;;
  425. fedora|centos)
  426. (( allow_downgrades )) && install_flags+=(--allowerasing)
  427. (( no_gpg_check )) && install_flags+=(--nogpgcheck)
  428. (( refresh )) && install_flags+=(--refresh)
  429. ;;
  430. suse)
  431. (( no_gpg_check )) && install_flags+=(--allow-unsigned-rpm)
  432. ;;
  433. esac
  434. # Install packages from package array
  435. if [[ ${#pkg_array[@]} -ge 1 ]]; then
  436. echo HERE
  437. pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}"
  438. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  439. if ! eval "$pkg_install_cmd"; then
  440. (( silent )) || err "Failed to install ${pkg_array[*]}. Attempting to continue"
  441. return 1
  442. fi
  443. fi
  444. return 0
  445. }
  446. #######################################
  447. # Installs JRiver Media Center from a remote repository
  448. #######################################
  449. installMCFromRepo() {
  450. debug "Running: ${FUNCNAME[0]}"
  451. declare repo_dir
  452. case "$ID" in
  453. fedora|centos)
  454. repo_dir="/etc/yum.repos.d/"
  455. sudo bash -c "cat <<-EOF > $repo_dir/jriver.repo
  456. [jriver]
  457. name=JRiver Media Center repo by BryanC
  458. baseurl=https://repos.bryanroessler.com/jriver
  459. gpgcheck=0
  460. EOF"
  461. ;;
  462. debian|ubuntu)
  463. repo_dir="/etc/apt/sources.list.d"
  464. [[ ! -d $repo_dir ]] && sudo mkdir -p "$repo_dir"
  465. sudo rm -rf "$repo_dir"/mediacenter*.list
  466. installPackage wget
  467. sudo bash -c "cat <<-EOF > $repo_dir/jriver.list
  468. deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $DEBIANBASE main
  469. EOF"
  470. wget -qO- "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" | sudo tee /etc/apt/trusted.gpg.d/jriver.asc &>/dev/null
  471. ;;
  472. *)
  473. err "An MC repository for $ID is not yet available."
  474. err "Try using --install local to install MC on $ID."
  475. return 1
  476. ;;
  477. esac
  478. declare pkg_update_cmd="pkg_update"
  479. debug "$pkg_update_cmd" || pkg_update_cmd+=" &>/dev/null"
  480. if ! eval "$pkg_update_cmd"; then
  481. err "Package update failed!"
  482. return 1
  483. fi
  484. declare pkg_install_cmd="installPackage --skip-check-installed --allow-downgrades --no-gpg-check $MCPKG"
  485. debug "$pkg_install_cmd"
  486. if ! eval "$pkg_install_cmd"; then
  487. err "Package install failed!"
  488. return 1
  489. fi
  490. }
  491. #######################################
  492. # Acquires the source DEB package from JRiver
  493. #######################################
  494. acquireDeb() {
  495. debug "Running: ${FUNCNAME[0]}"
  496. declare -g MCDEB="$OUTPUTDIR/SOURCES/MediaCenter-$MCVERSION-amd64.deb"
  497. # If necessary, create SOURCES dir
  498. [[ ! -d "$OUTPUTDIR/SOURCES" ]] && mkdir -p "$OUTPUTDIR/SOURCES"
  499. # If deb file already exists, skip download
  500. if [[ -f "$MCDEB" ]]; then
  501. echo "Using existing DEB: $MCDEB"
  502. return 0
  503. fi
  504. if [[ -v BETAPASS ]]; then
  505. echo "Checking beta repo for DEB package"
  506. if wget -q -O "$MCDEB" \
  507. "https://files.jriver.com/mediacenter/channels/v$MVERSION/beta/$BETAPASS/MediaCenter-$MCVERSION-amd64.deb"; then
  508. echo "Found!"
  509. fi
  510. elif echo "Checking latest repo for DEB package" && wget -q -O "$MCDEB" \
  511. "https://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb"; then
  512. echo "Found!"
  513. elif echo "Checking test repo for DEB package" && wget -q -O "$MCDEB" \
  514. "https://files.jriver.com/mediacenter/test/MediaCenter-$MCVERSION-amd64.deb"; then
  515. echo "Found!"
  516. else
  517. err "Cannot find DEB file"
  518. exit 1
  519. fi
  520. if [[ -f "$MCDEB" ]]; then
  521. echo "Downloaded MC $MCVERSION DEB to $MCDEB"
  522. else
  523. err "Downloaded DEB file missing or corrupted"
  524. exit 1
  525. fi
  526. }
  527. #######################################
  528. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  529. #######################################
  530. buildRPM() {
  531. debug "Running: ${FUNCNAME[0]}"
  532. declare i rpmbuild_cmd
  533. declare -a requires recommends
  534. # skip rebuilding the rpm if it already exists
  535. if [[ -f "$MCRPM" ]]; then
  536. echo "$MCRPM already exists. Skipping build step"
  537. return 0
  538. fi
  539. [[ ! -d "$OUTPUTDIR/SPECS" ]] && mkdir -p "$OUTPUTDIR/SPECS"
  540. # Load deb dependencies into array
  541. IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MCDEB" Depends)"
  542. IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MCDEB" Recommends)"
  543. # Clean up formatting
  544. requires=("${requires[@]%%|*}")
  545. requires=("${requires[@]/?:/}")
  546. requires=("${requires[@]# }")
  547. requires=("${requires[@]% }")
  548. requires=("${requires[@]//\(/}")
  549. requires=("${requires[@]//)/}")
  550. recommends=("${recommends[@]%%|*}")
  551. recommends=("${recommends[@]/?:/}")
  552. recommends=("${recommends[@]# }")
  553. recommends=("${recommends[@]% }")
  554. recommends=("${recommends[@]//\(/}")
  555. recommends=("${recommends[@]//)/}")
  556. # Translate package names
  557. case "$TARGET" in
  558. fedora|centos)
  559. requires=("${requires[@]/libc6/glibc}")
  560. requires=("${requires[@]/libasound2/alsa-lib}")
  561. requires=("${requires[@]/libuuid1/libuuid}")
  562. requires=("${requires[@]/libx11-6/libX11}")
  563. requires=("${requires[@]/libxext6/libXext}")
  564. requires=("${requires[@]/libxcb1/libxcb}")
  565. requires=("${requires[@]/libxdmcp6/libXdmcp}")
  566. requires=("${requires[@]/libstdc++6/libstdc++}")
  567. requires=("${requires[@]/libgtk-3-0/gtk3}")
  568. requires=("${requires[@]/libgl1/mesa-libGL}")
  569. requires=("${requires[@]/libpango-1.0-0/pango}")
  570. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  571. requires=("${requires[@]/libpangox-1.0-0/pango}")
  572. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  573. requires=("${requires[@]/libnss3/nss}")
  574. requires=("${requires[@]/libnspr4/nspr}")
  575. requires=("${requires[@]/libgomp1/libgomp}")
  576. requires=("${requires[@]/libfribidi0/fribidi}")
  577. requires=("${requires[@]/libfontconfig1/fontconfig}")
  578. requires=("${requires[@]/libfreetype6/freetype}")
  579. requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
  580. requires=("${requires[@]/libgbm1/mesa-libgbm}")
  581. requires=("${requires[@]/libva2/libva}")
  582. requires=("${requires[@]/libepoxy0/libepoxy}")
  583. requires=("${requires[@]/liblcms2-2/lcms2}")
  584. requires=("${requires[@]/libvulkan1/vulkan-loader}")
  585. requires=("${requires[@]/libepoxy0/libepoxy}")
  586. requires=("${requires[@]/python/python3}")
  587. recommends+=(mesa-va-drivers-freeworld)
  588. ;;
  589. suse)
  590. requires=("${requires[@]/libc6/glibc}")
  591. requires=("${requires[@]/libasound2/alsa-lib}")
  592. requires=("${requires[@]/libx11-6/libX11-6}")
  593. requires=("${requires[@]/libxext6/libXext6}")
  594. requires=("${requires[@]/libxdmcp6/libXdmcp6}")
  595. requires=("${requires[@]/libgtk-3-0/gtk3}")
  596. requires=("${requires[@]/libgl1/Mesa-libGL1}")
  597. requires=("${requires[@]/libpango-1.0-0/pango}")
  598. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  599. requires=("${requires[@]/libpangox-1.0-0/pango}")
  600. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  601. requires=("${requires[@]/libnss3/mozilla-nss}")
  602. requires=("${requires[@]/libnspr4/mozilla-nspr}")
  603. requires=("${requires[@]/libfribidi0/fribidi}")
  604. requires=("${requires[@]/libfontconfig1/fontconfig}")
  605. requires=("${requires[@]/libfreetype6*/freetype}") # Remove minimum version specifier
  606. requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
  607. for i in "${!requires[@]}"; do
  608. [[ "${requires[$i]}" == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
  609. done
  610. recommends+=(libvulkan_intel)
  611. recommends+=(libvulkan_radeon)
  612. ;;
  613. esac
  614. # Convert array to newline delim'd string (for heredoc)
  615. printf -v requires "Requires: %s\n" "${requires[@]}"
  616. printf -v recommends "Recommends: %s\n" "${recommends[@]}"
  617. # Strip last newline
  618. requires="${requires%?}"
  619. recommends="${recommends%?}"
  620. if (( COMPAT_SWITCH )); then
  621. # Strip minimum versions
  622. requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
  623. fi
  624. # Create spec file
  625. cat <<-EOF > "$OUTPUTDIR/SPECS/mediacenter.spec"
  626. Name: mediacenter$MVERSION
  627. Version: $MCVERSION
  628. Release: 1
  629. Summary: JRiver Media Center
  630. Group: Applications/Media
  631. Source0: http://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb
  632. BuildArch: x86_64
  633. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
  634. AutoReq: 0
  635. $requires
  636. $recommends
  637. Conflicts: MediaCenter
  638. Provides: mediacenter$MVERSION
  639. License: Copyright 1998-2022, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  640. URL: http://www.jriver.com/
  641. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  642. %description
  643. Media Center is more than a world class player.
  644. %global __os_install_post %{nil}
  645. %prep
  646. %build
  647. %install
  648. dpkg -x %{S:0} %{buildroot}
  649. %post -p /sbin/ldconfig
  650. %postun -p /sbin/ldconfig
  651. %files
  652. %{_bindir}/mediacenter$MVERSION
  653. %{_libdir}/jriver
  654. %{_datadir}
  655. %exclude %{_datadir}/applications/media_center_packageinstaller_$MVERSION.desktop
  656. /etc/security/limits.d/*
  657. EOF
  658. # Run rpmbuild
  659. echo "Building MC $MCVERSION RPM, this may take awhile"
  660. (( DEBUG )) || echo "Use --debug for verbose output"
  661. rpmbuild_cmd="rpmbuild --define=\"%_topdir $OUTPUTDIR\" --define=\"%_libdir /usr/lib\" -bb"
  662. rpmbuild_cmd+=" $OUTPUTDIR/SPECS/mediacenter.spec"
  663. debug "$rpmbuild_cmd" || rpmbuild_cmd+=" &>/dev/null"
  664. if eval "$rpmbuild_cmd" && [[ -f "$MCRPM" ]] ; then
  665. echo "Build successful. The RPM file is located at: $MCRPM"
  666. else
  667. err "Build failed"
  668. # For automation, let's remove the source DEB and reaquire it on next run
  669. # after failure in case it is corrupted or buggy
  670. [[ -f "$MCDEB" ]] && echo "Removing source DEB" && rm -f "$MCDEB"
  671. exit 1
  672. fi
  673. }
  674. #######################################
  675. # Installs local Media Center DEB package and optional compatability fixes
  676. #######################################
  677. installMCDEB() {
  678. debug "Running: ${FUNCNAME[0]}"
  679. declare pkg_install_cmd="installPackage --skip-check-installed --no-gpg-check"
  680. if (( COMPAT_SWITCH )); then
  681. declare extract_dir && extract_dir="$(mktemp -d)"
  682. pushd "$extract_dir" &>/dev/null || return
  683. ar x "$MCDEB"
  684. tar -xJf "control.tar.xz"
  685. # Remove minimum version specifiers from control file
  686. sed -i 's/ ([^)]*)//g' "control"
  687. sed -i 's/([^)]*)//g' "control" # TODO MC DEB package error
  688. [[ "$ID" == "ubuntu" && "${VERSION_ID%.*}" -le 16 ]] &&
  689. sed -i 's/libva2/libva1/g' "control"
  690. tar -cJf "control.tar.xz" "control" "postinst"
  691. declare -g MCDEB="${MCDEB/.deb/.compat.deb}"
  692. ar rcs "$MCDEB" "debian-binary" "control.tar.xz" "data.tar.xz"
  693. popd &>/dev/null || return
  694. rm -rf "$extract_dir"
  695. pkg_install_cmd+=" --allow-downgrades"
  696. fi
  697. pkg_install_cmd+=" $MCDEB"
  698. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  699. eval "$pkg_install_cmd"
  700. }
  701. #######################################
  702. # Installs local Media Center RPM package
  703. #######################################
  704. installMCRPM() {
  705. debug "Running: ${FUNCNAME[0]}"
  706. installPackage --skip-check-installed --no-gpg-check --allow-downgrades "$MCRPM"
  707. }
  708. #######################################
  709. # Installs local Media Center PKGBUILD
  710. #######################################
  711. installMCARCH() {
  712. debug "Running: ${FUNCNAME[0]}"
  713. echo "Arch install under construction"
  714. }
  715. #######################################
  716. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  717. #######################################
  718. runCreaterepo() {
  719. debug "Running: ${FUNCNAME[0]}"
  720. declare cr_cmd cr_cp_cmd cr_mkdir_cmd cr_chown_cmd
  721. installPackage createrepo_c
  722. # If the webroot does not exist, create it
  723. if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then
  724. cr_mkdir_cmd="sudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT"
  725. debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
  726. if ! eval "$cr_mkdir_cmd"; then
  727. cr_mkdir_cmd="sudo mkdir -p $CREATEREPO_WEBROOT"
  728. debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
  729. cr_chown_cmd="sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
  730. debug "$cr_chown_cmd" || cr_chown_cmd+=" &>/dev/null"
  731. if ! ( eval "$cr_mkdir_cmd" && eval "$cr_chown_cmd" ); then
  732. err "Could not create the createrepo-webroot path!"
  733. err "Make sure that the webroot $CREATEREPO_WEBROOT is writeable by user $CREATEREPO_USER"
  734. err "Or change the repo ownership with --createrepo-user"
  735. return 1
  736. fi
  737. fi
  738. fi
  739. # Copy built rpms to webroot
  740. cr_cp_cmd="sudo cp -nf $MCRPM $CREATEREPO_WEBROOT"
  741. cr_chown_cmd="sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
  742. debug "$cr_cp_cmd" || cr_cp_cmd+=" &>/dev/null"
  743. debug "$cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null"
  744. if ! ( eval "$cr_cp_cmd" && eval "$cr_chown_cmd" ); then
  745. err "Could not copy $MCRPM to $CREATEREPO_WEBROOT"
  746. return 1
  747. fi
  748. # Run createrepo
  749. cr_cmd="sudo -u $CREATEREPO_USER createrepo -q $CREATEREPO_WEBROOT"
  750. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
  751. debug "$cr_cmd" || cr_cmd+=" &>/dev/null"
  752. if ! eval "$cr_cmd"; then
  753. cr_cmd="sudo createrepo -q $CREATEREPO_WEBROOT"
  754. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
  755. cr_chown_cmd="sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
  756. debug "$cr_cmd" || cr_cmd+=" &>/dev/null"
  757. debug "$cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null"
  758. if ! ( eval "$cr_cmd" && eval "$cr_chown_cmd"); then
  759. err "Createrepo failed"
  760. return 1
  761. fi
  762. fi
  763. }
  764. #######################################
  765. # Symlink certificates if they do not exist in default location
  766. #######################################
  767. symlinkCerts() {
  768. debug "Running: ${FUNCNAME[0]}"
  769. declare mc_cert_link="/usr/lib/jriver/Media Center $MVERSION/ca-certificates.crt"
  770. declare target_cert ln_cmd
  771. target_cert=$(readlink -f "$mc_cert_link")
  772. [[ -f $target_cert ]] && return 0
  773. # Have to use command array instead of eval because of whitespace in $mc_cert_link
  774. if [[ -f /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ]]; then
  775. ln_cmd="sudo ln -fs /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem \"$mc_cert_link\"" # For RHEL
  776. elif [[ -f /var/lib/ca-certificates/ca-bundle.pem ]]; then
  777. ln_cmd="sudo ln -fs /var/lib/ca-certificates/ca-bundle.pem \"$mc_cert_link\"" # For SUSE
  778. fi
  779. debug "$ln_cmd" || ln_cmd+=" &>/dev/null"
  780. if ! eval "$ln_cmd"; then
  781. err "Symlinking certificates failed"
  782. return 1
  783. fi
  784. }
  785. #######################################
  786. # Restore the mjr license file if it is next to installJRMC or RESTOREFILE is set
  787. #######################################
  788. restoreLicense() {
  789. debug "Running: ${FUNCNAME[0]}"
  790. declare mjrfile
  791. # Allow user to put the mjr file next to installJRMC
  792. if [[ ! -v RESTOREFILE ]]; then
  793. for mjrfile in "$PWD"/*.mjr; do
  794. [[ $mjrfile -nt $RESTOREFILE ]] && RESTOREFILE="$mjrfile"
  795. done
  796. fi
  797. # Restore license
  798. if [[ -f "$RESTOREFILE" ]]; then
  799. if ! "mediacenter$MVERSION" /RestoreFromFile "$RESTOREFILE"; then
  800. err "Automatic license restore failed"
  801. return 1
  802. fi
  803. fi
  804. }
  805. #######################################
  806. # Opens ports using the system firewall tool
  807. # Arguments:
  808. # Pre-defined service to enable
  809. #######################################
  810. openFirewall() {
  811. debug "Running: ${FUNCNAME[0]}" "$@"
  812. # Create OS-specific port rules based on argument (service) name
  813. declare -a f_ports # for firewall-cmd
  814. declare u_ports # for ufw
  815. #declare -a n_ports # for nftables
  816. declare port
  817. if [[ "$1" == "jriver-mediacenter" ]]; then
  818. f_ports=(52100-52200/tcp 1900/udp)
  819. u_ports="52100:52200/tcp|1900/udp"
  820. #n_ports=("tcp dport 52100-52200 accept" "udp dport 1900 accept")
  821. elif [[ "$1" =~ ^(jriver-x11vnc|jriver-xvnc)$ ]]; then
  822. f_ports=("$PORT"/tcp 1900/udp)
  823. u_ports="$PORT/tcp|1900/udp"
  824. #n_ports=("tcp dport $PORT accept" "udp dport 1900 accept")
  825. fi
  826. # Open the ports
  827. if ! case "$ID" in
  828. fedora|centos|suse)
  829. hash firewall-cmd 2>/dev/null || installPackage firewalld
  830. if ! firewall_cmd --get-services | grep -q "$1"; then
  831. firewall_cmd --permanent --new-service="$1" &>/dev/null
  832. firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" &>/dev/null
  833. firewall_cmd --permanent --service="$1" --set-short="$1" &>/dev/null
  834. for port in "${f_ports[@]}"; do
  835. firewall_cmd --permanent --service="$1" --add-port="$port" &>/dev/null
  836. done
  837. firewall_cmd --add-service "$1" --permanent &>/dev/null
  838. firewall_cmd --reload &>/dev/null
  839. fi
  840. ;;
  841. debian|ubuntu)
  842. # Debian ufw package state is broken on fresh installations
  843. hash ufw 2>/dev/null || installPackage ufw
  844. if [[ ! -f "/etc/ufw/applications.d/$1" ]]; then
  845. sudo bash -c "cat <<-EOF > /etc/ufw/applications.d/$1
  846. [$1]
  847. title=$1
  848. description=$1 installed by installJRMC
  849. ports=$u_ports
  850. EOF"
  851. fi
  852. firewall_cmd app update "$1" &>/dev/null
  853. firewall_cmd allow "$1" &>/dev/null
  854. ;;
  855. arch)
  856. # sysctl -w net.ipv4.ip_forward = 1
  857. # sudo nft create table inet "jriver"
  858. # sudo nft create chain inet "jriver" "$1" '{ type filter hook input priority 0; policy accept; }'
  859. # for port in "${n_ports[@]}"; do
  860. # sudo nft add rule inet jriver "$1" handle tcp dport "$port"
  861. # done
  862. ;;
  863. esac; then
  864. err "Firewall ports could not be opened"
  865. return 1
  866. fi
  867. }
  868. #######################################
  869. # Create the xvnc or x11vnc password file
  870. # Arguments:
  871. # Service type (xvnc, x11vnc)
  872. #######################################
  873. setVNCPass() {
  874. debug "Running: ${FUNCNAME[0]}"
  875. declare vncpassfile="$HOME/.vnc/jrmc_passwd"
  876. declare vnc_pass_cmd
  877. [[ ! -d "${vncpassfile%/*}" ]] && mkdir -p "${vncpassfile%/*}"
  878. if [[ -f "$vncpassfile" ]]; then
  879. if [[ ! -v VNCPASS ]]; then
  880. err "Refusing to overwrite existing $vncpassfile with an empty password"
  881. err "Remove existing $vncpassfile or set --vncpass to use an empty password"
  882. exit 1
  883. else
  884. rm -f "$vncpassfile"
  885. fi
  886. fi
  887. if [[ -v VNCPASS ]]; then
  888. if [[ $1 == "xvnc" ]]; then
  889. vnc_pass_cmd="echo $VNCPASS | vncpasswd -f > $vncpassfile"
  890. elif [[ $1 == "x11vnc" ]]; then
  891. vnc_pass_cmd="x11vnc -storepasswd $VNCPASS $vncpassfile"
  892. fi
  893. if ! eval "$vnc_pass_cmd"; then
  894. err "Could not create VNC password file"
  895. return 1
  896. fi
  897. else
  898. declare -g NOVNCAUTH=1
  899. fi
  900. }
  901. #######################################
  902. # Set display and port variables
  903. #######################################
  904. setDisplay() {
  905. debug "Running: ${FUNCNAME[0]}"
  906. declare -g DISPLAY DISPLAYNUM NEXT_DISPLAY NEXT_DISPLAYNUM
  907. # Check USER_DISPLAY, else environment DISPLAY, else set to :0 by default
  908. DISPLAY="${USER_DISPLAY:-${DISPLAY:-0}}"
  909. DISPLAYNUM="${DISPLAY#*:}" # strip prefix
  910. DISPLAYNUM="${DISPLAYNUM%%.*}" # strip suffix
  911. NEXT_DISPLAYNUM=$(( DISPLAYNUM + 1 ))
  912. NEXT_DISPLAY=":$NEXT_DISPLAYNUM"
  913. }
  914. #######################################
  915. # Create associated service variables based on service name
  916. # Arguments
  917. # Pre-defined service name
  918. #######################################
  919. setServiceVars() {
  920. debug "Running: ${FUNCNAME[0]}"
  921. declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME USER_STRING GRAPHICAL_TARGET
  922. declare -g SERVICE_TYPE="${SERVICE_TYPE:-system}"
  923. declare service_dir="/usr/lib/systemd/$SERVICE_TYPE"
  924. if [[ "$USER" == "root" && "$SERVICE_TYPE" == "user" ]]; then
  925. err "Trying to install user service as root"
  926. err "Use --service-type service and/or execute installJRMC as non-root user"
  927. return 1
  928. fi
  929. if [[ "$SERVICE_TYPE" == "system" ]]; then
  930. systemctl_reload_cmd(){ sudo systemctl daemon-reload; }
  931. systemctl_enable_cmd(){ sudo systemctl enable --now "$@"; }
  932. systemctl_disable_cmd(){ sudo systemctl disable --now "$@"; }
  933. systemctl_is_enabled_cmd(){ sudo systemctl is-enabled -q "$@"; }
  934. systemctl_is_active_cmd(){ sudo systemctl is-active -q "$@"; }
  935. GRAPHICAL_TARGET="graphical.target"
  936. elif [[ "$SERVICE_TYPE" == "user" ]]; then
  937. systemctl_reload_cmd(){ systemctl --user daemon-reload; }
  938. systemctl_enable_cmd(){ systemctl --user enable --now "$@"; }
  939. systemctl_disable_cmd(){ systemctl --user disable --now "$@"; }
  940. systemctl_is_enabled_cmd(){ systemctl --user is-enabled -q "$@"; }
  941. systemctl_is_active_cmd(){ systemctl --user is-active -q "$@"; }
  942. GRAPHICAL_TARGET="default.target"
  943. fi
  944. [[ ! -d "$service_dir" ]] && sudo mkdir -p "$service_dir"
  945. if [[ "$SERVICE_TYPE" == "system" && "$USER" != "root" ]]; then
  946. SERVICE_FNAME="$service_dir/${1}@.service"
  947. TIMER_FNAME="$service_dir/${1}@.timer"
  948. SERVICE_NAME="${1}@$USER.service"
  949. TIMER_NAME="${1}@$USER.timer"
  950. USER_STRING="User=%I"
  951. else
  952. SERVICE_NAME="${1}.service"
  953. TIMER_NAME="${1}.timer"
  954. SERVICE_FNAME="$service_dir/${SERVICE_NAME}"
  955. TIMER_FNAME="$service_dir/${TIMER_NAME}"
  956. USER_STRING=""
  957. fi
  958. }
  959. #######################################
  960. # Starts and enables (at startup) a JRiver Media Center service
  961. # Arguments:
  962. # Passes arguments as startup options to /usr/bin/mediacenter??
  963. #######################################
  964. service_jriver-mediacenter() {
  965. debug "Running: ${FUNCNAME[0]}"
  966. setServiceVars "${FUNCNAME[0]##*_}"
  967. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  968. [Unit]
  969. Description=JRiver Media Center $MVERSION
  970. After=$GRAPHICAL_TARGET
  971. [Service]
  972. $USER_STRING
  973. Type=simple
  974. ExecStart=/usr/bin/mediacenter$MVERSION $*
  975. Restart=always
  976. RestartSec=10
  977. KillSignal=SIGHUP
  978. TimeoutStopSec=30
  979. [Install]
  980. WantedBy=$GRAPHICAL_TARGET
  981. EOF"
  982. systemctl_reload_cmd &&
  983. systemctl_enable_cmd "$SERVICE_NAME" &&
  984. openFirewall "jriver-mediacenter"
  985. }
  986. #######################################
  987. # Starts and enables (at startup) a JRiver Media Server service
  988. #######################################
  989. service_jriver-mediaserver() {
  990. debug "Running: ${FUNCNAME[0]}"
  991. setServiceVars "${FUNCNAME[0]##*_}"
  992. service_jriver-mediacenter "/MediaServer"
  993. }
  994. #######################################
  995. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  996. #######################################
  997. service_jriver-xvnc() {
  998. debug "Running: ${FUNCNAME[0]}"
  999. setServiceVars "${FUNCNAME[0]##*_}"
  1000. setDisplay
  1001. declare start_cmd
  1002. declare -g PORT=$(( NEXT_DISPLAYNUM + 5900 ))
  1003. installPackage tigervnc-server
  1004. setVNCPass xvnc
  1005. if (( NOVNCAUTH )); then
  1006. start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -name jriver$NEXT_DISPLAY -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$MVERSION"
  1007. else
  1008. start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$MVERSION"
  1009. fi
  1010. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1011. [Unit]
  1012. Description=Remote desktop service (VNC)
  1013. After=multi-user.target
  1014. [Service]
  1015. Type=forking
  1016. $USER_STRING
  1017. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
  1018. ExecStart=$start_cmd
  1019. ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
  1020. Restart=always
  1021. [Install]
  1022. WantedBy=multi-user.target
  1023. EOF"
  1024. systemctl_reload_cmd &&
  1025. systemctl_enable_cmd "$SERVICE_NAME" &&
  1026. echo "Xvnc running on localhost:$PORT" &&
  1027. openFirewall "jriver-xvnc" &&
  1028. openFirewall "jriver-mediacenter"
  1029. }
  1030. #######################################
  1031. # Starts and enables (at startup) x11vnc screen sharing for the local desktop
  1032. #######################################
  1033. service_jriver-x11vnc() {
  1034. debug "Running: ${FUNCNAME[0]}"
  1035. setServiceVars "${FUNCNAME[0]##*_}"
  1036. setDisplay
  1037. declare start_cmd
  1038. declare -g PORT=$(( DISPLAYNUM + 5900 ))
  1039. installPackage x11vnc
  1040. setVNCPass x11vnc
  1041. # If .Xauthority file is missing, generate a dummy for x11vnc -auth guess
  1042. if [[ ! -f "$HOME/.Xauthority" ]]; then
  1043. [[ "$XDG_SESSION_TYPE" == "wayland" ]] && ask_ok "Unsupported Wayland session detected for x11vnc, continue?" || return 1
  1044. touch "$HOME/.Xauthority"
  1045. xauth generate "$DISPLAY" . trusted
  1046. xauth add "$HOST$DISPLAY" . "$(xxd -l 16 -p /dev/urandom)"
  1047. fi
  1048. if (( NOVNCAUTH )); then
  1049. start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -nopw"
  1050. else
  1051. start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd"
  1052. fi
  1053. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1054. [Unit]
  1055. Description=x11vnc
  1056. After=$GRAPHICAL_TARGET
  1057. [Service]
  1058. $USER_STRING
  1059. Type=forking
  1060. Environment=DISPLAY=$DISPLAY
  1061. ExecStart=$start_cmd
  1062. Restart=always
  1063. RestartSec=10
  1064. [Install]
  1065. WantedBy=$GRAPHICAL_TARGET
  1066. EOF"
  1067. systemctl_reload_cmd &&
  1068. systemctl_enable_cmd "$SERVICE_NAME" &&
  1069. echo "x11vnc running on localhost:$PORT" &&
  1070. openFirewall "jriver-x11vnc"
  1071. }
  1072. #######################################
  1073. # Starts and enables (at startup) an hourly service to build the latest version of JRiver Media
  1074. # Center RPM from the source DEB and create/update an RPM repository
  1075. #######################################
  1076. service_jriver-createrepo() {
  1077. debug "Running: ${FUNCNAME[0]}"
  1078. if [[ "$CREATEREPO_USER" != "$USER" ]]; then
  1079. USER="root" SERVICE_TYPE="system" setServiceVars "${FUNCNAME[0]##*_}"
  1080. else
  1081. setServiceVars "${FUNCNAME[0]##*_}"
  1082. fi
  1083. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1084. [Unit]
  1085. Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo
  1086. [Service]
  1087. $USER_STRING
  1088. ExecStart=$PWD/installJRMC --outputdir $OUTPUTDIR --createrepo=$TARGET --createrepo-webroot $CREATEREPO_WEBROOT --createrepo-user $CREATEREPO_USER
  1089. [Install]
  1090. WantedBy=multi-user.target
  1091. EOF"
  1092. sudo bash -c "cat <<-EOF > $TIMER_FNAME
  1093. [Unit]
  1094. Description=Run JRiver MC rpmbuild hourly
  1095. [Timer]
  1096. OnCalendar=hourly
  1097. Persistent=true
  1098. [Install]
  1099. WantedBy=timers.target
  1100. EOF"
  1101. systemctl_reload_cmd &&
  1102. systemctl_enable_cmd "$TIMER_NAME"
  1103. }
  1104. #######################################
  1105. # CONTAINERS
  1106. #######################################
  1107. # container_jriver-createrepo() {
  1108. # :
  1109. # }
  1110. # container_jriver-xvnc() {
  1111. # :
  1112. # }
  1113. # container_jriver-mediacenter() {
  1114. # installPackage buildah podman
  1115. # # Eventually try to switch to Debian
  1116. # # if ! CNT=$(buildah from debian:$DEBIANBASE); then
  1117. # # echo "Bad base image for container $CNAME, skipping"
  1118. # # continue
  1119. # # fi
  1120. # if ! CNT=$(buildah from jlesage/baseimage-gui:debian-10-v3.5.7); then
  1121. # echo "Bad base image for container $CNAME, skipping"
  1122. # continue
  1123. # fi
  1124. # buildah run "$CNT" add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg
  1125. # # #BASEIMAGE=jlesage/baseimage-gui:debian-10-v3.5.7
  1126. # # JRIVER_RELEASE=28
  1127. # # JRIVER_TAG=stable
  1128. # # ARCH=amd64
  1129. # # REBUILD_MIN=22
  1130. # # REBUILD_MAX=120
  1131. # # # JRiver Version tag (latest, stable or beta)
  1132. # # ARG jriver_tag
  1133. # # # JRiver Release Version (25, 26 etc.)
  1134. # # ARG jriver_release
  1135. # # # Image Version of the build
  1136. # # ARG image_version
  1137. # # # .deb download URL, if set to "repository" the JRiver repository will be used
  1138. # # ARG deb_url
  1139. # # RUN add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg
  1140. # # Install JRiver
  1141. # RUN \
  1142. # add-pkg --virtual build-dependencies wget &&
  1143. # # Install from Repository
  1144. # if [ "${deb_url}" = "repository" ]; then \
  1145. # echo "Installing JRiver from repository ${jriver_release}:${jriver_tag}" &&
  1146. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &&
  1147. # wget http://dist.jriver.com/${jriver_tag}/mediacenter/mediacenter${jriver_release}.list -O /etc/apt/sources.list.d/mediacenter${jriver_release}.list &&
  1148. # apt update &&
  1149. # add-pkg mediacenter${jriver_release}; \
  1150. # # Install from .deb URL
  1151. # else \
  1152. # echo "Installing JRiver from URL: ${deb_url}" &&
  1153. # wget -q -O "jrivermc.deb" ${deb_url} &&
  1154. # add-pkg "./jrivermc.deb"; \
  1155. # fi &&
  1156. # # Cleanup
  1157. # del-pkg build-dependencies &&
  1158. # rm -rf /tmp/* /tmp/.[!.]*
  1159. # # Add rootfs
  1160. # COPY rootfs/ /
  1161. # VOLUME ["/config"]
  1162. # # Application Icon
  1163. # RUN \
  1164. # APP_ICON_URL=https://gitlab.com/shiomax/jrivermc-docker/raw/master/assets/Application.png &&
  1165. # install_app_icon.sh "$APP_ICON_URL"
  1166. # # Various configuration vars
  1167. # ENV KEEP_APP_RUNNING=1 \
  1168. # DISPLAY_WIDTH=1280 \
  1169. # DISPLAY_HEIGHT=768 \
  1170. # APP_NAME="JRiver MediaCenter ${jriver_release}" \
  1171. # MAXIMIZE_POPUPS=0 \
  1172. # S6_KILL_GRACETIME=8000
  1173. # # Modify startapp.sh and rc.xml with JRiver version
  1174. # RUN sed-patch s/%%MC_VERSION%%/${jriver_release}/g \
  1175. # /startapp.sh &&
  1176. # sed-patch s/%%MC_VERSION%%/${jriver_release}/g \
  1177. # /etc/xdg/openbox/rc.xml
  1178. # EXPOSE 5800 5900 52100 52101 52199 1900/udp
  1179. # # Metadata.
  1180. # LABEL \
  1181. # org.label-schema.name="jrivermc${jriver_release}" \
  1182. # org.label-schema.description="Docker image for JRiver Media Center ${jriver_release}" \
  1183. # org.label-schema.version="${image_version}" \
  1184. # org.label-schema.vcs-url="https://gitlab.com/shiomax/jrivermc-docker" \
  1185. # org.label-schema.schema-version="1.0"
  1186. # installPackage buildah podman
  1187. # cnt=$(buildah from docker.io/jlesage/baseimage-gui:debian-10)
  1188. # podman_create_cmd=(podman create --name "$CNAME")
  1189. # buildah_config_cmd=(buildah config \
  1190. # --author bryanroessler@gmail.com \
  1191. # --label maintainer="$MAINTAINER" \
  1192. # --env TZ="$TZ" \
  1193. # --workingdir /app \
  1194. # --cmd mediacenter"$MVERSION")
  1195. # mkcdirs() {
  1196. # declare dir
  1197. # for dir in "$@"; do
  1198. # if [[ ! -d "$dir" ]]; then
  1199. # if ! mkdir -p "$dir"; then
  1200. # err "Could not create directory $dir, check your permissions"
  1201. # fi
  1202. # fi
  1203. # if ! chcon -t container_file_t -R "$dir"; then
  1204. # err "Could not set container_file_t attribute for $dir, check your permissions"
  1205. # fi
  1206. # done
  1207. # }
  1208. # mkcdirs "$HOME/.jriver"
  1209. # podman_create_cmd+=(-v "$HOME/.jriver:/root/.jriver")
  1210. # podman_create_cmd+=(-v "$DOWNLOAD_ROOT:/downloads:z")
  1211. # podman_create_cmd+=(-v "$MONITOR_ROOT/nzbs:/nzbs")
  1212. # podman_create_cmd+=(-p "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1213. # brc() { buildah run "$1" "${@:2}" || return 1; }
  1214. # brc add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1
  1215. # brc add-pkg --virtual .build-deps wget
  1216. # brc sh -s <<-EOF
  1217. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &>/dev/null
  1218. # EOF
  1219. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list"
  1220. # brc apt update -y -q0
  1221. # brc add-pkg "mediacenter$MVERSION"
  1222. # brc del-pkg .build-deps
  1223. # }
  1224. #######################################
  1225. # Detects if MC is installed on btrfs and disables CoW
  1226. #######################################
  1227. disableCoW() {
  1228. debug "Running: ${FUNCNAME[0]}"
  1229. declare dir
  1230. declare mc_system_path="/usr/lib/jriver"
  1231. declare mc_user_path="$HOME/.jriver"
  1232. [[ -d "$mc_user_path" ]] || mkdir -p "$mc_user_path"
  1233. for dir in "$mc_system_path" "$mc_user_path"; do
  1234. [[ -d "$dir" ]] || return
  1235. if [[ $(stat -f -c %T "$dir") == "btrfs" ]] &&
  1236. ! lsattr -d "$dir" | cut -f1 -d" " | grep -q C; then
  1237. echo "Disabling CoW for $dir"
  1238. sudo chattr +C "$dir"
  1239. fi
  1240. done
  1241. }
  1242. #######################################
  1243. # Migrate major versions
  1244. #######################################
  1245. migrateLibrary() {
  1246. debug "Running: ${FUNCNAME[0]}"
  1247. declare mc_user_path="$HOME/.jriver"
  1248. declare current_config_path="$mc_user_path/Media Center $MVERSION"
  1249. declare previous_config_path="$mc_user_path/Media Center $(( MVERSION - 1 ))"
  1250. if [[ ! -d "$current_config_path" ]] &&
  1251. [[ -d "$previous_config_path" ]] &&
  1252. mkdir -p "$current_config_path"; then
  1253. echo "Migrating $previous_config_path to $current_config_path"
  1254. cp -fa "$previous_config_path"/* "$current_config_path" &>/dev/null
  1255. fi
  1256. }
  1257. #######################################
  1258. # Completely uninstalls MC, services, and firewall rules
  1259. #######################################
  1260. uninstall() {
  1261. debug "Running: ${FUNCNAME[0]}"
  1262. declare service unit f i
  1263. echo "Stopping and removing all Media Center services"
  1264. for service in $(compgen -A "function" "service"); do
  1265. service="${service##service_}"
  1266. for i in user system; do
  1267. SERVICE_TYPE="$i" setServiceVars "$service";
  1268. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1269. if systemctl_is_active_cmd "$unit" &>/dev/null ||
  1270. systemctl_is_enabled_cmd "$unit" &>/dev/null; then
  1271. debug "Disabling $unit"
  1272. systemctl_disable_cmd "$unit"
  1273. fi
  1274. done
  1275. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1276. [[ -f "$f" ]] && debug "Removing $f" && sudo rm -f "$f"
  1277. done
  1278. systemctl_reload_cmd
  1279. done
  1280. for f in /etc/systemd/system/jriver-*; do
  1281. sudo rm -f "$f"
  1282. done
  1283. done
  1284. echo "Removing repo files"
  1285. sudo rm -rf \
  1286. "/etc/yum.repos.d/jriver.repo" \
  1287. /etc/apt/sources.list.d/{jriver,mediacenter}*.list # also remove legacy repo files
  1288. if [[ "$ID" == "suse" ]]; then
  1289. sudo zypper rr jriver &>/dev/null
  1290. fi
  1291. echo "Removing firewall rules"
  1292. if hash firewall-cmd 2>/dev/null; then
  1293. if [[ -v debug ]]; then
  1294. debug "firewall_cmd --permanent --remove-service=jriver"
  1295. firewall_cmd --permanent --remove-service=jriver
  1296. debug "firewall_cmd --permanent --delete-service=jriver"
  1297. firewall_cmd --permanent --delete-service=jriver
  1298. debug "firewall_cmd --reload"
  1299. firewall_cmd --reload
  1300. else
  1301. firewall_cmd --permanent --remove-service=jriver &>/dev/null
  1302. firewall_cmd --permanent --delete-service=jriver &>/dev/null
  1303. firewall_cmd --reload &>/dev/null
  1304. fi
  1305. elif hash ufw 2>/dev/null; then
  1306. firewall_cmd="firewall_cmd delete allow jriver"
  1307. debug "$firewall_cmd" || firewall_cmd+=" &>/dev/null"
  1308. eval "$firewall_cmd"
  1309. [[ -f "/etc/ufw/applications.d/jriver" ]] &&
  1310. sudo rm -f /etc/ufw/applications.d/jriver
  1311. # elif hash nft 2>/dev/null; then
  1312. # sudo nft delete table inet jriver
  1313. fi
  1314. echo "Uninstalling JRiver Media Center package"
  1315. mc_pkg_rm_cmd="pkg_remove $MCPKG"
  1316. debug "$mc_pkg_rm_cmd" || mc_pkg_rm_cmd+=" &>/dev/null"
  1317. if eval "$mc_pkg_rm_cmd"; then
  1318. echo "JRiver Media Center has been completely uninstalled"
  1319. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1320. elif [[ $? -eq 100 ]]; then
  1321. err "JRiver Media Center package '$MCPKG' is not present and was not uninstalled"
  1322. else
  1323. err "Could not remove Media Center package"
  1324. fi
  1325. }
  1326. tests() {
  1327. # To test on Mint/16.04: sudo apt install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1328. : # TODO
  1329. }
  1330. main() {
  1331. init
  1332. parseInput "$@"
  1333. if (( DEBUG )); then
  1334. echo "Debugging on"
  1335. echo "installJRMC version: $SCRIPTVERSION"
  1336. fi
  1337. if ((TEST_SWITCH)); then
  1338. echo "Running tests, all other options are skipped"
  1339. tests
  1340. exit
  1341. fi
  1342. setMCVersion
  1343. if (( UNINSTALL_SWITCH )); then
  1344. if askOk "Do you really want to uninstall JRiver Media Center?"; then
  1345. uninstall
  1346. else
  1347. echo "Uninstall canceled."
  1348. fi
  1349. exit
  1350. fi
  1351. # Install external repos, if required
  1352. case "$ID" in
  1353. ubuntu)
  1354. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  1355. echo "Adding universe repository"
  1356. sudo add-apt-repository universe
  1357. fi
  1358. ;;
  1359. centos)
  1360. if ! hash dpkg &>/dev/null; then
  1361. echo "Adding EPEL repository"
  1362. installPackage epel-release
  1363. fi
  1364. if ! pkg_query rpmfusion-free-release &>/dev/null; then
  1365. installPackage --skip-check-installed \
  1366. "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1367. fi
  1368. ;;
  1369. fedora)
  1370. if ! pkg_query rpmfusion-free-release &>/dev/null; then
  1371. installPackage --skip-check-installed \
  1372. "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1373. fi
  1374. ;;
  1375. esac
  1376. if (( REPO_INSTALL_SWITCH )); then
  1377. echo "Installing JRiver Media Center from remote repository"
  1378. if installMCFromRepo; then
  1379. echo "JRiver Media Center installed successfully from repo"
  1380. symlinkCerts
  1381. migrateLibrary
  1382. restoreLicense
  1383. openFirewall "jriver-mediacenter"
  1384. disableCoW
  1385. else
  1386. err "JRiver Media Center installation from repo failed"
  1387. return 1
  1388. fi
  1389. fi
  1390. if (( BUILD_SWITCH )); then
  1391. installPackage "wget"
  1392. acquireDeb
  1393. if [[ "$TARGET" =~ (centos|fedora|suse) ]]; then
  1394. installPackage "dpkg" "rpm-build"
  1395. buildRPM
  1396. fi
  1397. fi
  1398. if (( LOCAL_INSTALL_SWITCH )); then
  1399. if pkg_install_local; then
  1400. echo "JRiver Media Center installed successfully from local package"
  1401. else
  1402. err "JRiver Media Center local package installation failed"
  1403. return 1
  1404. fi
  1405. symlinkCerts
  1406. migrateLibrary
  1407. restoreLicense
  1408. openFirewall "jriver-mediacenter"
  1409. disableCoW
  1410. fi
  1411. if (( CREATEREPO_SWITCH )); then
  1412. if runCreaterepo; then
  1413. echo "Successfully updated repo"
  1414. else
  1415. err "Repo creation failed"
  1416. fi
  1417. fi
  1418. if [[ "${#SERVICES[@]}" -gt 0 ]]; then
  1419. declare service
  1420. for service in "${SERVICES[@]}"; do
  1421. if ! "service_$service"; then
  1422. if [[ $? -eq 127 ]]; then
  1423. err "Service $service does not exist, check your service name"
  1424. else
  1425. err "Failed to create service: $service"
  1426. fi
  1427. fi
  1428. done
  1429. fi
  1430. # for _container in "${CONTAINERS[@]}"; do
  1431. # if ! "_container_$_container"; then
  1432. # if [[ $? -eq 127 ]]; then
  1433. # err "Container $_container does not exist, check your container name"
  1434. # else
  1435. # err "Failed to create container: $_container"
  1436. # fi
  1437. # fi
  1438. # done
  1439. }
  1440. # Quickly turn debugging on (catch for real with getopt in parseInput())
  1441. [[ " $* " =~ ( --debug | -d ) ]] && echo "First Debugging on!" && DEBUG=1
  1442. main "$@"