installJRMC 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. #!/usr/bin/env bash
  2. # This script will install JRiver Media Center and associated services
  3. # on Fedora, CentOS, Debian, and Ubuntu
  4. # Copyright (c) 2021 Bryan C. Roessler
  5. # This software is released under the Apache License.
  6. # https://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Use installJRMC --help to see available options or
  9. # read printHelp() below.
  10. #
  11. # TODO
  12. # 1. Raspberry Pi OS support
  13. # 2. Interactive installation (ncurses?)
  14. # 3. Additional containerization (createrepo and rpmbuild)
  15. # 4. Tests
  16. #
  17. # BUGS
  18. # 1. SUSE probably broken
  19. # 2. No createrepo on Mint
  20. shopt -s extglob
  21. _scriptversion="1.0b4"
  22. _outputdir="$PWD/output"
  23. _createrepo_webroot="/var/www/jriver"
  24. _exec_user="$(whoami)"
  25. _systemddir="/usr/lib/systemd/system"
  26. # MC version
  27. # _mcversion="28.0.87" # to set manually, if unset use automatic latest check
  28. printHelp() {
  29. debug "Running: ${FUNCNAME[0]}"
  30. cat <<- 'EOF'
  31. USAGE:
  32. installJRMC [[OPTION] [VALUE]]...
  33. If no options (besides -d) are provided, the script will default to '--install repo'.
  34. OPTIONS
  35. --install, -i repo|rpm
  36. repo: Install MC from repository, updates are handled by the system package manager
  37. rpm: Build and install RPM locally (RPM-based distros only)
  38. --build
  39. Build RPM from source DEB (but don't install it)
  40. --build-suse
  41. Override OS detection and build SUSE RPM
  42. --mcversion VERSION
  43. Specify the MC version, ex. "28.0.25" (Default: latest version)
  44. --outputdir PATH
  45. Generate rpmbuild output in this directory (Default: $PWD/output)
  46. --restorefile RESTOREFILE
  47. Restore file location for automatic license registration (Default: skip registration)
  48. --betapass PASSWORD
  49. Enter beta team password for access to beta builds
  50. --service, -s SERVICE
  51. See SERVICES section below for a list of possible services to install
  52. --service-user USER
  53. Install systemd services and containers for user USER (Default: current user)
  54. --container, -c CONTAINER (TODO: Under construction)
  55. See CONTAINERS section below for a list of possible services to install
  56. --createrepo
  57. Build rpm, copy to webroot, and run createrepo
  58. --createrepo-webroot PATH
  59. The webroot directory to install the repo (Default: /var/www/jriver)
  60. --createrepo-user USER
  61. The web server user (Default: current user)
  62. --createrepo-suse
  63. Override OS detection and run --createrepo with SUSE RPM
  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. --uninstall, -u
  71. Uninstall JRiver MC, cleanup service files, and remove firewall rules (does not remove library files)
  72. SERVICES
  73. jriver-mediaserver
  74. Enable and start a mediaserver systemd service (requires an existing X server)
  75. jriver-mediacenter
  76. Enable and start a mediacenter systemd service (requires an existing X server)
  77. jriver-x11vnc
  78. Enable and start x11vnc for the local desktop (requires an existing X server)
  79. Usually combined with jriver-mediaserver or jriver-mediacenter services
  80. --vncpass and --display are optional (see below)
  81. jriver-xvnc
  82. Enable and start a new Xvnc session running JRiver Media Center
  83. --vncpass PASSWORD
  84. Set vnc password for x11vnc/Xvnc access. If no password is set, the script
  85. will either use existing password stored in ~/.vnc/jrmc_passwd or use no password
  86. --display DISPLAY
  87. Display to start x11vnc/Xvnc (Default: The current display (x11vnc) or the
  88. current display incremented by 1 (Xvnc))
  89. jriver-createrepo
  90. Install hourly service to build latest MC RPM and run createrepo
  91. CONTAINERS (TODO: Under construction)
  92. mediacenter-xvnc
  93. createrepo
  94. EOF
  95. }
  96. init() {
  97. debug "Running: ${FUNCNAME[0]}"
  98. getOS
  99. # Make sure universe repo is installed on Ubuntu
  100. if [[ "$ID" == "ubuntu" ]]; then
  101. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  102. ifSudo add-apt-repository universe
  103. fi
  104. fi
  105. # Agnostic commands
  106. bash_cmd(){ ifSudo bash -c "$@"; }
  107. rm_cmd(){ ifSudo rm -rf "$@"; }
  108. cp_cmd(){ ifSudo cp -n -f "$@"; }
  109. mkdir_cmd(){ ifSudo mkdir -p "$@"; }
  110. ln_cmd(){ ifSudo ln -s "$@"; }
  111. systemctl_reload(){ ifSudo systemctl daemon-reload; }
  112. systemctl_enable(){ ifSudo systemctl enable --now "$@"; }
  113. systemctl_disable(){ ifSudo systemctl disable --now "$@"; }
  114. # OS-specific commands
  115. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  116. pkg_install(){ ifSudo dnf install -y "$@"; }
  117. pkg_remove(){ ifSudo dnf remove -y "$@"; }
  118. pkg_update(){ ifSudo dnf makecache; }
  119. pkg_query(){ ifSudo rpm -q "$@"; }
  120. firewall_cmd(){ ifSudo firewall-cmd "$@"; }
  121. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  122. pkg_install(){ ifSudo apt-get install -y -q0 "$@"; }
  123. pkg_remove(){ ifSudo apt-get remove --auto-remove -y -q0 "$@"; }
  124. pkg_update(){ ifSudo apt-get update -y -q0; }
  125. pkg_query(){ ifSudo dpkg -s "$@"; }
  126. firewall_cmd(){ ifSudo ufw "$@"; }
  127. elif [[ "$ID" =~ ^opensuse.* ]]; then
  128. pkg_install(){ ifSudo zypper --non-interactive -q install --force --no-confirm "$@"; }
  129. pkg_remove(){ ifSudo zypper --non-interactive -q remove --clean-deps "$@"; }
  130. pkg_update(){ ifSudo zypper --non-interactive -q refresh jriver; }
  131. pkg_query(){ ifSudo rpm -q "$@"; }
  132. firewall_cmd(){ ifSudo firewall-cmd "$@"; }
  133. fi
  134. parseInput "$@"
  135. _service_user="${_service_user:-$_exec_user}"
  136. _createrepo_user="${_createrepo_user:-$_exec_user}"
  137. # Set package aliases
  138. if [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  139. declare -Ag PKG_ALIASES
  140. PKG_ALIASES["xorg-x11-utils"]="xorg-x11"
  141. PKG_ALIASES["rpm-build"]="rpm"
  142. PKG_ALIASES["createrepo_c"]="createrepo"
  143. PKG_ALIASES["tigervnc-server"]="tigervnc-standalone-server"
  144. fi
  145. # Install script dependencies
  146. [[ "$ID" == "centos" ]] && installPackage epel-release
  147. # Select MC version to work with
  148. if [[ -v _mcversion ]]; then
  149. _version_source="user input"
  150. else
  151. getLatestVersion
  152. fi
  153. [[ ! "$_mcversion" =~ ([0-9]+.[0-9]+.[0-9]+) ]] && err "Invalid version number" && exit 1
  154. echo "Using MC version $_mcversion determined by $_version_source"
  155. echo "To override, use --mcversion"
  156. # Extract major version number
  157. _mversion="${_mcversion%%.*}"
  158. # Saving this substituion in case it's needed in the future
  159. # _variation="${_mcversion##*.}"
  160. }
  161. # Some helper functions
  162. askOk() {
  163. local _response
  164. read -r -p "$* [y/N]" _response
  165. _response=${_response,,}
  166. [[ ! "$_response" =~ ^(yes|y)$ ]] && return 1
  167. return 0
  168. }
  169. debug() {
  170. if [[ -v _debug ]]; then
  171. if [[ $# -gt 0 ]]; then
  172. echo "Debug: $*"
  173. fi
  174. else
  175. return 1
  176. fi
  177. }
  178. err() { echo "Error: $*" >&2; }
  179. getOS() {
  180. debug "Running: ${FUNCNAME[0]}"
  181. if [[ -e "/etc/os-release" ]]; then
  182. source "/etc/os-release"
  183. else
  184. err "/etc/os-release not found"
  185. err "Your OS is unsupported"
  186. printHelp && exit 1
  187. fi
  188. debug "Platform: $ID $VERSION_ID"
  189. }
  190. ifSudo() {
  191. local _user="root"
  192. if [[ $# == 0 ]]; then
  193. [[ "$_exec_user" == "root" ]]; return $?
  194. elif [[ $# -eq 2 && "$1" == "-u" ]]; then
  195. _user="$2"
  196. [[ "$_exec_user" == "$_user" ]]; return $?
  197. elif [[ $# -gt 2 && "$1" == "-u" ]]; then
  198. _user="$2"
  199. shift 2
  200. fi
  201. if [[ "$_user" == "$_exec_user" ]]; then
  202. "$@"
  203. else
  204. sudo -u "$_user" "$@"
  205. fi
  206. }
  207. parseInput() {
  208. debug "Running: ${FUNCNAME[0]}"
  209. if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$1" =~ ^(--debug|-d)$ ]]; then
  210. debug "No options passed, defaulting to repo installation method"
  211. _install="repo"
  212. fi
  213. if _input=$(getopt -o +i:vdhus:c: -l install:,build,build-suse,outputdir:,mcversion:,restorefile:,betapass:,service-user:,service:,version,debug,help,uninstall,createrepo,createrepo-suse,createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests -- "$@"); then
  214. eval set -- "$_input"
  215. while true; do
  216. case "$1" in
  217. --install|-i)
  218. shift
  219. _install="$1"
  220. if [[ "$_install" == "rpm" ]]; then
  221. if [[ ! "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  222. err "RPM install method not available on $ID"
  223. printHelp && exit 1
  224. fi
  225. _build=true
  226. fi
  227. ;;
  228. --build)
  229. _build=true
  230. ;;
  231. --build-suse)
  232. _build=true
  233. _build_suse=true
  234. ;;
  235. --outputdir)
  236. shift && _outputdir="$1"
  237. ;;
  238. --mcversion)
  239. shift && _mcversion="$1"
  240. ;;
  241. --restorefile)
  242. shift && _restorefile="$1"
  243. ;;
  244. --betapass)
  245. shift && _betapass="$1"
  246. ;;
  247. --service-user)
  248. shift && _service_user="$1"
  249. ;;
  250. --service|-s)
  251. shift && _services+=("$1")
  252. ;;
  253. --createrepo)
  254. _build=true
  255. _createrepo=true
  256. ;;
  257. --createrepo-suse)
  258. _build=true
  259. _build_suse=true
  260. _createrepo=true
  261. ;;
  262. --createrepo-webroot)
  263. shift && _createrepo_webroot="$1"
  264. ;;
  265. --createrepo-user)
  266. shift && _createrepo_user="$1"
  267. ;;
  268. --vncpass)
  269. shift && _vncpass="$1"
  270. ;;
  271. --display)
  272. shift && _display="$1"
  273. ;;
  274. --container|-c)
  275. shift && _containers+=("$1")
  276. ;;
  277. --version|-v)
  278. echo "Version: $_scriptversion"
  279. exit 0
  280. ;;
  281. --debug|-d)
  282. echo "Debugging on"
  283. echo "installJRMC version: $_scriptversion"
  284. _debug="true"
  285. ;;
  286. --help|-h)
  287. printHelp && exit $?
  288. ;;
  289. --uninstall|-u)
  290. _uninstall=true
  291. ;;
  292. --tests)
  293. echo "Running tests, all other options are skipped"
  294. tests
  295. ;;
  296. --)
  297. shift
  298. break
  299. ;;
  300. esac
  301. shift
  302. done
  303. else
  304. err "Incorrect options provided"
  305. printHelp && exit 1
  306. fi
  307. }
  308. #######################################
  309. # Use several methods to determine the latest JRiver MC version
  310. #######################################
  311. getLatestVersion() {
  312. debug "Running: ${FUNCNAME[0]}"
  313. declare -g _mcversion
  314. # Latest defaults
  315. _base="buster" # For container method
  316. _boardurl="https://yabb.jriver.com/interact/index.php/board,71.0.html" # MC28 (Buster), for fallback webscrape
  317. #_base_next="bullseye" # TODO use for fallback to smooth upgrades
  318. # Legacy
  319. #_boardurl26="https://yabb.jriver.com/interact/index.php/board,64.0.html" # jessie/stretch
  320. # Peg older versions to prevent ABI and dependency mismatches in automatic mode
  321. # This can be overriden w/ --mcversion
  322. # TODO need user input here
  323. # disable version checks for createrepo or rpmbuild (servers)
  324. if [[ -v _build && ! -v _install ]]; then
  325. if [[ "$ID" == "ubuntu" ]]; then
  326. # [[ "$VERSION_CODENAME" =~ ^(focal|groovy|hirsute|impish)$ ]] && \
  327. # _base="bullseye"
  328. [[ "$VERSION_CODENAME" =~ ^(cosmic|disco|eoan)$ ]] && \
  329. _base="buster"
  330. [[ "$VERSION_CODENAME" =~ ^(xenial|yakkety|zesty|artful|bionic)$ ]] && \
  331. _mcversion="26.0.107"
  332. [[ "$VERSION_CODENAME" =~ ^(trusty|utopic|vivid|wily)$ ]] && \
  333. _mcversion="26.0.107"
  334. elif [[ "$ID" == "debian" ]]; then
  335. _base="$VERSION_CODENAME"
  336. [[ $VERSION_ID -eq 10 ]] && \
  337. _base="buster"
  338. [[ $VERSION_ID -le 9 ]] && \
  339. _mcversion="26.0.107" # For 9 and 8
  340. elif [[ "$ID" == "centos" ]]; then
  341. [[ "$VERSION_ID" -eq "8" ]] && \
  342. _base="buster"
  343. [[ "$VERSION_ID" -lt "8" ]] && \
  344. _mcversion="26.0.107" # Doubtful
  345. fi
  346. [[ -v _mcversion ]] && \
  347. _version_source="compatibility lookup" && \
  348. debug "To override, use --mcversion" && \
  349. return 0
  350. fi
  351. # Use a containerized package manager
  352. # TODO but how to determine build distro ($_base=buster)?
  353. [[ ! -x $(command -v buildah) ]] && installPackage --silent buildah
  354. if [[ -x $(command -v buildah) ]] && CNT=$(buildah from debian:$_base); then
  355. buildah run "$CNT" -- bash -c \
  356. "echo 'deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $_base main' > /etc/apt/sources.list 2>&1"
  357. buildah run "$CNT" -- bash -c \
  358. "apt-get update --allow-insecure-repositories -y > /dev/null 2>&1"
  359. if _mcversion=$(buildah run "$CNT" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1); then
  360. _version_source="containerized package manager"
  361. fi
  362. buildah rm "$CNT" > /dev/null 2>&1
  363. # Else scrape from Interact
  364. elif _mcversion=$(wget -qO- "$_boardurl" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
  365. _version_source="webscrape"
  366. fi
  367. if ! [[ -v _mcversion ]]; then
  368. err "MC version could not be determined. Please check the boardurl: $_boardurl or specify a version manually using --mcversion"
  369. exit 1
  370. fi
  371. }
  372. #######################################
  373. # Installs a package using the system package manager
  374. # Arguments:
  375. # One or more package names
  376. # Options:
  377. # --nocheck: Do not check if package is already installed
  378. # --nogpgcheck: Disable GPG checks for RPM based distros
  379. # --silent, -s: Do not report errors (useful if package is not strictly required and errors are noisy)
  380. #######################################
  381. installPackage() {
  382. debug "Running: ${FUNCNAME[0]}" "$@"
  383. local -a _pkg_array _install_flags
  384. local _pkg _nocheck _silent _return
  385. if _input=$(getopt -o +s -l nocheck,nogpgcheck,silent -- "$@"); then
  386. eval set -- "$_input"
  387. while true; do
  388. case "$1" in
  389. --nocheck)
  390. _nocheck=true
  391. ;;
  392. --nogpgcheck)
  393. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  394. _install_flags+=("--nogpgcheck")
  395. elif [[ "$ID" =~ ^opensuse.* ]]; then
  396. _install_flags+=("--allow-unsigned-rpm")
  397. fi
  398. ;;
  399. --silent|-s)
  400. _silent=true
  401. ;;
  402. --)
  403. shift
  404. break
  405. ;;
  406. esac
  407. shift
  408. done
  409. else
  410. err "Incorrect options provided"
  411. exit 1
  412. fi
  413. for _pkg in "$@"; do
  414. # Check for alias
  415. if [[ ! -v _nocheck && -v PKG_ALIASES[$_pkg] ]]; then
  416. _pkg=${PKG_ALIASES[$_pkg]}
  417. fi
  418. # Check if already installed
  419. if [[ -v _nocheck ]] || ! pkg_query "$_pkg" > /dev/null 2>&1; then
  420. _pkg_array+=("$_pkg")
  421. fi
  422. done
  423. # Install packages from package array
  424. if [[ ${#_pkg_array[@]} -ge 1 ]]; then
  425. debug "Installing: ${_pkg_array[*]}"
  426. if debug; then
  427. debug "pkg_install ${_install_flags[*]} ${_pkg_array[*]}"
  428. pkg_install "${_install_flags[@]}" "${_pkg_array[@]}"
  429. else
  430. pkg_install "${_install_flags[@]}" "${_pkg_array[@]}" > /dev/null 2>&1
  431. fi
  432. _return=$?
  433. [[ $_return -ne 0 && ! -v _silent ]] && err "Failed to install ${_pkg_array[*]}. Attempting to continue..."
  434. return $_return
  435. fi
  436. }
  437. #######################################
  438. # Add the JRiver repository files
  439. #######################################
  440. addRepo() {
  441. debug "Running: ${FUNCNAME[0]}"
  442. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  443. bash_cmd 'cat <<- EOF > /etc/yum.repos.d/jriver.repo
  444. [jriver]
  445. name=JRiver Media Center repo by BryanC
  446. baseurl=https://repos.bryanroessler.com/jriver
  447. gpgcheck=0
  448. EOF'
  449. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  450. # _mversion will depend on _base unless --mcversion is passed
  451. installPackage wget
  452. wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | ifSudo apt-key add - > /dev/null 2>&1
  453. ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$_mversion.list" -O "/etc/apt/sources.list.d/mediacenter$_mversion.list" > /dev/null 2>&1
  454. elif [[ "$ID" =~ ^opensuse.* ]]; then
  455. ifSudo zypper addrepo --no-gpgcheck "https://repos.bryanroessler.com/jriver" jriver > /dev/null 2>&1
  456. fi
  457. }
  458. #######################################
  459. # Installs JRiver Media Center from a repository
  460. #######################################
  461. installMCFromRepo() {
  462. debug "Running: ${FUNCNAME[0]}"
  463. local _mcpkg
  464. echo "Installing JRiver Media Center $_mcversion from repository."
  465. echo "Future updates will be handled by your package manager."
  466. if ! debug; then
  467. echo "This may take a few minutes to complete."
  468. echo "Use --debug for verbose output."
  469. fi
  470. addRepo
  471. # Update package list
  472. debug "Updating package list"
  473. if ! pkg_update > /dev/null 2>&1; then
  474. err "Package update failed!"
  475. exit 1
  476. fi
  477. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  478. _mcpkg="MediaCenter"
  479. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  480. _mcpkg="mediacenter$_mversion"
  481. fi
  482. if [[ -v _specific_version ]]; then
  483. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  484. _mcpkg="$_mcpkg-$_mcversion"
  485. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  486. _mcpkg="$_mcpkg=$_mcversion"
  487. fi
  488. fi
  489. if debug; then
  490. debug "installPackage --nocheck $_mcpkg"
  491. installPackage --nocheck --nogpgcheck "$_mcpkg"
  492. else
  493. installPackage --nocheck --nogpgcheck "$_mcpkg" > /dev/null 2>&1
  494. fi
  495. return $?
  496. }
  497. #######################################
  498. # Acquire the source DEB package from JRiver's servers
  499. #######################################
  500. acquireDeb() {
  501. debug "Running: ${FUNCNAME[0]}"
  502. declare -g DEBFILENAME
  503. DEBFILENAME="$_outputdir/SOURCES/MediaCenter-$_mcversion-amd64.deb"
  504. # If necessary, create SOURCES dir
  505. [[ ! -d "$_outputdir/SOURCES" ]] && mkdir -p "$_outputdir/SOURCES"
  506. # If deb file already exists, skip download
  507. if [[ -f "$DEBFILENAME" ]]; then
  508. echo "Using local DEB file: $DEBFILENAME"
  509. elif [[ -v _betapass ]]; then
  510. echo "Checking beta repo..."
  511. if wget -q -O "$DEBFILENAME" \
  512. "https://files.jriver.com/mediacenter/channels/v$_mversion/beta/$_betapass/MediaCenter-$_mcversion-amd64.deb"; then
  513. echo "Found!"
  514. fi
  515. elif echo "Checking test repo..." && wget -q -O "$DEBFILENAME" \
  516. "https://files.jriver.com/mediacenter/test/MediaCenter-$_mcversion-amd64.deb"; then
  517. echo "Found!"
  518. # Else check latest repo
  519. elif echo "Checking latest repo..." && wget -q -O "$DEBFILENAME" \
  520. "https://files.jriver.com/mediacenter/channels/v$_mversion/latest/MediaCenter-$_mcversion-amd64.deb"; then
  521. echo "Found!"
  522. else
  523. err "Cannot find DEB file."
  524. exit 1
  525. fi
  526. if [[ ! -f "$DEBFILENAME" ]]; then
  527. err "Downloaded DEB file missing or corrupted."
  528. exit 1
  529. fi
  530. }
  531. #######################################
  532. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  533. #######################################
  534. buildRPM() {
  535. debug "Running: ${FUNCNAME[0]}"
  536. local _build_requires _global_requires _custom_requires _ec
  537. declare -g _mcrpm="$_outputdir/RPMS/x86_64/MediaCenter-$_mcversion.x86_64.rpm"
  538. # skip rebuilding the rpm if it already exists
  539. if [[ -f "$_mcrpm" ]]; then
  540. echo "$_mcrpm already exists. Skipping build step."
  541. return 0
  542. fi
  543. # install build dependencies
  544. installPackage "wget" "dpkg" "rpm-build"
  545. [[ ! -d "$_outputdir/SPECS" ]] && mkdir -p "$_outputdir/SPECS"
  546. # rpmbuild uses rpm to check for build dependencies
  547. # this will fail on non-rpm distros
  548. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  549. _build_requires=$'BuildRequires: rpm >= 4.11.0\nBuildRequires: dpkg'
  550. fi
  551. read -r -d '' _global_requires <<- 'EOF'
  552. Requires: glibc >= 2.28
  553. Requires: alsa-lib >= 1.1.8
  554. Requires: gtk3 >= 3.24
  555. Requires: pango >= 1.42
  556. Requires: python3
  557. Requires: xdg-utils
  558. Requires: fribidi >= 1.0.5
  559. Requires: fontconfig >= 2.13
  560. Requires: lcms2 >= 2.9
  561. Requires: vulkan-headers >= 1.1
  562. Requires: ca-certificates
  563. Requires: libXScrnSaver
  564. EOF
  565. # SUSE dependency name variations
  566. if [[ "$ID" =~ ^opensuse.*$ || -v _build_suse ]]; then
  567. read -r -d '' _custom_requires <<- 'EOF'
  568. Requires: Mesa-libVulkan-devel
  569. Requires: freetype >= 1.3.1
  570. Requires: libharfbuzz0 >= 2.3.1
  571. Requires: libX11-6 >= 1.6
  572. Requires: libX11-data >= 1.6
  573. Requires: libXdmcp6 >= 1.1
  574. Requires: libXext6 >= 1.3
  575. Requires: libepoxy0 >= 1.5.3
  576. Requires: libgomp1 >= 7.4
  577. Requires: libstdc++6 >= 7.4
  578. Requires: libuuid1 >= 2.33
  579. Requires: libva2 >= 2.4.0
  580. Requires: libxcb1 >= 1.1
  581. Requires: libgbm1 >= 18.3.6
  582. Requires: mozilla-nspr >= 4.20
  583. Requires: mozilla-nss >= 3.42
  584. EOF
  585. else
  586. read -r -d '' _custom_requires <<- 'EOF'
  587. Requires: mesa-vulkan-drivers
  588. Requires: freetype >= 2.9.1
  589. Requires: harfbuzz >= 2.3.1
  590. Requires: libX11 >= 1.6
  591. Requires: libX11-common >= 1.6
  592. Requires: libXdmcp >= 1.1
  593. Requires: libXext >= 1.3
  594. Requires: libepoxy >= 1.5.3
  595. Requires: libgomp >= 7.4
  596. Requires: libstdc++ >= 7.4
  597. Requires: libuuid >= 2.33
  598. Requires: libva >= 2.4.0
  599. Requires: libxcb >= 1.1
  600. Requires: mesa-libgbm >= 18.3.6
  601. Requires: nspr >= 4.20
  602. Requires: nss >= 3.42
  603. EOF
  604. fi
  605. #debug "Requires: $_requires"
  606. # Create spec file
  607. cat <<- EOF > "$_outputdir/SPECS/mediacenter.spec"
  608. Name: MediaCenter
  609. Version: $_mcversion
  610. Release: 1
  611. Summary: JRiver Media Center
  612. Group: Applications/Media
  613. Source0: http://files.jriver.com/mediacenter/channels/v$_mversion/latest/MediaCenter-$_mcversion-amd64.deb
  614. ${_build_requires:-}
  615. BuildArch: x86_64
  616. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
  617. AutoReq: 0
  618. ${_global_requires:-}
  619. ${_custom_requires:-}
  620. Recommends: vorbis-tools >= 1.4.0
  621. Recommends: lame >= 3.0
  622. Provides: mediacenter$_mversion
  623. License: Copyright 1998-2022, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  624. URL: http://www.jriver.com/
  625. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  626. %description
  627. Media Center is more than a world class player.
  628. %global __os_install_post %{nil}
  629. %prep
  630. %build
  631. %install
  632. dpkg -x %{S:0} %{buildroot}
  633. %post -p /sbin/ldconfig
  634. %postun -p /sbin/ldconfig
  635. %files
  636. %{_bindir}/mediacenter$_mversion
  637. %{_libdir}/jriver
  638. %{_datadir}
  639. %exclude %{_datadir}/applications/media_center_packageinstaller_$_mversion.desktop
  640. /etc/security/limits.d/*
  641. EOF
  642. # Run rpmbuild
  643. echo "Building version $_mcversion, please wait..."
  644. if debug; then
  645. rpmbuild --define="%_topdir $_outputdir" --define="%_libdir /usr/lib" -bb "$_outputdir/SPECS/mediacenter.spec"
  646. else
  647. rpmbuild --quiet --define="%_topdir $_outputdir" --define="%_libdir /usr/lib" -bb "$_outputdir/SPECS/mediacenter.spec" > /dev/null 2>&1
  648. fi
  649. _ec=$?
  650. [[ "$_ec" == 0 ]] && echo "Build successful. The RPM file is located at: $_mcrpm"
  651. return $_ec
  652. }
  653. #######################################
  654. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  655. #######################################
  656. runCreaterepo() {
  657. debug "Running: ${FUNCNAME[0]}"
  658. declare -a createrepo_cmd
  659. installPackage createrepo_c
  660. # If the webroot does not exist, create it
  661. if [[ ! -d "$_createrepo_webroot" ]]; then
  662. debug "ifSudo -u $_createrepo_user mkdir -p $_createrepo_webroot"
  663. if ! ifSudo -u "$_createrepo_user" mkdir -p "$_createrepo_webroot" > /dev/null 2>&1; then
  664. debug "ifSudo mkdir -p $_createrepo_webroot"
  665. if ifSudo mkdir -p "$_createrepo_webroot" && \
  666. ifSudo chown -R "$_createrepo_user":"$_createrepo_user" "$_createrepo_webroot"; then
  667. :
  668. else
  669. err "Could not create the createrepo-webroot path!"
  670. err "Make sure that the createrepo-webroot is writeable by createrepo-user: $_createrepo_user"
  671. return 1
  672. fi
  673. fi
  674. fi
  675. # Copy built rpms to webroot
  676. debug "ifSudo -u $_createrepo_user cp -n -f $_mcrpm $_createrepo_webroot"
  677. if ! ifSudo -u "$_createrepo_user" cp -n -f "$_mcrpm" "$_createrepo_webroot" > /dev/null 2>&1; then
  678. debug "cp_cmd $_mcrpm $_createrepo_webroot"
  679. if cp_cmd "$_mcrpm" "$_createrepo_webroot" && \
  680. ifSudo chown -R "$_createrepo_user":"$_createrepo_user" "$_createrepo_webroot"; then
  681. :
  682. else
  683. err "Could not copy $_mcrpm to $_createrepo_webroot"
  684. err "Make sure that the createrepo-webroot path is writeable by createrepo-user: $_createrepo_user"
  685. return 1
  686. fi
  687. fi
  688. # Run createrepo
  689. createrepo_cmd=("sudo" "-u" "$_createrepo_user" "createrepo" "-q")
  690. [[ -d "$_createrepo_webroot/repodata" ]] && createrepo_cmd+=("--update")
  691. debug "${createrepo_cmd[*]} $_createrepo_webroot"
  692. if "${createrepo_cmd[@]}" "$_createrepo_webroot"; then
  693. echo "Successfully updated repo"
  694. return 0
  695. else
  696. err "Update repo failed"
  697. return 1
  698. fi
  699. }
  700. #######################################
  701. # Symlink certificates where JRiver Media Center expects them to be on Fedora/CentOS
  702. #######################################
  703. symlinkCerts() {
  704. debug "Running: ${FUNCNAME[0]}"
  705. if [[ ! -f /etc/ssl/certs/ca-certificates.crt && \
  706. -f /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ]]; then
  707. if ! ln_cmd /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/ssl/certs/ca-certificates.crt; then
  708. err "Symlinking certificates failed"
  709. return 1
  710. fi
  711. fi
  712. }
  713. #######################################
  714. # Automatically restore the mjr license file if it is found next to
  715. # installJRMC or _restorefile is set
  716. #######################################
  717. restoreLicense() {
  718. debug "Running: ${FUNCNAME[0]}"
  719. local _mjr
  720. # Allow user to put the mjr file next to installJRMC
  721. if [[ ! -v _restorefile ]]; then
  722. for _mjr in "$PWD"/*.mjr; do
  723. [[ $_mjr -nt $_restorefile ]] && _restorefile="$_mjr"
  724. done
  725. fi
  726. # Restore license
  727. if [[ -f "$_restorefile" ]]; then
  728. if ! "mediacenter$_mversion" /RestoreFromFile "$_restorefile"; then
  729. err "Automatic license restore failed"
  730. return 1
  731. fi
  732. fi
  733. }
  734. #######################################
  735. # Opens ports using the system firewall tool
  736. # Arguments
  737. # Pre-defined service to enable
  738. #######################################
  739. openFirewall() {
  740. debug "Running: ${FUNCNAME[0]}" "$@"
  741. # Create OS-specific port rules based on argument (service) name
  742. local -a _f_ports # for firewall-cmd
  743. local _u_ports # for ufw
  744. if [[ "$1" == "jriver" ]]; then
  745. _f_ports=("52100-52200/tcp" "1900/udp")
  746. _u_ports="52100:52200/tcp|1900/udp"
  747. elif [[ "$1" =~ ^(jriver-x11vnc|jriver-xvnc)$ ]]; then
  748. _f_ports=("$_port/tcp" "1900/udp")
  749. _u_ports="$_port/tcp|1900/udp"
  750. fi
  751. # Open the ports
  752. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  753. [[ ! -x $(command -v firewall-cmd) ]] && installPackage firewalld
  754. if ! firewall_cmd --get-services | grep -q "$1"; then
  755. firewall_cmd --permanent --new-service="$1" > /dev/null 2>&1
  756. firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" > /dev/null 2>&1
  757. firewall_cmd --permanent --service="$1" --set-short="$1" > /dev/null 2>&1
  758. for _f_port in "${_f_ports[@]}"; do
  759. firewall_cmd --permanent --service="$1" --add-port="$_f_port" > /dev/null 2>&1
  760. done
  761. firewall_cmd --add-service "$1" --permanent > /dev/null 2>&1
  762. firewall_cmd --reload > /dev/null 2>&1
  763. fi
  764. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  765. # Debian ufw package state is broken on fresh installations
  766. [[ ! -x $(command -v ufw) ]] && installPackage ufw
  767. if [[ ! -f "/etc/ufw/applications.d/$1" ]]; then
  768. bash_cmd "cat <<- EOF > /etc/ufw/applications.d/$1
  769. [$1]
  770. title=$1
  771. description=$1 installed by installJRMC
  772. ports=$_u_ports
  773. EOF"
  774. fi
  775. firewall_cmd app update "$1"
  776. firewall_cmd allow "$1" > /dev/null 2>&1
  777. fi
  778. # shellcheck disable=SC2181 # More concise
  779. if [[ $? -ne 0 ]]; then
  780. err "Firewall ports could not be opened"
  781. return 1
  782. fi
  783. }
  784. #######################################
  785. # Create the x11vnc password file
  786. #######################################
  787. setX11VNCPass() {
  788. debug "Running: ${FUNCNAME[0]}"
  789. _vncpassfile="$HOME/.vnc/jrmc_passwd"
  790. [[ ! -d "${_vncpassfile%/*}" ]] && mkdir -p "${_vncpassfile%/*}"
  791. if [[ -f "$_vncpassfile" ]]; then
  792. if [[ ! -v _vncpass ]]; then
  793. err "Refusing to overwrite existing $_vncpassfile with an empty password"
  794. err "Remove existing $_vncpassfile or set --vncpass to use an empty password"
  795. exit 1
  796. else
  797. rm -f "$_vncpassfile"
  798. fi
  799. fi
  800. if [[ -v _vncpass ]]; then
  801. if ! x11vnc -storepasswd "$_vncpass" "$_vncpassfile"; then
  802. err "Could not create VNC password file"
  803. return 1
  804. fi
  805. else
  806. _novncauth="true"
  807. fi
  808. }
  809. #######################################
  810. # Create the Xvnc password file
  811. #######################################
  812. setVNCPass() {
  813. debug "Running: ${FUNCNAME[0]}"
  814. _vncpassfile="$HOME/.vnc/jrmc_passwd"
  815. [[ ! -d "${_vncpassfile%/*}" ]] && mkdir -p "${_vncpassfile%/*}"
  816. if [[ -f "$_vncpassfile" ]]; then
  817. if [[ ! -v _vncpass ]]; then
  818. err "Refusing to overwrite existing $_vncpassfile with an empty password"
  819. err "Remove existing $_vncpassfile or set --vncpass to use an empty password"
  820. exit 1
  821. else
  822. rm -f "$_vncpassfile"
  823. fi
  824. fi
  825. if [[ -v _vncpass ]]; then
  826. if ! echo "$_vncpass" | vncpasswd -f > "$_vncpassfile"; then
  827. err "Could not create VNC password file"
  828. return 1
  829. fi
  830. else
  831. _novncauth="true"
  832. fi
  833. }
  834. #######################################
  835. # Set display and port variables
  836. #######################################
  837. setDisplay() {
  838. debug "Running: ${FUNCNAME[0]}"
  839. # Check _display, else DISPLAY, else set to :0 by default
  840. if [[ -v _display ]]; then
  841. _next_display="$_display"
  842. elif [[ -v DISPLAY ]]; then
  843. _display="${DISPLAY}"
  844. _displaynum="${_display#:}" # strip colon
  845. _displaynum="${_displaynum%.*}" # strip suffix
  846. _next_displaynum=$(( _displaynum + 1 ))
  847. _next_display=":$_next_displaynum"
  848. else
  849. _display=":0"
  850. _next_display=":1"
  851. fi
  852. _displaynum="${_display#:}" # strip colon
  853. _displaynum="${_displaynum%.*}" # strip suffix
  854. _next_displaynum=$(( _displaynum + 1 ))
  855. }
  856. #######################################
  857. # Create associated service variables based on service name
  858. #######################################
  859. setServiceVars() {
  860. debug "Running: ${FUNCNAME[0]}"
  861. if [[ "$_service_user" == "root" ]]; then
  862. _service_fname="$_systemddir/${1}.service"
  863. _timer_fname="$_systemddir/${1}.timer"
  864. _service_name="${1}.service"
  865. _timer_name="${1}.timer"
  866. _user_specifier=""
  867. else
  868. _service_fname="$_systemddir/${1}@.service"
  869. _timer_fname="$_systemddir/${1}@.timer"
  870. _service_name="${1}@$_service_user.service"
  871. _timer_name="${1}@$_service_user.timer"
  872. _user_specifier="User=%I"
  873. fi
  874. }
  875. #######################################
  876. # Starts and enables (at startup) a JRiver Media Center service
  877. # Arguments:
  878. # Passes arguments as startup options to /usr/bin/mediacenter??
  879. #######################################
  880. service_jriver-mediacenter() {
  881. debug "Running: ${FUNCNAME[0]}"
  882. bash_cmd "cat <<- EOF > $_service_fname
  883. [Unit]
  884. Description=JRiver Media Center $_mversion
  885. After=graphical.target
  886. [Service]
  887. $_user_specifier
  888. Type=simple
  889. Environment=DISPLAY=$_display
  890. Environment=XAUTHORITY=$XAUTHORITY
  891. ExecStart=/usr/bin/mediacenter$_mversion $*
  892. Restart=always
  893. RestartSec=10
  894. KillSignal=SIGHUP
  895. TimeoutStopSec=30
  896. [Install]
  897. WantedBy=graphical.target
  898. EOF"
  899. systemctl_reload && \
  900. systemctl_enable "$_service_name" && \
  901. openFirewall "jriver"
  902. }
  903. #######################################
  904. # Starts and enables (at startup) a JRiver Media Server service
  905. #######################################
  906. service_jriver-mediaserver() {
  907. debug "Running: ${FUNCNAME[0]}"
  908. service_jriver-mediacenter "/MediaServer"
  909. }
  910. #######################################
  911. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  912. #######################################
  913. service_jriver-xvnc() {
  914. debug "Running: ${FUNCNAME[0]}"
  915. installPackage tigervnc-server
  916. setVNCPass
  917. local _port=$(( _next_displaynum + 5900 ))
  918. if [[ -v _novncauth ]]; then
  919. _exec_start_cmd="/usr/bin/vncserver $_next_display -geometry 1440x900 -alwaysshared -name jriver$_next_display -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$_mversion"
  920. else
  921. _exec_start_cmd="/usr/bin/vncserver $_next_display -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$_mversion"
  922. fi
  923. bash_cmd "cat <<- EOF > $_service_fname
  924. [Unit]
  925. Description=Remote desktop service (VNC)
  926. After=syslog.target network.target
  927. [Service]
  928. Type=simple
  929. $_user_specifier
  930. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $_next_display > /dev/null 2>&1 || :'
  931. ExecStart=$_exec_start_cmd
  932. ExecStop=/usr/bin/vncserver -kill $_next_display
  933. Restart=always
  934. [Install]
  935. WantedBy=multi-user.target
  936. EOF"
  937. systemctl_reload && \
  938. systemctl_enable "$_service_name" && \
  939. echo "Xvnc running on localhost:$_port" && \
  940. openFirewall "jriver-xvnc" && \
  941. openFirewall "jriver"
  942. }
  943. #######################################
  944. # Starts and enables (at startup) JRiver Media Server and x11vnc sharing the local desktop
  945. #######################################
  946. service_jriver-x11vnc() {
  947. debug "Running: ${FUNCNAME[0]}"
  948. installPackage x11vnc
  949. setX11VNCPass
  950. local _port=$(( _displaynum + 5900 ))
  951. # Get current desktop resolution
  952. # TODO: may need to break this out into its own function and get smarter at identifying multi-monitors
  953. _getResolution() {
  954. debug "Running: ${FUNCNAME[0]}"
  955. installPackage xorg-x11-utils
  956. _res=$(xdpyinfo | grep dimensions | awk '{print $2}')
  957. }
  958. _getResolution
  959. if [[ -v _novncauth ]]; then
  960. _exec_start_cmd="/usr/bin/x11vnc -display $_display -noscr -geometry $_res -auth guess -forever -bg -nopw"
  961. else
  962. _exec_start_cmd="/usr/bin/x11vnc -display $_display -noscr -geometry $_res -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd"
  963. fi
  964. bash_cmd "cat <<-EOF > $_service_fname
  965. [Unit]
  966. Description=x11vnc
  967. After=multi.service
  968. [Service]
  969. $_user_specifier
  970. Type=forking
  971. Environment=DISPLAY=$_display
  972. ExecStart=$_exec_start_cmd
  973. Restart=always
  974. RestartSec=10
  975. [Install]
  976. WantedBy=multi-user.target
  977. EOF"
  978. systemctl_reload && \
  979. systemctl_enable "$_service_name" && \
  980. echo "x11vnc running on localhost:$_port" && \
  981. openFirewall "jriver-x11vnc"
  982. }
  983. #######################################
  984. # Starts and enables (at startup) an hourly service to build the latest version of JRiver Media
  985. # Center RPM from the source DEB and create/update an RPM repository
  986. #######################################
  987. service_jriver-createrepo() {
  988. debug "Running: ${FUNCNAME[0]}"
  989. bash_cmd "cat <<-EOF > $_service_fname
  990. [Unit]
  991. Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo
  992. [Service]
  993. $_user_specifier
  994. ExecStart=$PWD/installJRMC --outputdir $_outputdir --createrepo --createrepo-webroot $_createrepo_webroot --createrepo-user $_createrepo_user
  995. [Install]
  996. WantedBy=default.target
  997. EOF"
  998. bash_cmd "cat <<-EOF > $_timer_fname
  999. [Unit]
  1000. Description=Run JRiver MC rpmbuild hourly
  1001. [Timer]
  1002. OnCalendar=hourly
  1003. Persistent=true
  1004. [Install]
  1005. WantedBy=timers.target
  1006. EOF"
  1007. systemctl_reload && \
  1008. systemctl_enable "$_timer_name"
  1009. }
  1010. #######################################
  1011. # CONTAINERS
  1012. #######################################
  1013. # containerCreaterepo() {
  1014. # :
  1015. # }
  1016. # containerVNC() {
  1017. # :
  1018. # }
  1019. # containerMC() {
  1020. # installPackage buildah podman
  1021. # cnt=$(buildah from docker.io/jlesage/baseimage-gui:debian-10)
  1022. # podman_create_cmd=("podman" "create" "--name" "$CNAME")
  1023. # buildah_config_cmd=("buildah" "config" \
  1024. # "--author" "bryanroessler@gmail.com" \
  1025. # "--label" "maintainer=$MAINTAINER" \
  1026. # "--env" "TZ=$TZ" \
  1027. # "--workingdir" "/app" \
  1028. # "--cmd" "mediacenter$_mversion")
  1029. # mkcdirs() {
  1030. # local dir
  1031. # for dir in "$@"; do
  1032. # if [[ ! -d "$dir" ]]; then
  1033. # if ! mkdir -p "$dir"; then
  1034. # err "Could not create directory $dir, check your permissions"
  1035. # fi
  1036. # fi
  1037. # if ! chcon -t container_file_t -R "$dir"; then
  1038. # err "Could not set container_file_t attribute for $dir, check your permissions"
  1039. # fi
  1040. # done
  1041. # }
  1042. # mkcdirs "$HOME/.jriver"
  1043. # podman_create_cmd+=("-v" "$HOME/.jriver:/root/.jriver")
  1044. # podman_create_cmd+=("-v" "$DOWNLOAD_ROOT:/downloads:z")
  1045. # podman_create_cmd+=("-v" "$MONITOR_ROOT/nzbs:/nzbs")
  1046. # podman_create_cmd+=("-p" "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1047. # brc() { buildah run "$1" "${@:2}" || return 1; }
  1048. # brc add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1
  1049. # brc add-pkg --virtual .build-deps wget
  1050. # brc sh -s <<- EOF
  1051. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - > /dev/null 2>&1
  1052. # EOF
  1053. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$_mversion.list" -O "/etc/apt/sources.list.d/mediacenter$_mversion.list"
  1054. # brc apt-get update -y -q0
  1055. # brc add-pkg "mediacenter$_mversion"
  1056. # brc del-pkg .build-deps
  1057. # }
  1058. uninstall() {
  1059. debug "Running: ${FUNCNAME[0]}"
  1060. if ! askOk "Do you really want to uninstall JRiver Media Center"; then
  1061. echo "Cancelling uninstall..."
  1062. exit 0
  1063. fi
  1064. debug "Stopping and removing all associated Media Center services"
  1065. for _service in $(compgen -A "function" "service"); do
  1066. _service="${_service##service_}"
  1067. setServiceVars "$_service"
  1068. for unit in "$_service_name" "$_timer_name"; do
  1069. if systemctl is-active -q "$unit" > /dev/null 2>&1 || systemctl is-enabled -q "$unit" > /dev/null 2>&1; then
  1070. debug "Disabling $unit"
  1071. systemctl_disable "$unit"
  1072. fi
  1073. done
  1074. for f in "$_service_fname" "$_timer_fname"; do
  1075. debug "Removing $f"
  1076. rm_cmd "$f"
  1077. done
  1078. systemctl_reload
  1079. done
  1080. debug "Removing repo files"
  1081. [[ -f "/etc/yum.repos.d/jriver.repo" ]] \
  1082. && rm_cmd "/etc/yum.repos.d/jriver.repo"
  1083. [[ -f "/etc/apt/sources.list.d/jriver.list" ]] \
  1084. && rm_cmd "/etc/apt/sources.list.d/jriver.list"
  1085. if [[ "$ID" =~ ^opensuse.* ]]; then
  1086. ifSudo zypper rr jriver > /dev/null 2>&1
  1087. fi
  1088. debug "Removing firewall rules"
  1089. if [[ -x $(command -v firewall-cmd) ]]; then
  1090. if [[ -v debug ]]; then
  1091. debug "firewall_cmd --permanent --remove-service=jriver"
  1092. firewall_cmd --permanent --remove-service=jriver
  1093. debug "firewall_cmd --permanent --delete-service=jriver"
  1094. firewall_cmd --permanent --delete-service=jriver
  1095. debug "firewall_cmd --reload"
  1096. firewall_cmd --reload
  1097. else
  1098. firewall_cmd --permanent --remove-service=jriver > /dev/null 2>&1
  1099. firewall_cmd --permanent --delete-service=jriver > /dev/null 2>&1
  1100. firewall_cmd --reload > /dev/null 2>&1
  1101. fi
  1102. elif [[ -x $(command -v ufw) ]]; then
  1103. if [[ -v debug ]]; then
  1104. firewall_cmd delete allow jriver
  1105. else
  1106. firewall_cmd delete allow jriver > /dev/null 2>&1
  1107. fi
  1108. [[ -f "/etc/ufw/applications.d/jriver" ]] \
  1109. && rm_cmd /etc/ufw/applications.d/jriver
  1110. fi
  1111. debug "Uninstalling Media Center packages"
  1112. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  1113. _mcpkg="MediaCenter"
  1114. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  1115. _mcpkg="mediacenter$_mversion"
  1116. fi
  1117. if debug; then
  1118. debug "pkg_remove -q $_mcpkg"
  1119. pkg_remove "-q" "$_mcpkg"
  1120. else
  1121. pkg_remove "-q" "$_mcpkg" > /dev/null 2>&1
  1122. fi
  1123. echo "JRiver Media Center has been completely uninstalled."
  1124. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1125. echo "To remove your rpmbuild output files, run: rm -rf $_outputdir"
  1126. exit 0
  1127. }
  1128. tests() {
  1129. # To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1130. exit $?
  1131. }
  1132. main() {
  1133. debug "Running: ${FUNCNAME[0]}"
  1134. init "$@"
  1135. # Uninstall and exit
  1136. if [[ -v _uninstall ]]; then
  1137. uninstall
  1138. exit $?
  1139. fi
  1140. # Install MC using package manager
  1141. if [[ -v _install && "$_install" == "repo" ]]; then
  1142. if [[ "$ID" =~ ^opensuse.*$ ]]; then
  1143. echo "A SUSE repository is not yet available."
  1144. echo "Use --install rpm to build and install a SUSE RPM instead."
  1145. exit 1
  1146. fi
  1147. if installMCFromRepo; then
  1148. echo "JRiver Media Center installed successfully"
  1149. else
  1150. err "JRiver Media Center installation failed"
  1151. exit 1
  1152. fi
  1153. symlinkCerts
  1154. restoreLicense
  1155. openFirewall "jriver"
  1156. fi
  1157. # Build RPM from source deb package
  1158. if [[ -v _build ]]; then
  1159. acquireDeb
  1160. if ! buildRPM; then
  1161. err "Build failed."
  1162. # For automation, let's remove the source DEB and reaquire it on next run in case it is corrupted or buggy
  1163. [[ -f "$DEBFILENAME" ]] && echo "Removing source DEB" && rm -f "$DEBFILENAME"
  1164. exit 1
  1165. fi
  1166. fi
  1167. # Run createrepo
  1168. if [[ -v _createrepo ]]; then
  1169. runCreaterepo
  1170. exit $?
  1171. fi
  1172. # Install RPM
  1173. if [[ -v _install && "$_install" == "rpm" ]]; then
  1174. if installPackage --nocheck --nogpgcheck "$_mcrpm"; then
  1175. echo "JRiver Media Center installed successfully"
  1176. else
  1177. err "JRiver Media Center installation failed"
  1178. exit 1
  1179. fi
  1180. symlinkCerts
  1181. restoreLicense
  1182. openFirewall "jriver"
  1183. fi
  1184. # Install services
  1185. if [[ "${#_services[@]}" -gt 0 ]]; then
  1186. setDisplay
  1187. ! [[ -d "$_systemddir" ]] && ifSudo mkdir -p "$_systemddir"
  1188. for _service in "${_services[@]}"; do
  1189. setServiceVars "$_service"
  1190. if ! "service_$_service"; then
  1191. if [[ $? -eq 127 ]]; then
  1192. err "Service $_service does not exist, check your service name"
  1193. else
  1194. err "Failed to create service: $_service"
  1195. fi
  1196. fi
  1197. done
  1198. fi
  1199. # Install containers
  1200. # for _container in "${_containers[@]}"; do
  1201. # if ! "_container_$_container"; then
  1202. # if [[ $? -eq 127 ]]; then
  1203. # err "Container $_container does not exist, check your container name"
  1204. # else
  1205. # err "Failed to create container: $_container"
  1206. # fi
  1207. # fi
  1208. # done
  1209. }
  1210. main "$@"