installJRMC 59 KB

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