installJRMC 51 KB

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