installJRMC 50 KB

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