installJRMC 44 KB

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