installJRMC 59 KB

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