installJRMC 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  1. #!/usr/bin/env bash
  2. # Install JRiver Media Center and associated services
  3. # See installJRMC --help or printHelp() below
  4. #
  5. # Copyright (c) 2021-2023 Bryan C. Roessler
  6. # This software is released under the Apache License.
  7. # https://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # TODO (v2)
  10. # 1. Interactive installation (ncurses?)
  11. # 2. Additional containerization (createrepo and rpmbuild)
  12. # 3. Tests
  13. #
  14. # BUGS
  15. # 1. No createrepo on Mint
  16. shopt -s extglob
  17. declare -g SCRIPTVERSION="1.0-rc4"
  18. declare -g OUTPUTDIR="$PWD/output"
  19. declare -g BOARDURL="https://yabb.jriver.com/interact/index.php/board,76.0.html" # MC30 (Buster)
  20. declare -g DEBIANBASE="buster"
  21. declare -g MCVERSION_HARDCODE="30.0.48" # Hardcoded fallback
  22. declare -g CREATEREPO_WEBROOT="/var/www/jriver"
  23. declare -g USER="${SUDO_USER:-$USER}"
  24. declare -g HOME; HOME=$(getent passwd "$USER" | cut -d: -f6)
  25. printHelp() {
  26. debug "Running: ${FUNCNAME[0]}"
  27. cat <<-'EOF'
  28. USAGE:
  29. installJRMC [[OPTION] [VALUE]]...
  30. If no options (excluding -d) are provided, the script will default to '--install repo'.
  31. OPTIONS
  32. --install, -i repo|local
  33. repo: Install MC from repository, updates are handled by the system package manager
  34. local: Build and install MC package locally
  35. --build[=suse|fedora|centos]
  36. Build RPM from source DEB but do not install
  37. Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
  38. --compat
  39. Build/install MC locally without minimum library specifiers
  40. --mcversion VERSION
  41. Specify the MC version, ex. "30.0.17" (Default: latest version)
  42. --outputdir PATH
  43. Generate rpmbuild output in this directory (Default: ./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-type user|system
  51. Starts services at boot (system) or at user login (user) (Default: boot)
  52. --container, -c CONTAINER (TODO: Under construction)
  53. See CONTAINERS section below for a list of possible services to install
  54. --createrepo[=suse|fedora|centos]
  55. Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos
  56. Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
  57. --createrepo-webroot PATH
  58. Specify the webroot directory to install the repo (Default: /var/www/jriver)
  59. --createrepo-user USER
  60. Specify the web server user if it differs from $USER
  61. --version, -v
  62. Print this script version and exit
  63. --debug, -d
  64. Print debug output
  65. --help, -h
  66. Print help dialog and exit
  67. --uninstall, -u
  68. Uninstall JRiver MC, remove services, and remove firewall rules (does not remove library files)
  69. SERVICES
  70. jriver-mediaserver
  71. Enable and start a mediaserver systemd service (requires an existing X server) (user)
  72. jriver-mediacenter
  73. Enable and start a mediacenter systemd service (requires an existing X server) (user)
  74. jriver-x11vnc
  75. Enable and start x11vnc for the local desktop (requires an existing X server) (user)
  76. Usually combined with jriver-mediaserver or jriver-mediacenter services
  77. --vncpass and --display are optional (see below)
  78. jriver-xvnc
  79. Enable and start a new Xvnc session running JRiver Media Center (system)
  80. --vncpass PASSWORD
  81. Set vnc password for x11vnc/Xvnc access. If no password is set, the script
  82. will either use existing password stored in $HOME/.vnc/jrmc_passwd or use no password
  83. --display DISPLAY
  84. Display to start x11vnc/Xvnc (Default: The current display (x11vnc) or the
  85. current display incremented by 1 (Xvnc))
  86. jriver-createrepo
  87. Install hourly service to build latest MC RPM and run createrepo (system)
  88. CONTAINERS (TODO: Under construction)
  89. mediacenter-xvnc
  90. createrepo
  91. EOF
  92. }
  93. # Helpers
  94. debug() { (( DEBUG )) && [[ $# -gt 0 ]] && echo "Debug: $*"; }
  95. err() { echo "Error: $*" >&2; }
  96. askOk() {
  97. declare response
  98. read -r -p "$* [y/N]: " response
  99. [[ "${response,,}" =~ ^(yes|y)$ ]]
  100. }
  101. #######################################
  102. # Parses user input and sets sensible defaults
  103. #######################################
  104. parseInput() {
  105. debug "Running: ${FUNCNAME[0]}"
  106. declare -g BUILD_SWITCH REPO_INSTALL_SWITCH COMPAT_SWITCH LOCAL_INSTALL_SWITCH CREATEREPO_SWITCH UNINSTALL_SWITCH TEST_SWITCH
  107. declare -g OUTPUTDIR RESTOREFILE BETAPASS SERVICE_TYPE VNCPASS USER_DISPLAY CREATEREPO_WEBROOT
  108. declare -ga SERVICES CONTAINERS
  109. declare long_opts short_opts input
  110. # Allow some environment variables to override and set sane fallbacks
  111. declare -g TARGET=${TARGET:-$ID}
  112. declare -g CREATEREPO_USER="${CREATEREPO_USER:-$USER}"
  113. if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$1" =~ ^(--debug|-d)$ ]]; then
  114. REPO_INSTALL_SWITCH=1
  115. elif [[ $# -eq 1 && "$1" =~ ^(--compat)$ ]]; then
  116. BUILD_SWITCH=1
  117. LOCAL_INSTALL_SWITCH=1
  118. fi
  119. long_opts="install:,build::,outputdir:,mcversion:,restorefile:,betapass:,"
  120. long_opts+="service-type:,service:,version,debug,help,uninstall,createrepo::,"
  121. long_opts+="createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests,compat"
  122. short_opts="+i:vb::dhus:c:"
  123. if input=$(getopt -o $short_opts -l $long_opts -- "$@"); then
  124. eval set -- "$input"
  125. while true; do
  126. case "$1" in
  127. --install|-i)
  128. shift
  129. case "$1" in
  130. local|rpm)
  131. BUILD_SWITCH=1
  132. LOCAL_INSTALL_SWITCH=1
  133. ;;
  134. repo)
  135. REPO_INSTALL_SWITCH=1
  136. ;;
  137. esac
  138. ;;
  139. --build|-b)
  140. BUILD_SWITCH=1
  141. shift && TARGET="$1"
  142. ;;
  143. --outputdir)
  144. shift && OUTPUTDIR="$1"
  145. ;;
  146. --mcversion)
  147. shift && declare -g MCVERSION_INPUT="$1"
  148. ;;
  149. --restorefile)
  150. shift && RESTOREFILE="$1"
  151. ;;
  152. --betapass)
  153. shift && BETAPASS="$1"
  154. ;;
  155. --service-type)
  156. shift && SERVICE_TYPE="$1"
  157. ;;
  158. --service|-s)
  159. shift && SERVICES+=("$1")
  160. ;;
  161. --createrepo)
  162. BUILD_SWITCH=1
  163. CREATEREPO_SWITCH=1
  164. shift && TARGET="$1"
  165. ;;
  166. --createrepo-webroot)
  167. shift && CREATEREPO_WEBROOT="$1"
  168. ;;
  169. --createrepo-user)
  170. shift && CREATEREPO_USER="$1"
  171. ;;
  172. --vncpass)
  173. shift && VNCPASS="$1"
  174. ;;
  175. --display)
  176. shift && USER_DISPLAY="$1"
  177. ;;
  178. --compat)
  179. COMPAT_SWITCH=1
  180. ;;
  181. --container|-c)
  182. shift && CONTAINERS+=("$1")
  183. ;;
  184. --version|-v)
  185. echo "Version: $SCRIPTVERSION"
  186. exit 0
  187. ;;
  188. --debug|-d)
  189. DEBUG=1
  190. ;;
  191. --help|-h)
  192. printHelp
  193. exit
  194. ;;
  195. --uninstall|-u)
  196. UNINSTALL_SWITCH=1
  197. ;;
  198. --tests)
  199. TEST_SWITCH=1
  200. ;;
  201. --)
  202. shift
  203. break
  204. ;;
  205. esac
  206. shift
  207. done
  208. else
  209. err "Incorrect options provided"
  210. printHelp && exit 1
  211. fi
  212. }
  213. #######################################
  214. # Perform OS detection and fallback
  215. # Generate OS-specific functions
  216. #######################################
  217. init() {
  218. debug "Running: ${FUNCNAME[0]}"
  219. declare -g ID RPM_MGR
  220. echo "Starting installJRMC"
  221. debug || echo "To enable debugging output, use --debug or -d"
  222. if [[ -e "/etc/os-release" ]]; then
  223. source "/etc/os-release"
  224. else
  225. err "/etc/os-release not found"
  226. err "Your OS is unsupported"
  227. printHelp
  228. exit 1
  229. fi
  230. debug "Detected host platform: $ID $VERSION_ID"
  231. # normalize ID and set distro-specific vars
  232. case "$ID" in
  233. debian|arch)
  234. ;;
  235. centos|fedora)
  236. if hash dnf &>/dev/null; then
  237. RPM_MGR="dnf"
  238. elif hash yum &>/dev/null; then
  239. RPM_MGR="yum"
  240. fi
  241. ;;
  242. rhel)
  243. ID="centos"
  244. ;;
  245. linuxmint|neon|*ubuntu*)
  246. ID="ubuntu"
  247. ;;
  248. *suse*)
  249. ID="suse"
  250. ;;
  251. raspbian)
  252. ID="debian"
  253. ;;
  254. *)
  255. echo "Autodetecting distro, this may be unreliable and --compat may also be required"
  256. if hash dnf &>/dev/null; then
  257. ID="fedora"
  258. RPM_MGR="dnf"
  259. elif hash yum &>/dev/null; then
  260. ID="centos"
  261. RPM_MGR="yum"
  262. COMPAT_SWITCH=1
  263. elif hash apt &>/dev/null; then
  264. ID="ubuntu"
  265. elif hash pacman &>/dev/null; then
  266. ID="arch"
  267. else
  268. err "OS detection failed!"
  269. exit 1
  270. fi
  271. ;;
  272. esac
  273. debug "Using host platform: $ID $VERSION_ID"
  274. # Set distro-specific functions
  275. case "$ID" in
  276. fedora|centos)
  277. pkg_install(){ sudo "$RPM_MGR" install -y "$@"; }
  278. pkg_install_local() { installMCRPM; }
  279. pkg_remove(){ sudo "$RPM_MGR" remove -y "$@"; }
  280. pkg_update(){ sudo "$RPM_MGR" makecache; }
  281. pkg_swap() { sudo dnf swap -y "$1" "$2"; }
  282. pkg_query(){ rpm -q "$@"; }
  283. firewall_cmd(){ sudo firewall-cmd "$@"; }
  284. ;;
  285. debian|ubuntu)
  286. pkg_install(){ sudo apt-get install -y -q0 "$@"; }
  287. pkg_install_local() { installMCDEB; }
  288. pkg_remove(){ sudo apt-get remove --auto-remove -y -q0 "$@"; }
  289. pkg_update(){ sudo apt-get update -y -q0; }
  290. pkg_query(){ dpkg -s "$@"; }
  291. firewall_cmd(){ sudo ufw "$@"; }
  292. ;;
  293. suse)
  294. pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; }
  295. pkg_install_local() { installMCRPM; }
  296. pkg_remove(){ sudo zypper --non-interactive -q remove --clean-deps "$@"; }
  297. pkg_update(){ sudo zypper --non-interactive -q refresh jriver; }
  298. pkg_query(){ rpm -q "$@"; }
  299. firewall_cmd(){ sudo firewall-cmd "$@"; }
  300. ;;
  301. arch)
  302. pkg_install(){ sudo pacman -Sy --noconfirm "$@"; }
  303. pkg_install_local() { installMCARCH; }
  304. pkg_remove(){ sudo pacman -Rs --noconfirm "$@"; }
  305. pkg_update(){ sudo pacman -Syy ; }
  306. pkg_query(){ sudo pacman -Qs "$@"; }
  307. #firewall_cmd(){ sudo nft -A INPUT "$@"; }
  308. ;;
  309. esac
  310. }
  311. #######################################
  312. # Uses several methods to determine the latest JRiver MC version
  313. # TODO but how to determine build distro `$DEBIANBASE=buster`?
  314. #######################################
  315. setMCVersion() {
  316. debug "Running: ${FUNCNAME[0]}"
  317. declare -g MCVERSION MCVERSION_SOURCE MVERSION MCPKG MCRPM
  318. declare cnt
  319. # User input
  320. if [[ -v MCVERSION_INPUT ]]; then
  321. if ! [[ "$MCVERSION_INPUT" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  322. err "Incorrect --mcversion format provided"
  323. printHelp && exit 1
  324. fi
  325. MCVERSION="$MCVERSION_INPUT"
  326. MCVERSION_SOURCE="user input"
  327. # Containerized package manager
  328. elif installPackage --silent buildah &&
  329. cnt=$(buildah from --quiet debian:$DEBIANBASE-slim) &>/dev/null &&
  330. buildah run "$cnt" -- bash -c \
  331. "echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $DEBIANBASE main' > /etc/apt/sources.list 2>&1" &>/dev/null &&
  332. buildah run "$cnt" -- bash -c \
  333. "apt update --allow-insecure-repositories &>/dev/null" &>/dev/null &&
  334. MCVERSION=$(buildah run "$cnt" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) &>/dev/null &&
  335. [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  336. MCVERSION_SOURCE="containerized package manager"
  337. buildah rm "$cnt" &>/dev/null
  338. # Webscrape
  339. elif installPackage wget && MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1) &&
  340. [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  341. MCVERSION_SOURCE="webscrape"
  342. # Hardcoded
  343. else
  344. MCVERSION="$MCVERSION_HARDCODE"
  345. MCVERSION_SOURCE="hardcoded version"
  346. err "Warning! Using hardcoded version number."
  347. fi
  348. MVERSION="${MCVERSION%%.*}"
  349. MCPKG="mediacenter$MVERSION"
  350. MCRPM="$OUTPUTDIR/RPMS/x86_64/mediacenter$MVERSION-$MCVERSION.x86_64.rpm"
  351. if [[ "$MCVERSION_SOURCE" == "user input" ]]; then
  352. # Append explicit package version when user provides --mcversion
  353. case "$ID" in
  354. fedora|centos|suse)
  355. MCPKG+="-$MCVERSION"
  356. ;;
  357. debian|ubuntu)
  358. MCPKG+="=$MCVERSION"
  359. ;;
  360. esac
  361. fi
  362. echo "Using MC version $MCVERSION determined by $MCVERSION_SOURCE."
  363. [[ "$MCVERSION_SOURCE" == "user input" ]] || echo "To override, use --mcversion."
  364. debug "MVERSION: $MVERSION, MCVERSION: $MCVERSION, MCPKG: $MCPKG, MCRPM: $MCRPM"
  365. }
  366. #######################################
  367. # Installs a package using the system package manager
  368. # Arguments:
  369. # One or more package names
  370. # Options:
  371. # --skip-check-installed: Do not check if package is already installed
  372. # --no-gpg-check: Disable GPG checks for RPM based distros
  373. # --allow-downgrades: Useful for installing specific MC versions
  374. # --silent, -s: Do not report errors (useful if package is not strictly required and errors are noisy)
  375. #######################################
  376. installPackage() {
  377. debug "Running: ${FUNCNAME[0]}" "$@"
  378. declare -a pkg_array install_flags
  379. declare input pkg skip_check_installed silent pkg_install_cmd refresh allow_downgrades no_gpg_check
  380. declare -A pkg_aliases
  381. if input=$(getopt -o +s -l skip-check-installed,allow-downgrades,no-gpg-check,refresh,silent -- "$@"); then
  382. eval set -- "$input"
  383. while true; do
  384. case "$1" in
  385. --skip-check-installed)
  386. skip_check_installed=1
  387. ;;
  388. --allow-downgrades)
  389. allow_downgrades=1
  390. ;;
  391. --no-gpg-check)
  392. no_gpg_check=1
  393. ;;
  394. --refresh)
  395. refresh=1
  396. ;;
  397. --silent|-s)
  398. silent=1
  399. ;;
  400. --)
  401. shift
  402. break
  403. ;;
  404. esac
  405. shift
  406. done
  407. else
  408. err "Incorrect options provided"
  409. exit 1
  410. fi
  411. # Package aliases
  412. case "$ID" in
  413. debian|ubuntu)
  414. pkg_aliases["rpm-build"]="rpm"
  415. pkg_aliases["createrepo_c"]="createrepo"
  416. pkg_aliases["tigervnc-server"]="tigervnc-standalone-server"
  417. ;;
  418. esac
  419. # Filter installed packages
  420. for pkg in "$@"; do
  421. if [[ -v pkg_aliases[$pkg] ]]; then
  422. pkg=${pkg_aliases[$pkg]}
  423. fi
  424. if (( skip_check_installed )) || ! (hash "$pkg" &>/dev/null || pkg_query "$pkg" &>/dev/null); then
  425. pkg_array+=("$pkg")
  426. else
  427. debug "$pkg already installed, skipping installation"
  428. fi
  429. done
  430. # Generate distro-specific install flags
  431. case "$ID" in
  432. debian|ubuntu)
  433. (( allow_downgrades )) && install_flags+=(--allow-downgrades)
  434. ;;
  435. fedora|centos)
  436. (( allow_downgrades )) && install_flags+=(--allowerasing)
  437. (( no_gpg_check )) && install_flags+=(--nogpgcheck)
  438. (( refresh )) && install_flags+=(--refresh)
  439. ;;
  440. suse)
  441. (( no_gpg_check )) && install_flags+=(--allow-unsigned-rpm)
  442. ;;
  443. esac
  444. # Install packages from package array
  445. if [[ ${#pkg_array[@]} -ge 1 ]]; then
  446. pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}"
  447. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  448. if ! eval "$pkg_install_cmd"; then
  449. (( silent )) || err "Failed to install ${pkg_array[*]}. Attempting to continue"
  450. return 1
  451. fi
  452. fi
  453. return 0
  454. }
  455. #######################################
  456. # Installs JRiver Media Center from a remote repository
  457. #######################################
  458. installMCFromRepo() {
  459. debug "Running: ${FUNCNAME[0]}"
  460. declare repo_dir
  461. case "$ID" in
  462. fedora|centos)
  463. repo_dir="/etc/yum.repos.d/"
  464. sudo bash -c "cat <<-EOF > $repo_dir/jriver.repo
  465. [jriver]
  466. name=JRiver Media Center repo by BryanC
  467. baseurl=https://repos.bryanroessler.com/jriver
  468. gpgcheck=0
  469. EOF"
  470. ;;
  471. debian|ubuntu)
  472. repo_dir="/etc/apt/sources.list.d"
  473. [[ ! -d $repo_dir ]] && sudo mkdir -p "$repo_dir"
  474. sudo rm -rf "$repo_dir"/mediacenter*.list
  475. installPackage wget
  476. sudo bash -c "cat <<-EOF > $repo_dir/jriver.list
  477. deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $DEBIANBASE main
  478. EOF"
  479. wget -qO- "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" | sudo tee /etc/apt/trusted.gpg.d/jriver.asc &>/dev/null
  480. ;;
  481. *)
  482. err "An MC repository for $ID is not yet available."
  483. err "Try using --install local to install MC on $ID."
  484. return 1
  485. ;;
  486. esac
  487. declare pkg_update_cmd="pkg_update"
  488. debug "$pkg_update_cmd" || pkg_update_cmd+=" &>/dev/null"
  489. if ! eval "$pkg_update_cmd"; then
  490. err "Package update failed!"
  491. return 1
  492. fi
  493. # Install mesa-va-drivers-freeworld separately from the RPM for dnf swap
  494. installMesa
  495. declare pkg_install_cmd="installPackage --skip-check-installed --allow-downgrades --no-gpg-check $MCPKG"
  496. debug "$pkg_install_cmd"
  497. if ! eval "$pkg_install_cmd"; then
  498. err "Package install failed!"
  499. return 1
  500. fi
  501. }
  502. #######################################
  503. # Acquires the source DEB package from JRiver
  504. #######################################
  505. acquireDeb() {
  506. debug "Running: ${FUNCNAME[0]}"
  507. declare -g MCDEB="$OUTPUTDIR/SOURCES/MediaCenter-$MCVERSION-amd64.deb"
  508. # If necessary, create SOURCES dir
  509. [[ ! -d "$OUTPUTDIR/SOURCES" ]] && mkdir -p "$OUTPUTDIR/SOURCES"
  510. # If deb file already exists, skip download
  511. if [[ -f "$MCDEB" ]]; then
  512. echo "Using existing DEB: $MCDEB"
  513. return 0
  514. fi
  515. if [[ -v BETAPASS ]]; then
  516. echo "Checking beta repo for DEB package"
  517. if wget -q -O "$MCDEB" \
  518. "https://files.jriver.com/mediacenter/channels/v$MVERSION/beta/$BETAPASS/MediaCenter-$MCVERSION-amd64.deb"; then
  519. echo "Found!"
  520. fi
  521. elif echo "Checking latest repo for DEB package" && wget -q -O "$MCDEB" \
  522. "https://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb"; then
  523. echo "Found!"
  524. elif echo "Checking test repo for DEB package" && wget -q -O "$MCDEB" \
  525. "https://files.jriver.com/mediacenter/test/MediaCenter-$MCVERSION-amd64.deb"; then
  526. echo "Found!"
  527. else
  528. err "Cannot find DEB file"
  529. exit 1
  530. fi
  531. if [[ -f "$MCDEB" ]]; then
  532. echo "Downloaded MC $MCVERSION DEB to $MCDEB"
  533. else
  534. err "Downloaded DEB file missing or corrupted"
  535. exit 1
  536. fi
  537. }
  538. #######################################
  539. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  540. #######################################
  541. buildRPM() {
  542. debug "Running: ${FUNCNAME[0]}"
  543. declare i rpmbuild_cmd
  544. declare -a requires recommends
  545. # skip rebuilding the rpm if it already exists
  546. if [[ -f "$MCRPM" ]]; then
  547. echo "$MCRPM already exists. Skipping build step"
  548. return 0
  549. fi
  550. [[ ! -d "$OUTPUTDIR/SPECS" ]] && mkdir -p "$OUTPUTDIR/SPECS"
  551. # Load deb dependencies into array
  552. IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MCDEB" Depends)"
  553. IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MCDEB" Recommends)"
  554. # Clean up formatting
  555. requires=("${requires[@]%%|*}")
  556. requires=("${requires[@]/?:/}")
  557. requires=("${requires[@]# }")
  558. requires=("${requires[@]% }")
  559. requires=("${requires[@]//\(/}")
  560. requires=("${requires[@]//)/}")
  561. recommends=("${recommends[@]%%|*}")
  562. recommends=("${recommends[@]/?:/}")
  563. recommends=("${recommends[@]# }")
  564. recommends=("${recommends[@]% }")
  565. recommends=("${recommends[@]//\(/}")
  566. recommends=("${recommends[@]//)/}")
  567. # Translate package names
  568. case "$TARGET" in
  569. fedora|centos)
  570. requires=("${requires[@]/libc6/glibc}")
  571. requires=("${requires[@]/libasound2/alsa-lib}")
  572. requires=("${requires[@]/libuuid1/libuuid}")
  573. requires=("${requires[@]/libx11-6/libX11}")
  574. requires=("${requires[@]/libxext6/libXext}")
  575. requires=("${requires[@]/libxcb1/libxcb}")
  576. requires=("${requires[@]/libxdmcp6/libXdmcp}")
  577. requires=("${requires[@]/libstdc++6/libstdc++}")
  578. requires=("${requires[@]/libgtk-3-0/gtk3}")
  579. requires=("${requires[@]/libgl1/mesa-libGL}")
  580. requires=("${requires[@]/libpango-1.0-0/pango}")
  581. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  582. requires=("${requires[@]/libpangox-1.0-0/pango}")
  583. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  584. requires=("${requires[@]/libnss3/nss}")
  585. requires=("${requires[@]/libnspr4/nspr}")
  586. requires=("${requires[@]/libgomp1/libgomp}")
  587. requires=("${requires[@]/libfribidi0/fribidi}")
  588. requires=("${requires[@]/libfontconfig1/fontconfig}")
  589. requires=("${requires[@]/libfreetype6/freetype}")
  590. requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
  591. requires=("${requires[@]/libgbm1/mesa-libgbm}")
  592. requires=("${requires[@]/libva2/libva}")
  593. requires=("${requires[@]/libepoxy0/libepoxy}")
  594. requires=("${requires[@]/liblcms2-2/lcms2}")
  595. requires=("${requires[@]/libvulkan1/vulkan-loader}")
  596. requires=("${requires[@]/libepoxy0/libepoxy}")
  597. requires=("${requires[@]/python/python3}")
  598. recommends+=(mesa-va-drivers-freeworld)
  599. ;;
  600. suse)
  601. requires=("${requires[@]/libc6/glibc}")
  602. requires=("${requires[@]/libasound2/alsa-lib}")
  603. requires=("${requires[@]/libx11-6/libX11-6}")
  604. requires=("${requires[@]/libxext6/libXext6}")
  605. requires=("${requires[@]/libxdmcp6/libXdmcp6}")
  606. requires=("${requires[@]/libgtk-3-0/gtk3}")
  607. requires=("${requires[@]/libgl1/Mesa-libGL1}")
  608. requires=("${requires[@]/libpango-1.0-0/pango}")
  609. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  610. requires=("${requires[@]/libpangox-1.0-0/pango}")
  611. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  612. requires=("${requires[@]/libnss3/mozilla-nss}")
  613. requires=("${requires[@]/libnspr4/mozilla-nspr}")
  614. requires=("${requires[@]/libfribidi0/fribidi}")
  615. requires=("${requires[@]/libfontconfig1/fontconfig}")
  616. requires=("${requires[@]/libfreetype6*/freetype}") # Remove minimum version specifier
  617. requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
  618. for i in "${!requires[@]}"; do
  619. [[ "${requires[$i]}" == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
  620. done
  621. recommends+=(libvulkan_intel)
  622. recommends+=(libvulkan_radeon)
  623. ;;
  624. esac
  625. # Convert array to newline delim'd string (for heredoc)
  626. printf -v requires "Requires: %s\n" "${requires[@]}"
  627. printf -v recommends "Recommends: %s\n" "${recommends[@]}"
  628. # Strip last newline
  629. requires="${requires%?}"
  630. recommends="${recommends%?}"
  631. if (( COMPAT_SWITCH )); then
  632. # Strip minimum versions
  633. requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
  634. fi
  635. # Create spec file
  636. cat <<-EOF > "$OUTPUTDIR/SPECS/mediacenter.spec"
  637. Name: mediacenter$MVERSION
  638. Version: $MCVERSION
  639. Release: 1
  640. Summary: JRiver Media Center
  641. Group: Applications/Media
  642. Source0: http://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb
  643. BuildArch: x86_64
  644. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
  645. AutoReq: 0
  646. $requires
  647. $recommends
  648. Conflicts: MediaCenter
  649. Provides: mediacenter$MVERSION
  650. License: Copyright 1998-2022, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  651. URL: http://www.jriver.com/
  652. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  653. %description
  654. Media Center is more than a world class player.
  655. %global __os_install_post %{nil}
  656. %prep
  657. %build
  658. %install
  659. dpkg -x %{S:0} %{buildroot}
  660. %post -p /sbin/ldconfig
  661. %postun -p /sbin/ldconfig
  662. %files
  663. %{_bindir}/mediacenter$MVERSION
  664. %{_libdir}/jriver
  665. %{_datadir}
  666. %exclude %{_datadir}/applications/media_center_packageinstaller_$MVERSION.desktop
  667. /etc/security/limits.d/*
  668. EOF
  669. # Run rpmbuild
  670. echo "Building MC $MCVERSION RPM, this may take awhile"
  671. rpmbuild_cmd="rpmbuild --define=\"%_topdir $OUTPUTDIR\" --define=\"%_libdir /usr/lib\" -bb"
  672. rpmbuild_cmd+=" $OUTPUTDIR/SPECS/mediacenter.spec"
  673. debug "$rpmbuild_cmd" || rpmbuild_cmd+=" &>/dev/null"
  674. if eval "$rpmbuild_cmd" && [[ -f "$MCRPM" ]] ; then
  675. echo "Build successful. The RPM file is located at: $MCRPM"
  676. else
  677. err "Build failed"
  678. # For automation, let's remove the source DEB and reaquire it on next run
  679. # after failure in case it is corrupted or buggy
  680. [[ -f "$MCDEB" ]] && echo "Removing source DEB" && rm -f "$MCDEB"
  681. exit 1
  682. fi
  683. }
  684. #######################################
  685. # Installs local Media Center DEB package and optional compatability fixes
  686. #######################################
  687. installMCDEB() {
  688. debug "Running: ${FUNCNAME[0]}"
  689. declare pkg_install_cmd="installPackage --skip-check-installed --no-gpg-check --allow-downgrades"
  690. if (( COMPAT_SWITCH )); then
  691. declare extract_dir && extract_dir="$(mktemp -d)"
  692. pushd "$extract_dir" &>/dev/null || return
  693. ar x "$MCDEB"
  694. tar -xJf "control.tar.xz"
  695. # Remove minimum version specifiers from control file
  696. sed -i 's/ ([^)]*)//g' "control"
  697. sed -i 's/([^)]*)//g' "control" # TODO MC DEB package error
  698. [[ "$ID" == "ubuntu" && "${VERSION_ID%.*}" -le 16 ]] &&
  699. sed -i 's/libva2/libva1/g' "control"
  700. tar -cJf "control.tar.xz" "control" "postinst"
  701. declare -g MCDEB="${MCDEB/.deb/.compat.deb}"
  702. ar rcs "$MCDEB" "debian-binary" "control.tar.xz" "data.tar.xz"
  703. popd &>/dev/null || return
  704. rm -rf "$extract_dir"
  705. fi
  706. pkg_install_cmd+=" $MCDEB"
  707. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  708. eval "$pkg_install_cmd"
  709. }
  710. #######################################
  711. # Installs local Media Center RPM package
  712. #######################################
  713. installMCRPM() {
  714. debug "Running: ${FUNCNAME[0]}"
  715. # Install mesa-va-freeworld separately from the RPM for dnf swap
  716. installMesa
  717. installPackage --skip-check-installed --no-gpg-check --allow-downgrades "$MCRPM"
  718. }
  719. #######################################
  720. # Installs mesa-va-drivers-freeworld
  721. #######################################
  722. installMesa() {
  723. debug "Running: ${FUNCNAME[0]}"
  724. # Currently only necessary in Fedora/CentOS
  725. case "$ID" in
  726. fedora|centos)
  727. if ! pkg_query mesa-va-drivers-freeworld &>/dev/null; then
  728. if pkg_query mesa-va-drivers &>/dev/null; then
  729. declare pkg_swap_cmd="pkg_swap mesa-va-drivers mesa-va-drivers-freeworld"
  730. debug "$pkg_swap_cmd" || pkg_swap_cmd+=" &>/dev/null"
  731. if ! eval "$pkg_swap_cmd"; then
  732. err "Package swap failed!"
  733. return 1
  734. fi
  735. else
  736. pkg_install mesa-va-drivers-freeworld
  737. fi
  738. fi
  739. ;;
  740. esac
  741. }
  742. #######################################
  743. # Installs local Media Center PKGBUILD
  744. #######################################
  745. installMCARCH() {
  746. debug "Running: ${FUNCNAME[0]}"
  747. echo "Arch install under construction"
  748. [[ -d "$OUTPUTDIR/PKGBUILD" ]] || mkdir -p "$OUTPUTDIR/PKGBUILD"
  749. cat <<-EOF > "$OUTPUTDIR/PKGBUILD/mediacenter.pkgbuild"
  750. pkgname=mediacenter$MVERSION
  751. pkgver=$MCVERSION
  752. pkgrel=1
  753. pkgdesc="The Most Comprehensive Media Software"
  754. arch=('x86_64')
  755. url="http://www.jriver.com/"
  756. license=('custom')
  757. depends=('alsa-lib' 'gcc-libs' 'libx11' 'libxext' 'libxcb' 'libxau' 'libxdmcp' 'util-linux' 'libxext' 'gtk3')
  758. optdepends=(
  759. 'mesa-libgl: nouveau video support'
  760. 'nvidia-libgl: nvidia video support'
  761. 'nvidia-utils: nvidia vulkan support'
  762. 'vulkan-intel: intel vulkan support'
  763. 'vulkan-radeon: amd vulkan support'
  764. 'vorbis-tools: ogg vorbis support'
  765. 'musepack-tools: musepack support'
  766. )
  767. source=("http://files.jriver.com/mediacenter/channels/v30/latest/MediaCenter-$MCVERSION-amd64.deb")
  768. package() {
  769. cd "\$srcdir"
  770. bsdtar xf data.tar.xz -C "\$pkgdir"
  771. }
  772. EOF
  773. pushd "$OUTPUTDIR/PKGBUILD" &>/dev/null || return
  774. makepkg_cmd="makepkg"
  775. # TODO try to acquire checksums from deb
  776. makepkg_cmd+=" --syncdeps --clean --cleanbuild --skipinteg --force --install --noconfirm"
  777. makepkg_cmd+=" -p mediacenter.pkgbuild"
  778. if ! eval "${makepkg_cmd}"; then
  779. echo "makepkg failed"
  780. exit
  781. fi
  782. popd &>/dev/null || return
  783. }
  784. #######################################
  785. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  786. #######################################
  787. runCreaterepo() {
  788. debug "Running: ${FUNCNAME[0]}"
  789. declare cr_cmd cr_cp_cmd cr_mkdir_cmd cr_chown_cmd
  790. installPackage createrepo_c
  791. # If the webroot does not exist, create it
  792. if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then
  793. cr_mkdir_cmd="sudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT"
  794. debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
  795. if ! eval "$cr_mkdir_cmd"; then
  796. cr_mkdir_cmd="sudo mkdir -p $CREATEREPO_WEBROOT"
  797. debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
  798. cr_chown_cmd="sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
  799. debug "$cr_chown_cmd" || cr_chown_cmd+=" &>/dev/null"
  800. if ! ( eval "$cr_mkdir_cmd" && eval "$cr_chown_cmd" ); then
  801. err "Could not create the createrepo-webroot path!"
  802. err "Make sure that the webroot $CREATEREPO_WEBROOT is writeable by user $CREATEREPO_USER"
  803. err "Or change the repo ownership with --createrepo-user"
  804. return 1
  805. fi
  806. fi
  807. fi
  808. # Copy built rpms to webroot
  809. cr_cp_cmd="sudo cp -nf $MCRPM $CREATEREPO_WEBROOT"
  810. cr_chown_cmd="sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
  811. debug "$cr_cp_cmd" || cr_cp_cmd+=" &>/dev/null"
  812. debug "$cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null"
  813. if ! ( eval "$cr_cp_cmd" && eval "$cr_chown_cmd" ); then
  814. err "Could not copy $MCRPM to $CREATEREPO_WEBROOT"
  815. return 1
  816. fi
  817. # Run createrepo
  818. cr_cmd="sudo -u $CREATEREPO_USER createrepo -q $CREATEREPO_WEBROOT"
  819. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
  820. debug "$cr_cmd" || cr_cmd+=" &>/dev/null"
  821. if ! eval "$cr_cmd"; then
  822. cr_cmd="sudo createrepo -q $CREATEREPO_WEBROOT"
  823. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
  824. cr_chown_cmd="sudo chown -R $CREATEREPO_USER:$CREATEREPO_USER $CREATEREPO_WEBROOT"
  825. debug "$cr_cmd" || cr_cmd+=" &>/dev/null"
  826. debug "$cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null"
  827. if ! ( eval "$cr_cmd" && eval "$cr_chown_cmd"); then
  828. err "Createrepo failed"
  829. return 1
  830. fi
  831. fi
  832. }
  833. #######################################
  834. # Symlink certificates if they do not exist in default location
  835. #######################################
  836. symlinkCerts() {
  837. debug "Running: ${FUNCNAME[0]}"
  838. declare mc_cert_link="/usr/lib/jriver/Media Center $MVERSION/ca-certificates.crt"
  839. declare target_cert ln_cmd
  840. target_cert=$(readlink -f "$mc_cert_link")
  841. [[ -f $target_cert ]] && return 0
  842. # Have to use command array instead of eval because of whitespace in $mc_cert_link
  843. if [[ -f /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ]]; then
  844. ln_cmd="sudo ln -fs /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem \"$mc_cert_link\"" # For RHEL
  845. elif [[ -f /var/lib/ca-certificates/ca-bundle.pem ]]; then
  846. ln_cmd="sudo ln -fs /var/lib/ca-certificates/ca-bundle.pem \"$mc_cert_link\"" # For SUSE
  847. fi
  848. debug "$ln_cmd" || ln_cmd+=" &>/dev/null"
  849. if ! eval "$ln_cmd"; then
  850. err "Symlinking certificates failed"
  851. return 1
  852. fi
  853. }
  854. #######################################
  855. # Restore the mjr license file if it is next to installJRMC or RESTOREFILE is set
  856. #######################################
  857. restoreLicense() {
  858. debug "Running: ${FUNCNAME[0]}"
  859. declare mjrfile
  860. # Allow user to put the mjr file next to installJRMC
  861. if [[ ! -v RESTOREFILE ]]; then
  862. for mjrfile in "$PWD"/*.mjr; do
  863. [[ $mjrfile -nt $RESTOREFILE ]] && RESTOREFILE="$mjrfile"
  864. done
  865. fi
  866. # Restore license
  867. if [[ -f "$RESTOREFILE" ]]; then
  868. if ! "mediacenter$MVERSION" /RestoreFromFile "$RESTOREFILE"; then
  869. err "Automatic license restore failed"
  870. return 1
  871. fi
  872. fi
  873. }
  874. #######################################
  875. # Opens ports using the system firewall tool
  876. # Arguments:
  877. # Pre-defined service to enable
  878. #######################################
  879. openFirewall() {
  880. debug "Running: ${FUNCNAME[0]}" "$@"
  881. # Create OS-specific port rules based on argument (service) name
  882. declare -a f_ports # for firewall-cmd
  883. declare u_ports # for ufw
  884. #declare -a n_ports # for nftables
  885. declare port
  886. if [[ "$1" == "jriver-mediacenter" ]]; then
  887. f_ports=(52100-52200/tcp 1900/udp)
  888. u_ports="52100:52200/tcp|1900/udp"
  889. #n_ports=("tcp dport 52100-52200 accept" "udp dport 1900 accept")
  890. elif [[ "$1" =~ ^(jriver-x11vnc|jriver-xvnc)$ ]]; then
  891. f_ports=("$PORT"/tcp 1900/udp)
  892. u_ports="$PORT/tcp|1900/udp"
  893. #n_ports=("tcp dport $PORT accept" "udp dport 1900 accept")
  894. fi
  895. # Open the ports
  896. if ! case "$ID" in
  897. fedora|centos|suse)
  898. hash firewall-cmd 2>/dev/null || installPackage firewalld
  899. if ! firewall_cmd --get-services | grep -q "$1"; then
  900. firewall_cmd --permanent --new-service="$1" &>/dev/null
  901. firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" &>/dev/null
  902. firewall_cmd --permanent --service="$1" --set-short="$1" &>/dev/null
  903. for port in "${f_ports[@]}"; do
  904. firewall_cmd --permanent --service="$1" --add-port="$port" &>/dev/null
  905. done
  906. firewall_cmd --add-service "$1" --permanent &>/dev/null
  907. firewall_cmd --reload &>/dev/null
  908. fi
  909. ;;
  910. debian|ubuntu)
  911. # Debian ufw package state is broken on fresh installations
  912. hash ufw 2>/dev/null || installPackage ufw
  913. if [[ ! -f "/etc/ufw/applications.d/$1" ]]; then
  914. sudo bash -c "cat <<-EOF > /etc/ufw/applications.d/$1
  915. [$1]
  916. title=$1
  917. description=$1 installed by installJRMC
  918. ports=$u_ports
  919. EOF"
  920. fi
  921. firewall_cmd app update "$1" &>/dev/null
  922. firewall_cmd allow "$1" &>/dev/null
  923. ;;
  924. arch)
  925. # sysctl -w net.ipv4.ip_forward = 1
  926. # sudo nft create table inet "jriver"
  927. # sudo nft create chain inet "jriver" "$1" '{ type filter hook input priority 0; policy accept; }'
  928. # for port in "${n_ports[@]}"; do
  929. # sudo nft add rule inet jriver "$1" handle tcp dport "$port"
  930. # done
  931. ;;
  932. esac; then
  933. err "Firewall ports could not be opened"
  934. return 1
  935. fi
  936. }
  937. #######################################
  938. # Create the xvnc or x11vnc password file
  939. # Arguments:
  940. # Service type (xvnc, x11vnc)
  941. #######################################
  942. setVNCPass() {
  943. debug "Running: ${FUNCNAME[0]}"
  944. declare vncpassfile="$HOME/.vnc/jrmc_passwd"
  945. declare vnc_pass_cmd
  946. [[ ! -d "${vncpassfile%/*}" ]] && mkdir -p "${vncpassfile%/*}"
  947. if [[ -f "$vncpassfile" ]]; then
  948. if [[ ! -v VNCPASS ]]; then
  949. err "Refusing to overwrite existing $vncpassfile with an empty password"
  950. err "Remove existing $vncpassfile or set --vncpass to use an empty password"
  951. exit 1
  952. else
  953. rm -f "$vncpassfile"
  954. fi
  955. fi
  956. if [[ -v VNCPASS ]]; then
  957. if [[ $1 == "xvnc" ]]; then
  958. vnc_pass_cmd="echo $VNCPASS | vncpasswd -f > $vncpassfile"
  959. elif [[ $1 == "x11vnc" ]]; then
  960. vnc_pass_cmd="x11vnc -storepasswd $VNCPASS $vncpassfile"
  961. fi
  962. if ! eval "$vnc_pass_cmd"; then
  963. err "Could not create VNC password file"
  964. return 1
  965. fi
  966. else
  967. declare -g NOVNCAUTH=1
  968. fi
  969. }
  970. #######################################
  971. # Set display and port variables
  972. #######################################
  973. setDisplay() {
  974. debug "Running: ${FUNCNAME[0]}"
  975. declare -g DISPLAY DISPLAYNUM NEXT_DISPLAY NEXT_DISPLAYNUM
  976. # Check USER_DISPLAY, else environment DISPLAY, else set to :0 by default
  977. DISPLAY="${USER_DISPLAY:-${DISPLAY:-0}}"
  978. DISPLAYNUM="${DISPLAY#*:}" # strip prefix
  979. DISPLAYNUM="${DISPLAYNUM%%.*}" # strip suffix
  980. NEXT_DISPLAYNUM=$(( DISPLAYNUM + 1 ))
  981. NEXT_DISPLAY=":$NEXT_DISPLAYNUM"
  982. }
  983. #######################################
  984. # Create associated service variables based on service name
  985. # Arguments
  986. # Pre-defined service name
  987. #######################################
  988. setServiceVars() {
  989. debug "Running: ${FUNCNAME[0]}"
  990. declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME USER_STRING DISPLAY_STRING GRAPHICAL_TARGET
  991. declare -g SERVICE_TYPE="${SERVICE_TYPE:-system}"
  992. declare service_dir="/usr/lib/systemd/$SERVICE_TYPE"
  993. if [[ "$USER" == "root" && "$SERVICE_TYPE" == "user" ]]; then
  994. err "Trying to install user service as root"
  995. err "Use --service-type service and/or execute installJRMC as non-root user"
  996. return 1
  997. fi
  998. if [[ "$SERVICE_TYPE" == "system" ]]; then
  999. systemctl_reload_cmd(){ sudo systemctl daemon-reload; }
  1000. systemctl_enable_cmd(){ sudo systemctl enable --now "$@"; }
  1001. systemctl_disable_cmd(){ sudo systemctl disable --now "$@"; }
  1002. systemctl_is_enabled_cmd(){ sudo systemctl is-enabled -q "$@"; }
  1003. systemctl_is_active_cmd(){ sudo systemctl is-active -q "$@"; }
  1004. GRAPHICAL_TARGET="graphical.target"
  1005. elif [[ "$SERVICE_TYPE" == "user" ]]; then
  1006. systemctl_reload_cmd(){ systemctl --user daemon-reload; }
  1007. systemctl_enable_cmd(){ systemctl --user enable --now "$@"; }
  1008. systemctl_disable_cmd(){ systemctl --user disable --now "$@"; }
  1009. systemctl_is_enabled_cmd(){ systemctl --user is-enabled -q "$@"; }
  1010. systemctl_is_active_cmd(){ systemctl --user is-active -q "$@"; }
  1011. GRAPHICAL_TARGET="default.target"
  1012. fi
  1013. [[ ! -d "$service_dir" ]] && sudo mkdir -p "$service_dir"
  1014. # TODO Ubuntu needs these in the service file, fedora (and others?) does not
  1015. case "$ID" in
  1016. ubuntu|debian)
  1017. DISPLAY_STRING="Environment=DISPLAY=$DISPLAY"
  1018. DISPLAY_STRING+=$'\n'"Environment=XAUTHORITY=$XAUTHORITY"
  1019. ;;
  1020. *)
  1021. DISPLAY_STRING=""
  1022. ;;
  1023. esac
  1024. if [[ "$SERVICE_TYPE" == "system" && "$USER" != "root" ]]; then
  1025. SERVICE_FNAME="$service_dir/${1}@.service"
  1026. TIMER_FNAME="$service_dir/${1}@.timer"
  1027. SERVICE_NAME="${1}@$USER.service"
  1028. TIMER_NAME="${1}@$USER.timer"
  1029. USER_STRING="User=%I"
  1030. else
  1031. SERVICE_NAME="${1}.service"
  1032. TIMER_NAME="${1}.timer"
  1033. SERVICE_FNAME="$service_dir/${SERVICE_NAME}"
  1034. TIMER_FNAME="$service_dir/${TIMER_NAME}"
  1035. USER_STRING=""
  1036. fi
  1037. }
  1038. #######################################
  1039. # Starts and enables (at startup) a JRiver Media Center service
  1040. # Arguments:
  1041. # Passes arguments as startup options to /usr/bin/mediacenter??
  1042. #######################################
  1043. service_jriver-mediacenter() {
  1044. debug "Running: ${FUNCNAME[0]}"
  1045. setServiceVars "${FUNCNAME[0]##*_}"
  1046. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1047. [Unit]
  1048. Description=JRiver Media Center $MVERSION
  1049. After=$GRAPHICAL_TARGET
  1050. [Service]
  1051. $USER_STRING
  1052. $DISPLAY_STRING
  1053. Type=simple
  1054. Environment=DISPLAY=$DISPLAY
  1055. Environment=XAUTHORITY=$XAUTHORITY
  1056. ExecStart=/usr/bin/mediacenter$MVERSION $*
  1057. Restart=always
  1058. RestartSec=10
  1059. KillSignal=SIGHUP
  1060. TimeoutStopSec=30
  1061. [Install]
  1062. WantedBy=$GRAPHICAL_TARGET
  1063. EOF"
  1064. systemctl_reload_cmd &&
  1065. systemctl_enable_cmd "$SERVICE_NAME" &&
  1066. openFirewall "jriver-mediacenter"
  1067. }
  1068. #######################################
  1069. # Starts and enables (at startup) a JRiver Media Server service
  1070. #######################################
  1071. service_jriver-mediaserver() {
  1072. debug "Running: ${FUNCNAME[0]}"
  1073. setServiceVars "${FUNCNAME[0]##*_}"
  1074. service_jriver-mediacenter "/MediaServer"
  1075. }
  1076. #######################################
  1077. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  1078. #######################################
  1079. service_jriver-xvnc() {
  1080. debug "Running: ${FUNCNAME[0]}"
  1081. setServiceVars "${FUNCNAME[0]##*_}"
  1082. setDisplay
  1083. declare start_cmd
  1084. declare -g PORT=$(( NEXT_DISPLAYNUM + 5900 ))
  1085. installPackage tigervnc-server
  1086. setVNCPass xvnc
  1087. if (( NOVNCAUTH )); then
  1088. start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -name jriver$NEXT_DISPLAY -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$MVERSION"
  1089. else
  1090. start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$MVERSION"
  1091. fi
  1092. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1093. [Unit]
  1094. Description=Remote desktop service (VNC)
  1095. After=multi-user.target
  1096. [Service]
  1097. Type=forking
  1098. $USER_STRING
  1099. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
  1100. ExecStart=$start_cmd
  1101. ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
  1102. Restart=always
  1103. [Install]
  1104. WantedBy=multi-user.target
  1105. EOF"
  1106. systemctl_reload_cmd &&
  1107. systemctl_enable_cmd "$SERVICE_NAME" &&
  1108. echo "Xvnc running on localhost:$PORT" &&
  1109. openFirewall "jriver-xvnc" &&
  1110. openFirewall "jriver-mediacenter"
  1111. }
  1112. #######################################
  1113. # Starts and enables (at startup) x11vnc screen sharing for the local desktop
  1114. #######################################
  1115. service_jriver-x11vnc() {
  1116. debug "Running: ${FUNCNAME[0]}"
  1117. setServiceVars "${FUNCNAME[0]##*_}"
  1118. setDisplay
  1119. declare start_cmd
  1120. declare -g PORT=$(( DISPLAYNUM + 5900 ))
  1121. installPackage x11vnc
  1122. setVNCPass x11vnc
  1123. # If .Xauthority file is missing, generate a dummy for x11vnc -auth guess
  1124. if [[ ! -f "$HOME/.Xauthority" ]]; then
  1125. [[ "$XDG_SESSION_TYPE" == "wayland" ]] && ask_ok "Unsupported Wayland session detected for x11vnc, continue?" || return 1
  1126. touch "$HOME/.Xauthority"
  1127. xauth generate "$DISPLAY" . trusted
  1128. xauth add "$HOST$DISPLAY" . "$(xxd -l 16 -p /dev/urandom)"
  1129. fi
  1130. if (( NOVNCAUTH )); then
  1131. start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -nopw"
  1132. else
  1133. start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd"
  1134. fi
  1135. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1136. [Unit]
  1137. Description=x11vnc
  1138. After=$GRAPHICAL_TARGET
  1139. [Service]
  1140. $USER_STRING
  1141. Type=forking
  1142. Environment=DISPLAY=$DISPLAY
  1143. ExecStart=$start_cmd
  1144. Restart=always
  1145. RestartSec=10
  1146. [Install]
  1147. WantedBy=$GRAPHICAL_TARGET
  1148. EOF"
  1149. systemctl_reload_cmd &&
  1150. systemctl_enable_cmd "$SERVICE_NAME" &&
  1151. echo "x11vnc running on localhost:$PORT" &&
  1152. openFirewall "jriver-x11vnc"
  1153. }
  1154. #######################################
  1155. # Starts and enables (at startup) an hourly service to build the latest version of JRiver Media
  1156. # Center RPM from the source DEB and create/update an RPM repository
  1157. #######################################
  1158. service_jriver-createrepo() {
  1159. debug "Running: ${FUNCNAME[0]}"
  1160. if [[ "$CREATEREPO_USER" != "$USER" ]]; then
  1161. USER="root" SERVICE_TYPE="system" setServiceVars "${FUNCNAME[0]##*_}"
  1162. else
  1163. setServiceVars "${FUNCNAME[0]##*_}"
  1164. fi
  1165. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1166. [Unit]
  1167. Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo
  1168. [Service]
  1169. $USER_STRING
  1170. ExecStart=$PWD/installJRMC --outputdir $OUTPUTDIR --createrepo=$TARGET --createrepo-webroot $CREATEREPO_WEBROOT --createrepo-user $CREATEREPO_USER
  1171. [Install]
  1172. WantedBy=multi-user.target
  1173. EOF"
  1174. sudo bash -c "cat <<-EOF > $TIMER_FNAME
  1175. [Unit]
  1176. Description=Run JRiver MC rpmbuild hourly
  1177. [Timer]
  1178. OnCalendar=hourly
  1179. Persistent=true
  1180. [Install]
  1181. WantedBy=timers.target
  1182. EOF"
  1183. systemctl_reload_cmd &&
  1184. systemctl_enable_cmd "$TIMER_NAME"
  1185. }
  1186. #######################################
  1187. # CONTAINERS
  1188. #######################################
  1189. # container_jriver-createrepo() {
  1190. # :
  1191. # }
  1192. # container_jriver-xvnc() {
  1193. # :
  1194. # }
  1195. # container_jriver-mediacenter() {
  1196. # installPackage buildah podman
  1197. # # Eventually try to switch to Debian
  1198. # # if ! CNT=$(buildah from debian:$DEBIANBASE); then
  1199. # # echo "Bad base image for container $CNAME, skipping"
  1200. # # continue
  1201. # # fi
  1202. # if ! CNT=$(buildah from jlesage/baseimage-gui:debian-10-v3.5.7); then
  1203. # echo "Bad base image for container $CNAME, skipping"
  1204. # continue
  1205. # fi
  1206. # buildah run "$CNT" add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg
  1207. # # #BASEIMAGE=jlesage/baseimage-gui:debian-10-v3.5.7
  1208. # # JRIVER_RELEASE=28
  1209. # # JRIVER_TAG=stable
  1210. # # ARCH=amd64
  1211. # # REBUILD_MIN=22
  1212. # # REBUILD_MAX=120
  1213. # # # JRiver Version tag (latest, stable or beta)
  1214. # # ARG jriver_tag
  1215. # # # JRiver Release Version (25, 26 etc.)
  1216. # # ARG jriver_release
  1217. # # # Image Version of the build
  1218. # # ARG image_version
  1219. # # # .deb download URL, if set to "repository" the JRiver repository will be used
  1220. # # ARG deb_url
  1221. # # RUN add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg
  1222. # # Install JRiver
  1223. # RUN \
  1224. # add-pkg --virtual build-dependencies wget &&
  1225. # # Install from Repository
  1226. # if [ "${deb_url}" = "repository" ]; then \
  1227. # echo "Installing JRiver from repository ${jriver_release}:${jriver_tag}" &&
  1228. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &&
  1229. # wget http://dist.jriver.com/${jriver_tag}/mediacenter/mediacenter${jriver_release}.list -O /etc/apt/sources.list.d/mediacenter${jriver_release}.list &&
  1230. # apt update &&
  1231. # add-pkg mediacenter${jriver_release}; \
  1232. # # Install from .deb URL
  1233. # else \
  1234. # echo "Installing JRiver from URL: ${deb_url}" &&
  1235. # wget -q -O "jrivermc.deb" ${deb_url} &&
  1236. # add-pkg "./jrivermc.deb"; \
  1237. # fi &&
  1238. # # Cleanup
  1239. # del-pkg build-dependencies &&
  1240. # rm -rf /tmp/* /tmp/.[!.]*
  1241. # # Add rootfs
  1242. # COPY rootfs/ /
  1243. # VOLUME ["/config"]
  1244. # # Application Icon
  1245. # RUN \
  1246. # APP_ICON_URL=https://gitlab.com/shiomax/jrivermc-docker/raw/master/assets/Application.png &&
  1247. # install_app_icon.sh "$APP_ICON_URL"
  1248. # # Various configuration vars
  1249. # ENV KEEP_APP_RUNNING=1 \
  1250. # DISPLAY_WIDTH=1280 \
  1251. # DISPLAY_HEIGHT=768 \
  1252. # APP_NAME="JRiver MediaCenter ${jriver_release}" \
  1253. # MAXIMIZE_POPUPS=0 \
  1254. # S6_KILL_GRACETIME=8000
  1255. # # Modify startapp.sh and rc.xml with JRiver version
  1256. # RUN sed-patch s/%%MC_VERSION%%/${jriver_release}/g \
  1257. # /startapp.sh &&
  1258. # sed-patch s/%%MC_VERSION%%/${jriver_release}/g \
  1259. # /etc/xdg/openbox/rc.xml
  1260. # EXPOSE 5800 5900 52100 52101 52199 1900/udp
  1261. # # Metadata.
  1262. # LABEL \
  1263. # org.label-schema.name="jrivermc${jriver_release}" \
  1264. # org.label-schema.description="Docker image for JRiver Media Center ${jriver_release}" \
  1265. # org.label-schema.version="${image_version}" \
  1266. # org.label-schema.vcs-url="https://gitlab.com/shiomax/jrivermc-docker" \
  1267. # org.label-schema.schema-version="1.0"
  1268. # installPackage buildah podman
  1269. # cnt=$(buildah from docker.io/jlesage/baseimage-gui:debian-10)
  1270. # podman_create_cmd=(podman create --name "$CNAME")
  1271. # buildah_config_cmd=(buildah config \
  1272. # --author bryanroessler@gmail.com \
  1273. # --label maintainer="$MAINTAINER" \
  1274. # --env TZ="$TZ" \
  1275. # --workingdir /app \
  1276. # --cmd mediacenter"$MVERSION")
  1277. # mkcdirs() {
  1278. # declare dir
  1279. # for dir in "$@"; do
  1280. # if [[ ! -d "$dir" ]]; then
  1281. # if ! mkdir -p "$dir"; then
  1282. # err "Could not create directory $dir, check your permissions"
  1283. # fi
  1284. # fi
  1285. # if ! chcon -t container_file_t -R "$dir"; then
  1286. # err "Could not set container_file_t attribute for $dir, check your permissions"
  1287. # fi
  1288. # done
  1289. # }
  1290. # mkcdirs "$HOME/.jriver"
  1291. # podman_create_cmd+=(-v "$HOME/.jriver:/root/.jriver")
  1292. # podman_create_cmd+=(-v "$DOWNLOAD_ROOT:/downloads:z")
  1293. # podman_create_cmd+=(-v "$MONITOR_ROOT/nzbs:/nzbs")
  1294. # podman_create_cmd+=(-p "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1295. # brc() { buildah run "$1" "${@:2}" || return 1; }
  1296. # brc add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1
  1297. # brc add-pkg --virtual .build-deps wget
  1298. # brc sh -s <<-EOF
  1299. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &>/dev/null
  1300. # EOF
  1301. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list"
  1302. # brc apt update -y -q0
  1303. # brc add-pkg "mediacenter$MVERSION"
  1304. # brc del-pkg .build-deps
  1305. # }
  1306. #######################################
  1307. # Detects if MC is installed on btrfs and disables CoW
  1308. #######################################
  1309. disableCoW() {
  1310. debug "Running: ${FUNCNAME[0]}"
  1311. declare dir
  1312. declare mc_system_path="/usr/lib/jriver"
  1313. declare mc_user_path="$HOME/.jriver"
  1314. [[ -d "$mc_user_path" ]] || mkdir -p "$mc_user_path"
  1315. for dir in "$mc_system_path" "$mc_user_path"; do
  1316. [[ -d "$dir" ]] || return
  1317. if [[ $(stat -f -c %T "$dir") == "btrfs" ]] &&
  1318. ! lsattr -d "$dir" | cut -f1 -d" " | grep -q C; then
  1319. echo "Disabling CoW for $dir"
  1320. sudo chattr +C "$dir"
  1321. fi
  1322. done
  1323. }
  1324. #######################################
  1325. # Migrate major versions
  1326. #######################################
  1327. migrateLibrary() {
  1328. debug "Running: ${FUNCNAME[0]}"
  1329. declare mc_user_path="$HOME/.jriver"
  1330. declare current_config_path="$mc_user_path/Media Center $MVERSION"
  1331. declare previous_config_path="$mc_user_path/Media Center $(( MVERSION - 1 ))"
  1332. if [[ ! -d "$current_config_path" ]] &&
  1333. [[ -d "$previous_config_path" ]] &&
  1334. mkdir -p "$current_config_path"; then
  1335. echo "Migrating $previous_config_path to $current_config_path"
  1336. cp -fa "$previous_config_path"/* "$current_config_path" &>/dev/null
  1337. fi
  1338. }
  1339. #######################################
  1340. # Completely uninstalls MC, services, and firewall rules
  1341. #######################################
  1342. uninstall() {
  1343. debug "Running: ${FUNCNAME[0]}"
  1344. declare service unit f i
  1345. echo "Stopping and removing all Media Center services"
  1346. for service in $(compgen -A "function" "service"); do
  1347. service="${service##service_}"
  1348. for i in user system; do
  1349. SERVICE_TYPE="$i" setServiceVars "$service";
  1350. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1351. if systemctl_is_active_cmd "$unit" &>/dev/null ||
  1352. systemctl_is_enabled_cmd "$unit" &>/dev/null; then
  1353. debug "Disabling $unit"
  1354. systemctl_disable_cmd "$unit"
  1355. fi
  1356. done
  1357. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1358. [[ -f "$f" ]] && debug "Removing $f" && sudo rm -f "$f"
  1359. done
  1360. systemctl_reload_cmd
  1361. done
  1362. for f in /etc/systemd/system/jriver-*; do
  1363. sudo rm -f "$f"
  1364. done
  1365. done
  1366. echo "Removing repo files"
  1367. sudo rm -rf \
  1368. "/etc/yum.repos.d/jriver.repo" \
  1369. /etc/apt/sources.list.d/{jriver,mediacenter}*.list # also remove legacy repo files
  1370. if [[ "$ID" == "suse" ]]; then
  1371. sudo zypper rr jriver &>/dev/null
  1372. fi
  1373. echo "Removing firewall rules"
  1374. if hash firewall-cmd 2>/dev/null; then
  1375. if [[ -v debug ]]; then
  1376. debug "firewall_cmd --permanent --remove-service=jriver"
  1377. firewall_cmd --permanent --remove-service=jriver
  1378. debug "firewall_cmd --permanent --delete-service=jriver"
  1379. firewall_cmd --permanent --delete-service=jriver
  1380. debug "firewall_cmd --reload"
  1381. firewall_cmd --reload
  1382. else
  1383. firewall_cmd --permanent --remove-service=jriver &>/dev/null
  1384. firewall_cmd --permanent --delete-service=jriver &>/dev/null
  1385. firewall_cmd --reload &>/dev/null
  1386. fi
  1387. elif hash ufw 2>/dev/null; then
  1388. firewall_cmd="firewall_cmd delete allow jriver"
  1389. debug "$firewall_cmd" || firewall_cmd+=" &>/dev/null"
  1390. eval "$firewall_cmd"
  1391. [[ -f "/etc/ufw/applications.d/jriver" ]] &&
  1392. sudo rm -f /etc/ufw/applications.d/jriver
  1393. # elif hash nft 2>/dev/null; then
  1394. # sudo nft delete table inet jriver
  1395. fi
  1396. echo "Uninstalling JRiver Media Center package"
  1397. mc_pkg_rm_cmd="pkg_remove $MCPKG"
  1398. debug "$mc_pkg_rm_cmd" || mc_pkg_rm_cmd+=" &>/dev/null"
  1399. if eval "$mc_pkg_rm_cmd"; then
  1400. echo "JRiver Media Center has been completely uninstalled"
  1401. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1402. elif [[ $? -eq 100 ]]; then
  1403. err "JRiver Media Center package '$MCPKG' is not present and was not uninstalled"
  1404. else
  1405. err "Could not remove Media Center package"
  1406. fi
  1407. }
  1408. tests() {
  1409. # To test on Mint/16.04: sudo apt install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1410. : # TODO
  1411. }
  1412. main() {
  1413. debug "Running: ${FUNCNAME[0]} $*"
  1414. init
  1415. parseInput "$@"
  1416. if (( DEBUG )); then
  1417. echo "Debugging on"
  1418. echo "installJRMC version: $SCRIPTVERSION"
  1419. fi
  1420. if ((TEST_SWITCH)); then
  1421. echo "Running tests, all other options are skipped"
  1422. tests
  1423. exit
  1424. fi
  1425. setMCVersion
  1426. if (( UNINSTALL_SWITCH )); then
  1427. if askOk "Do you really want to uninstall JRiver Media Center?"; then
  1428. uninstall
  1429. else
  1430. echo "Uninstall canceled."
  1431. fi
  1432. exit
  1433. fi
  1434. # Install external repos
  1435. case "$ID" in
  1436. ubuntu)
  1437. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  1438. echo "Adding universe repository"
  1439. declare add_universe_cmd="sudo add-apt-repository -y universe"
  1440. debug "$add_universe_cmd" || add_universe_cmd+=" &>/dev/null"
  1441. if ! eval "$add_universe_cmd"; then
  1442. err "Adding universe repository failed"
  1443. fi
  1444. fi
  1445. ;;
  1446. centos)
  1447. if ! hash dpkg &>/dev/null; then
  1448. echo "Adding EPEL repository"
  1449. installPackage epel-release
  1450. fi
  1451. if ! pkg_query rpmfusion-free-release &>/dev/null; then
  1452. installPackage --skip-check-installed \
  1453. "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1454. fi
  1455. ;;
  1456. fedora)
  1457. if ! pkg_query rpmfusion-free-release &>/dev/null; then
  1458. installPackage --skip-check-installed \
  1459. "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1460. fi
  1461. ;;
  1462. esac
  1463. if (( REPO_INSTALL_SWITCH )); then
  1464. echo "Installing JRiver Media Center from remote repository"
  1465. if installMCFromRepo; then
  1466. echo "JRiver Media Center installed successfully from repo"
  1467. symlinkCerts
  1468. migrateLibrary
  1469. restoreLicense
  1470. openFirewall "jriver-mediacenter"
  1471. disableCoW
  1472. else
  1473. err "JRiver Media Center installation from repo failed"
  1474. return 1
  1475. fi
  1476. fi
  1477. if (( BUILD_SWITCH )) && [[ $ID != "arch" ]]; then
  1478. installPackage "wget"
  1479. acquireDeb
  1480. if [[ "$TARGET" =~ (centos|fedora|suse) ]]; then
  1481. installPackage "dpkg" "rpm-build"
  1482. buildRPM
  1483. fi
  1484. fi
  1485. if (( LOCAL_INSTALL_SWITCH )); then
  1486. if pkg_install_local; then
  1487. echo "JRiver Media Center installed successfully from local package"
  1488. else
  1489. err "JRiver Media Center local package installation failed"
  1490. return 1
  1491. fi
  1492. symlinkCerts
  1493. migrateLibrary
  1494. restoreLicense
  1495. openFirewall "jriver-mediacenter"
  1496. disableCoW
  1497. fi
  1498. if (( CREATEREPO_SWITCH )); then
  1499. if runCreaterepo; then
  1500. echo "Successfully updated repo"
  1501. else
  1502. err "Repo creation failed"
  1503. fi
  1504. fi
  1505. if [[ "${#SERVICES[@]}" -gt 0 ]]; then
  1506. declare service
  1507. for service in "${SERVICES[@]}"; do
  1508. if ! "service_$service"; then
  1509. if [[ $? -eq 127 ]]; then
  1510. err "Service $service does not exist, check your service name"
  1511. else
  1512. err "Failed to create service: $service"
  1513. fi
  1514. fi
  1515. done
  1516. fi
  1517. # for _container in "${CONTAINERS[@]}"; do
  1518. # if ! "_container_$_container"; then
  1519. # if [[ $? -eq 127 ]]; then
  1520. # err "Container $_container does not exist, check your container name"
  1521. # else
  1522. # err "Failed to create container: $_container"
  1523. # fi
  1524. # fi
  1525. # done
  1526. }
  1527. # Quickly turn debugging on, also use getopt in parseInput()
  1528. [[ " $* " =~ ( --debug | -d ) ]] && DEBUG=1
  1529. main "$@"