installJRMC 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  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'
  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'
  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: libuuid >= 2.33
  562. Requires: libXext >= 1.3
  563. Requires: libxcb >= 1.1
  564. Requires: libstdc++ >= 7.4
  565. Requires: gtk3 >= 3.24
  566. Requires: pango >= 1.42
  567. Requires: nss >= 3.42
  568. Requires: nspr >= 4.20
  569. Requires: python3
  570. Requires: xdg-utils
  571. Requires: libgomp >= 7.4
  572. Requires: fribidi >= 1.0.5
  573. Requires: fontconfig >= 2.13
  574. Requires: mesa-libgbm >= 18.3.6
  575. Requires: libva >= 2.4.0
  576. Requires: libepoxy >= 1.5.3
  577. Requires: lcms2 >= 2.9
  578. Requires: vulkan-headers >= 1.1
  579. Requires: ca-certificates
  580. Requires: libXScrnSaver
  581. ${_requires:-}
  582. Recommends: vorbis-tools >= 1.4.0
  583. Recommends: lame >= 3.0
  584. Provides: mediacenter$_mversion
  585. License: Copyright 1998-2021, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  586. URL: http://www.jriver.com/
  587. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  588. %description
  589. Media Center is more than a world class player.
  590. %global __os_install_post %{nil}
  591. %prep
  592. %build
  593. %install
  594. dpkg -x %{S:0} %{buildroot}
  595. %post -p /sbin/ldconfig
  596. %postun -p /sbin/ldconfig
  597. %files
  598. %{_bindir}/mediacenter$_mversion
  599. %{_libdir}/jriver
  600. %{_datadir}
  601. %exclude %{_datadir}/applications/media_center_packageinstaller_$_mversion.desktop
  602. /etc/security/limits.d/*
  603. EOF
  604. # Run rpmbuild
  605. echo "Building version $_mcversion, please wait..."
  606. if debug; then
  607. rpmbuild --define="%_topdir $_outputdir" --define="%_libdir /usr/lib" -bb "$_outputdir/SPECS/mediacenter.spec"
  608. else
  609. rpmbuild --quiet --define="%_topdir $_outputdir" --define="%_libdir /usr/lib" -bb "$_outputdir/SPECS/mediacenter.spec" > /dev/null 2>&1
  610. fi
  611. _ec=$?
  612. [[ "$_ec" == 0 ]] && echo "Build successful. The RPM file is located at: $_mcrpm"
  613. return $_ec
  614. }
  615. #######################################
  616. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  617. #######################################
  618. runCreaterepo() {
  619. debug "Running: ${FUNCNAME[0]}"
  620. declare -a createrepo_cmd
  621. installPackage createrepo_c
  622. # If the webroot does not exist, create it
  623. if [[ ! -d "$_createrepo_webroot" ]]; then
  624. debug "ifSudo -u $_createrepo_user mkdir -p $_createrepo_webroot"
  625. if ! ifSudo -u "$_createrepo_user" mkdir -p "$_createrepo_webroot" > /dev/null 2>&1; then
  626. debug "ifSudo mkdir -p $_createrepo_webroot"
  627. if ifSudo mkdir -p "$_createrepo_webroot" && \
  628. ifSudo chown -R "$_createrepo_user":"$_createrepo_user" "$_createrepo_webroot"; then
  629. :
  630. else
  631. err "Could not create the createrepo-webroot path!"
  632. err "Make sure that the createrepo-webroot is writeable by createrepo-user: $_createrepo_user"
  633. return 1
  634. fi
  635. fi
  636. fi
  637. # Copy built rpms to webroot
  638. debug "ifSudo -u $_createrepo_user cp -n -f $_mcrpm $_createrepo_webroot"
  639. if ! ifSudo -u "$_createrepo_user" cp -n -f "$_mcrpm" "$_createrepo_webroot" > /dev/null 2>&1; then
  640. debug "cp_cmd $_mcrpm $_createrepo_webroot"
  641. if cp_cmd "$_mcrpm" "$_createrepo_webroot" && \
  642. ifSudo chown -R "$_createrepo_user":"$_createrepo_user" "$_createrepo_webroot"; then
  643. :
  644. else
  645. err "Could not copy $_mcrpm to $_createrepo_webroot"
  646. err "Make sure that the createrepo-webroot path is writeable by createrepo-user: $_createrepo_user"
  647. return 1
  648. fi
  649. fi
  650. # Run createrepo
  651. createrepo_cmd=("sudo" "-u" "$_createrepo_user" "createrepo" "-q")
  652. [[ -d "$_createrepo_webroot/repodata" ]] && createrepo_cmd+=("--update")
  653. debug "${createrepo_cmd[*]} $_createrepo_webroot"
  654. if "${createrepo_cmd[@]}" "$_createrepo_webroot"; then
  655. echo "Successfully updated repo"
  656. return 0
  657. else
  658. err "Update repo failed"
  659. return 1
  660. fi
  661. }
  662. #######################################
  663. # Symlink certificates where JRiver Media Center expects them to be on Fedora/CentOS
  664. #######################################
  665. symlinkCerts() {
  666. debug "Running: ${FUNCNAME[0]}"
  667. if [[ ! -f /etc/ssl/certs/ca-certificates.crt && \
  668. -f /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ]]; then
  669. if ! ln_cmd /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/ssl/certs/ca-certificates.crt; then
  670. err "Symlinking certificates failed"
  671. return 1
  672. fi
  673. fi
  674. }
  675. #######################################
  676. # Automatically restore the mjr license file if it is found next to
  677. # installJRMC or _restorefile is set
  678. #######################################
  679. restoreLicense() {
  680. debug "Running: ${FUNCNAME[0]}"
  681. local _mjr
  682. # Allow user to put the mjr file next to installJRMC
  683. if [[ ! -v _restorefile ]]; then
  684. for _mjr in "$PWD"/*.mjr; do
  685. [[ $_mjr -nt $_restorefile ]] && _restorefile="$_mjr"
  686. done
  687. fi
  688. # Restore license
  689. if [[ -f "$_restorefile" ]]; then
  690. if ! "mediacenter$_mversion" /RestoreFromFile "$_restorefile"; then
  691. err "Automatic license restore failed"
  692. return 1
  693. fi
  694. fi
  695. }
  696. #######################################
  697. # Opens ports using the system firewall tool
  698. # Arguments
  699. # Pre-defined service to enable
  700. #######################################
  701. openFirewall() {
  702. debug "Running: ${FUNCNAME[0]}" "$@"
  703. # Create OS-specific port rules based on argument (service) name
  704. local -a _f_ports # for firewall-cmd
  705. local _u_ports # for ufw
  706. if [[ "$1" == "jriver" ]]; then
  707. _f_ports=("52100-52200/tcp" "1900/udp")
  708. _u_ports="52100:52200/tcp|1900/udp"
  709. elif [[ "$1" =~ ^(jriver-x11vnc|jriver-xvnc)$ ]]; then
  710. _f_ports=("$_port/tcp" "1900/udp")
  711. _u_ports="$_port/tcp|1900/udp"
  712. fi
  713. # Open the ports
  714. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  715. [[ ! -x $(command -v firewall-cmd) ]] && installPackage firewalld
  716. if ! firewall_cmd --get-services | grep -q "$1"; then
  717. firewall_cmd --permanent --new-service="$1" > /dev/null 2>&1
  718. firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" > /dev/null 2>&1
  719. firewall_cmd --permanent --service="$1" --set-short="$1" > /dev/null 2>&1
  720. for _f_port in "${_f_ports[@]}"; do
  721. firewall_cmd --permanent --service="$1" --add-port="$_f_port" > /dev/null 2>&1
  722. done
  723. firewall_cmd --add-service "$1" --permanent > /dev/null 2>&1
  724. firewall_cmd --reload > /dev/null 2>&1
  725. fi
  726. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  727. # Debian ufw package state is broken on fresh installations
  728. [[ ! -x $(command -v ufw) ]] && installPackage ufw
  729. if [[ ! -f "/etc/ufw/applications.d/$1" ]]; then
  730. bash_cmd "cat <<- EOF > /etc/ufw/applications.d/$1
  731. [$1]
  732. title=$1
  733. description=$1 installed by installJRMC
  734. ports=$_u_ports
  735. EOF"
  736. fi
  737. firewall_cmd app update "$1"
  738. firewall_cmd allow "$1" > /dev/null 2>&1
  739. fi
  740. # shellcheck disable=SC2181 # More concise
  741. if [[ $? -ne 0 ]]; then
  742. err "Firewall ports could not be opened"
  743. return 1
  744. fi
  745. }
  746. #######################################
  747. # Create the x11vnc password file
  748. #######################################
  749. setX11VNCPass() {
  750. debug "Running: ${FUNCNAME[0]}"
  751. _vncpassfile="$HOME/.vnc/jrmc_passwd"
  752. [[ ! -d "${_vncpassfile%/*}" ]] && mkdir -p "${_vncpassfile%/*}"
  753. if [[ -f "$_vncpassfile" ]]; then
  754. if [[ ! -v _vncpass ]]; then
  755. err "Refusing to overwrite existing $_vncpassfile with an empty password"
  756. err "Remove existing $_vncpassfile or set --vncpass to use an empty password"
  757. exit 1
  758. else
  759. rm -f "$_vncpassfile"
  760. fi
  761. fi
  762. if [[ -v _vncpass ]]; then
  763. if ! x11vnc -storepasswd "$_vncpass" "$_vncpassfile"; then
  764. err "Could not create VNC password file"
  765. return 1
  766. fi
  767. else
  768. _novncauth="true"
  769. fi
  770. }
  771. #######################################
  772. # Create the Xvnc password file
  773. #######################################
  774. setVNCPass() {
  775. debug "Running: ${FUNCNAME[0]}"
  776. _vncpassfile="$HOME/.vnc/jrmc_passwd"
  777. [[ ! -d "${_vncpassfile%/*}" ]] && mkdir -p "${_vncpassfile%/*}"
  778. if [[ -f "$_vncpassfile" ]]; then
  779. if [[ ! -v _vncpass ]]; then
  780. err "Refusing to overwrite existing $_vncpassfile with an empty password"
  781. err "Remove existing $_vncpassfile or set --vncpass to use an empty password"
  782. exit 1
  783. else
  784. rm -f "$_vncpassfile"
  785. fi
  786. fi
  787. if [[ -v _vncpass ]]; then
  788. if ! echo "$_vncpass" | vncpasswd -f > "$_vncpassfile"; then
  789. err "Could not create VNC password file"
  790. return 1
  791. fi
  792. else
  793. _novncauth="true"
  794. fi
  795. }
  796. #######################################
  797. # Set display and port variables
  798. #######################################
  799. setDisplay() {
  800. debug "Running: ${FUNCNAME[0]}"
  801. # Check _display, else DISPLAY, else set to :0 by default
  802. if [[ -v _display ]]; then
  803. _next_display="$_display"
  804. elif [[ -v DISPLAY ]]; then
  805. _display="${DISPLAY}"
  806. _displaynum="${_display#:}" # strip colon
  807. _displaynum="${_displaynum%.*}" # strip suffix
  808. _next_displaynum=$(( _displaynum + 1 ))
  809. _next_display=":$_next_displaynum"
  810. else
  811. _display=":0"
  812. _next_display=":1"
  813. fi
  814. _displaynum="${_display#:}" # strip colon
  815. _displaynum="${_displaynum%.*}" # strip suffix
  816. _next_displaynum=$(( _displaynum + 1 ))
  817. }
  818. #######################################
  819. # Create associated service variables based on service name
  820. #######################################
  821. setServiceVars() {
  822. debug "Running: ${FUNCNAME[0]}"
  823. if [[ "$_service_user" == "root" ]]; then
  824. _service_fname="$_systemddir/${1}.service"
  825. _timer_fname="$_systemddir/${1}.timer"
  826. _service_name="${1}.service"
  827. _timer_name="${1}.timer"
  828. _user_specifier=""
  829. else
  830. _service_fname="$_systemddir/${1}@.service"
  831. _timer_fname="$_systemddir/${1}@.timer"
  832. _service_name="${1}@$_service_user.service"
  833. _timer_name="${1}@$_service_user.timer"
  834. _user_specifier="User=%I"
  835. fi
  836. }
  837. #######################################
  838. # Starts and enables (at startup) a JRiver Media Center service
  839. # Arguments:
  840. # Passes arguments as startup options to /usr/bin/mediacenter??
  841. #######################################
  842. service_jriver-mediacenter() {
  843. debug "Running: ${FUNCNAME[0]}"
  844. bash_cmd "cat <<- EOF > $_service_fname
  845. [Unit]
  846. Description=JRiver Media Center $_mversion
  847. After=graphical.target
  848. [Service]
  849. $_user_specifier
  850. Type=simple
  851. Environment=DISPLAY=$_display
  852. Environment=XAUTHORITY=$XAUTHORITY
  853. ExecStart=/usr/bin/mediacenter$_mversion $*
  854. Restart=always
  855. RestartSec=10
  856. KillSignal=SIGHUP
  857. TimeoutStopSec=30
  858. [Install]
  859. WantedBy=graphical.target
  860. EOF"
  861. systemctl_reload && \
  862. systemctl_enable "$_service_name" && \
  863. openFirewall "jriver"
  864. }
  865. #######################################
  866. # Starts and enables (at startup) a JRiver Media Server service
  867. #######################################
  868. service_jriver-mediaserver() {
  869. debug "Running: ${FUNCNAME[0]}"
  870. service_jriver-mediacenter "/MediaServer"
  871. }
  872. #######################################
  873. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  874. #######################################
  875. service_jriver-xvnc() {
  876. debug "Running: ${FUNCNAME[0]}"
  877. installPackage tigervnc-server
  878. setVNCPass
  879. local _port=$(( _next_displaynum + 5900 ))
  880. if [[ -v _novncauth ]]; then
  881. _exec_start_cmd="/usr/bin/vncserver $_next_display -geometry 1440x900 -alwaysshared -name jriver$_next_display -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$_mversion"
  882. else
  883. _exec_start_cmd="/usr/bin/vncserver $_next_display -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$_mversion"
  884. fi
  885. bash_cmd "cat <<- EOF > $_service_fname
  886. [Unit]
  887. Description=Remote desktop service (VNC)
  888. After=syslog.target network.target
  889. [Service]
  890. Type=simple
  891. $_user_specifier
  892. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $_next_display > /dev/null 2>&1 || :'
  893. ExecStart=$_exec_start_cmd
  894. ExecStop=/usr/bin/vncserver -kill $_next_display
  895. Restart=always
  896. [Install]
  897. WantedBy=multi-user.target
  898. EOF"
  899. systemctl_reload && \
  900. systemctl_enable "$_service_name" && \
  901. echo "Xvnc running on localhost:$_port" && \
  902. openFirewall "jriver-xvnc" && \
  903. openFirewall "jriver"
  904. }
  905. #######################################
  906. # Starts and enables (at startup) JRiver Media Server and x11vnc sharing the local desktop
  907. #######################################
  908. service_jriver-x11vnc() {
  909. debug "Running: ${FUNCNAME[0]}"
  910. installPackage x11vnc
  911. setX11VNCPass
  912. local _port=$(( _displaynum + 5900 ))
  913. # Get current desktop resolution
  914. # TODO: may need to break this out into its own function and get smarter at identifying multi-monitors
  915. _getResolution() {
  916. debug "Running: ${FUNCNAME[0]}"
  917. installPackage xorg-x11-utils
  918. _res=$(xdpyinfo | grep dimensions | awk '{print $2}')
  919. }
  920. _getResolution
  921. if [[ -v _novncauth ]]; then
  922. _exec_start_cmd="/usr/bin/x11vnc -display $_display -noscr -geometry $_res -auth guess -forever -bg -nopw"
  923. else
  924. _exec_start_cmd="/usr/bin/x11vnc -display $_display -noscr -geometry $_res -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd"
  925. fi
  926. bash_cmd "cat <<-EOF > $_service_fname
  927. [Unit]
  928. Description=x11vnc
  929. After=multi.service
  930. [Service]
  931. $_user_specifier
  932. Type=forking
  933. Environment=DISPLAY=$_display
  934. ExecStart=$_exec_start_cmd
  935. Restart=always
  936. RestartSec=10
  937. [Install]
  938. WantedBy=multi-user.target
  939. EOF"
  940. systemctl_reload && \
  941. systemctl_enable "$_service_name" && \
  942. echo "x11vnc running on localhost:$_port" && \
  943. openFirewall "jriver-x11vnc"
  944. }
  945. #######################################
  946. # Starts and enables (at startup) an hourly service to build the latest version of JRiver Media
  947. # Center RPM from the source DEB and create/update an RPM repository
  948. #######################################
  949. service_jriver-createrepo() {
  950. debug "Running: ${FUNCNAME[0]}"
  951. bash_cmd "cat <<-EOF > $_service_fname
  952. [Unit]
  953. Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo
  954. [Service]
  955. $_user_specifier
  956. ExecStart=$PWD/installJRMC --outputdir $_outputdir --createrepo --createrepo-webroot $_createrepo_webroot --createrepo-user $_createrepo_user
  957. [Install]
  958. WantedBy=default.target
  959. EOF"
  960. bash_cmd "cat <<-EOF > $_timer_fname
  961. [Unit]
  962. Description=Run JRiver MC rpmbuild hourly
  963. [Timer]
  964. OnCalendar=hourly
  965. Persistent=true
  966. [Install]
  967. WantedBy=timers.target
  968. EOF"
  969. systemctl_reload && \
  970. systemctl_enable "$_timer_name"
  971. }
  972. #######################################
  973. # CONTAINERS
  974. #######################################
  975. # containerCreaterepo() {
  976. # :
  977. # }
  978. # containerVNC() {
  979. # :
  980. # }
  981. # containerMC() {
  982. # installPackage buildah podman
  983. # cnt=$(buildah from docker.io/jlesage/baseimage-gui:debian-10)
  984. # podman_create_cmd=("podman" "create" "--name" "$CNAME")
  985. # buildah_config_cmd=("buildah" "config" \
  986. # "--author" "bryanroessler@gmail.com" \
  987. # "--label" "maintainer=$MAINTAINER" \
  988. # "--env" "TZ=$TZ" \
  989. # "--workingdir" "/app" \
  990. # "--cmd" "mediacenter$_mversion")
  991. # mkcdirs() {
  992. # local dir
  993. # for dir in "$@"; do
  994. # if [[ ! -d "$dir" ]]; then
  995. # if ! mkdir -p "$dir"; then
  996. # err "Could not create directory $dir, check your permissions"
  997. # fi
  998. # fi
  999. # if ! chcon -t container_file_t -R "$dir"; then
  1000. # err "Could not set container_file_t attribute for $dir, check your permissions"
  1001. # fi
  1002. # done
  1003. # }
  1004. # mkcdirs "$HOME/.jriver"
  1005. # podman_create_cmd+=("-v" "$HOME/.jriver:/root/.jriver")
  1006. # podman_create_cmd+=("-v" "$DOWNLOAD_ROOT:/downloads:z")
  1007. # podman_create_cmd+=("-v" "$MONITOR_ROOT/nzbs:/nzbs")
  1008. # podman_create_cmd+=("-p" "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1009. # brc() { buildah run "$1" "${@:2}" || return 1; }
  1010. # brc add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1
  1011. # brc add-pkg --virtual .build-deps wget
  1012. # brc sh -s <<- EOF
  1013. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - > /dev/null 2>&1
  1014. # EOF
  1015. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$_mversion.list" -O "/etc/apt/sources.list.d/mediacenter$_mversion.list"
  1016. # brc apt-get update -y -q0
  1017. # brc add-pkg "mediacenter$_mversion"
  1018. # brc del-pkg .build-deps
  1019. # }
  1020. uninstall() {
  1021. debug "Running: ${FUNCNAME[0]}"
  1022. if ! askOk "Do you really want to uninstall JRiver Media Center"; then
  1023. echo "Cancelling uninstall..."
  1024. exit 0
  1025. fi
  1026. debug "Stopping and removing all associated Media Center services"
  1027. for _service in $(compgen -A "function" "service"); do
  1028. _service="${_service##service_}"
  1029. setServiceVars "$_service"
  1030. for unit in "$_service_name" "$_timer_name"; do
  1031. if systemctl is-active -q "$unit" > /dev/null 2>&1 || systemctl is-enabled -q "$unit" > /dev/null 2>&1; then
  1032. debug "Disabling $unit"
  1033. systemctl_disable "$unit"
  1034. fi
  1035. done
  1036. for f in "$_service_fname" "$_timer_fname"; do
  1037. debug "Removing $f"
  1038. rm_cmd "$f"
  1039. done
  1040. systemctl_reload
  1041. done
  1042. debug "Removing repo files"
  1043. [[ -f "/etc/yum.repos.d/jriver.repo" ]] \
  1044. && rm_cmd "/etc/yum.repos.d/jriver.repo"
  1045. [[ -f "/etc/apt/sources.list.d/jriver.list" ]] \
  1046. && rm_cmd "/etc/apt/sources.list.d/jriver.list"
  1047. if [[ "$ID" =~ ^opensuse.* ]]; then
  1048. ifSudo zypper rr jriver > /dev/null 2>&1
  1049. fi
  1050. debug "Removing firewall rules"
  1051. if [[ -x $(command -v firewall-cmd) ]]; then
  1052. if [[ -v debug ]]; then
  1053. debug "firewall_cmd --permanent --remove-service=jriver"
  1054. firewall_cmd --permanent --remove-service=jriver
  1055. debug "firewall_cmd --permanent --delete-service=jriver"
  1056. firewall_cmd --permanent --delete-service=jriver
  1057. debug "firewall_cmd --reload"
  1058. firewall_cmd --reload
  1059. else
  1060. firewall_cmd --permanent --remove-service=jriver > /dev/null 2>&1
  1061. firewall_cmd --permanent --delete-service=jriver > /dev/null 2>&1
  1062. firewall_cmd --reload > /dev/null 2>&1
  1063. fi
  1064. elif [[ -x $(command -v ufw) ]]; then
  1065. if [[ -v debug ]]; then
  1066. firewall_cmd delete allow jriver
  1067. else
  1068. firewall_cmd delete allow jriver > /dev/null 2>&1
  1069. fi
  1070. [[ -f "/etc/ufw/applications.d/jriver" ]] \
  1071. && rm_cmd /etc/ufw/applications.d/jriver
  1072. fi
  1073. debug "Uninstalling Media Center packages"
  1074. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  1075. _mcpkg="MediaCenter"
  1076. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
  1077. _mcpkg="mediacenter$_mversion"
  1078. fi
  1079. if debug; then
  1080. debug "pkg_remove -q $_mcpkg"
  1081. pkg_remove "-q" "$_mcpkg"
  1082. else
  1083. pkg_remove "-q" "$_mcpkg" > /dev/null 2>&1
  1084. fi
  1085. echo "JRiver Media Center has been completely uninstalled."
  1086. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1087. echo "To remove your rpmbuild output files, run: rm -rf $_outputdir"
  1088. exit 0
  1089. }
  1090. tests() {
  1091. # To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1092. exit $?
  1093. }
  1094. main() {
  1095. debug "Running: ${FUNCNAME[0]}"
  1096. init "$@"
  1097. # Uninstall and exit
  1098. if [[ -v _uninstall ]]; then
  1099. uninstall
  1100. exit $?
  1101. fi
  1102. # Install MC using package manager
  1103. if [[ -v _install && "$_install" == "repo" ]]; then
  1104. if installMCFromRepo; then
  1105. echo "JRiver Media Center installed successfully"
  1106. else
  1107. err "JRiver Media Center installation failed"
  1108. exit 1
  1109. fi
  1110. symlinkCerts
  1111. restoreLicense
  1112. openFirewall "jriver"
  1113. fi
  1114. # Build RPM from source deb package
  1115. if [[ -v _build ]]; then
  1116. acquireDeb
  1117. if ! buildRPM; then
  1118. err "Build failed."
  1119. # In case this is automated, let's remove the source DEB and reaquire
  1120. # it on next run in case it is corrupted or buggy
  1121. [[ -f "$DEBFILENAME" ]] && echo "Removing source DEB" && rm -f "$DEBFILENAME"
  1122. exit 1
  1123. fi
  1124. fi
  1125. # Run createrepo
  1126. if [[ -v _createrepo ]]; then
  1127. runCreaterepo
  1128. exit $?
  1129. fi
  1130. # Install RPM
  1131. if [[ -v _install && "$_install" == "rpm" ]]; then
  1132. if installPackage --nocheck --nogpgcheck "$_mcrpm"; then
  1133. echo "JRiver Media Center installed successfully"
  1134. else
  1135. err "JRiver Media Center installation failed"
  1136. exit 1
  1137. fi
  1138. symlinkCerts
  1139. restoreLicense
  1140. openFirewall "jriver"
  1141. fi
  1142. # Install services
  1143. if [[ "${#_services[@]}" -gt 0 ]]; then
  1144. setDisplay
  1145. ! [[ -d "$_systemddir" ]] && ifSudo mkdir -p "$_systemddir"
  1146. for _service in "${_services[@]}"; do
  1147. setServiceVars "$_service"
  1148. if ! "service_$_service"; then
  1149. if [[ $? -eq 127 ]]; then
  1150. err "Service $_service does not exist, check your service name"
  1151. else
  1152. err "Failed to create service: $_service"
  1153. fi
  1154. fi
  1155. done
  1156. fi
  1157. # Install containers
  1158. # for _container in "${_containers[@]}"; do
  1159. # if ! "_container_$_container"; then
  1160. # if [[ $? -eq 127 ]]; then
  1161. # err "Container $_container does not exist, check your container name"
  1162. # else
  1163. # err "Failed to create container: $_container"
  1164. # fi
  1165. # fi
  1166. # done
  1167. }
  1168. main "$@"