installJRMC 57 KB

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