installJRMC 56 KB

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