installJRMC 56 KB

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