installJRMC 58 KB

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