installJRMC 51 KB

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