installJRMC 57 KB

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