Advertisement
Guest User

Untitled

a guest
Oct 14th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 60.90 KB | None | 0 0
  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 (v1.1)
  10. # 1. Interactive mode
  11. # 2. Additional containerization (createrepo and rpmbuild)
  12. # 3. Tests
  13. #
  14. # BUGS
  15. # 1. No createrepo on Mint
  16.  
  17. shopt -s extglob
  18.  
  19. declare -g SCRIPTVERSION="1.0-rc11"
  20. declare -g BOARDURL="https://yabb.jriver.com/interact/index.php/board,80.0.html" # MC31
  21. declare -g DEBIANBASE="bullseye"
  22. declare -g MC_VERSION_HARDCODE="31.0.43" # Do find all replace
  23.  
  24. printHelp() {
  25. debug "Running: ${FUNCNAME[0]}"
  26.  
  27. cat <<-EOF
  28. USAGE:
  29. installJRMC [[OPTION] [VALUE]]...
  30.  
  31. If no options (excluding -d or --debug) are provided installJRMC defaults to '--install repo'.
  32.  
  33. OPTIONS
  34. --install, -i repo|local
  35. repo: Install MC from repository, updates are handled by the system package manager
  36. local: Build and install MC package locally from official source release
  37. --build[=suse|fedora|centos]
  38. Build RPM from source DEB but do not install
  39. Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
  40. --compat
  41. Build/install MC locally without minimum dependency version requirements
  42. --mcversion VERSION
  43. Specify the MC version, ex. "$MC_VERSION_HARDCODE" (default: latest version)
  44. --arch VERSION
  45. Specify the MC architecture, ex. "amd64", "arm64", etc (default: host architecture)
  46. --outputdir PATH
  47. Generate rpmbuild output in this directory (default: ./output)
  48. --restorefile RESTOREFILE
  49. Restore file location for automatic license registration
  50. --betapass PASSWORD
  51. Enter beta team password for access to beta builds
  52. --service, -s SERVICE
  53. See SERVICES section below for a list of possible services to install
  54. --service-type user|system
  55. Starts services at boot (system) or at user login (user) (default: per service, see SERVICES)
  56. --container, -c CONTAINER (TODO: Under construction)
  57. See CONTAINERS section below for a list of possible services to install
  58. --createrepo[=suse|fedora|centos]
  59. Build rpm, copy to webroot, and run createrepo.
  60. Use in conjunction with --build=TARGET for crossbuilding repos
  61. Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
  62. --createrepo-webroot PATH
  63. Specify the webroot directory to install the repo (default: /var/www/jriver)
  64. --createrepo-user USER
  65. Specify the web server user if it differs from \$USER
  66. --uninstall, -u
  67. Uninstall JRiver MC, remove services, containers, and firewall rules (does not remove library files)
  68. --yes, -y, --auto
  69. Always assume yes for questions
  70. --version, -v
  71. Print this script version and exit
  72. --debug, -d
  73. Print debug output
  74. --help, -h
  75. Print help dialog and exit
  76.  
  77. SERVICES
  78. jriver-mediaserver (default --service-type=user)
  79. Enable and start a mediaserver systemd service (requires an existing X server)
  80. jriver-mediacenter (user)
  81. Enable and start a mediacenter systemd service (requires an existing X server)
  82. jriver-x11vnc (user)
  83. Enable and start x11vnc for the local desktop (requires an existing X server)
  84. Usually combined with jriver-mediaserver or jriver-mediacenter services
  85. --vncpass and --display are optional (see below)
  86. jriver-xvnc (system)
  87. Enable and start a new Xvnc session running JRiver Media Center
  88. --vncpass PASSWORD
  89. Set the vnc password for x11vnc/Xvnc access. If no password is set, installJRMC
  90. will either use existing password stored in \$HOME/.vnc/jrmc_passwd or use no password
  91. --display DISPLAY
  92. Display to use for x11vnc/Xvnc (default: The current display (x11vnc) or the
  93. current display incremented by 1 (Xvnc))
  94. jriver-createrepo (system)
  95. Install hourly service to build latest MC RPM and run createrepo
  96.  
  97. CONTAINERS (TODO: Under construction)
  98. mediacenter-xvnc
  99. createrepo
  100. EOF
  101. }
  102.  
  103. #######################################
  104. # Helpers
  105. #######################################
  106. debug() { (( DEBUG )) && echo "Debug: $*"; }
  107. err() { echo "Error: $*" >&2; }
  108. askOk() {
  109. declare response
  110. (( YES_SWITCH )) && return 0
  111. read -r -p "$* [y/N]: " response
  112. [[ ${response,,} =~ ^(yes|y)$ ]]
  113. }
  114. execute() {
  115. if debug "$*"; then
  116. "$@"
  117. else
  118. "$@" &>/dev/null
  119. fi
  120. }
  121.  
  122.  
  123. #######################################
  124. # Perform OS detection and fallback
  125. # Generate OS-specific functions
  126. #######################################
  127. init() {
  128. debug "Running: ${FUNCNAME[0]}"
  129.  
  130. declare -g ID RPM_MGR ARCH
  131. declare -ga PKG_INSTALL PKG_REMOVE PKG_UPDATE PKG_QUERY
  132.  
  133. echo "Starting installJRMC"
  134. (( DEBUG )) || echo "To enable debugging output, use --debug or -d"
  135.  
  136. if [[ -e /etc/os-release ]]; then
  137. source "/etc/os-release"
  138. else
  139. err "/etc/os-release not found"
  140. err "Your OS is unsupported"
  141. printHelp
  142. exit 1
  143. fi
  144.  
  145. # Detect architecture and translate to MC convention
  146. # Override with user input with getopt
  147. ARCH=$(uname -m)
  148. case $ARCH in
  149. x86_64)
  150. ARCH="amd64"
  151. ;;
  152. aarch64)
  153. ARCH="arm64"
  154. ;;
  155. esac
  156.  
  157. debug "Detected host platform: $ID $VERSION_ID $ARCH"
  158.  
  159. # normalize ID and set distro-specific vars
  160. case $ID in
  161. debian|arch)
  162. ;;
  163. centos|fedora)
  164. if hash dnf &>/dev/null; then
  165. RPM_MGR="dnf"
  166. elif hash yum &>/dev/null; then
  167. RPM_MGR="yum"
  168. fi
  169. ;;
  170. rhel)
  171. ID="centos"
  172. ;;
  173. linuxmint|neon|zorin|*ubuntu*)
  174. ID="ubuntu"
  175. ;;
  176. *suse*)
  177. ID="suse"
  178. ;;
  179. raspbian)
  180. ID="debian"
  181. ;;
  182. *)
  183. err "Autodetecting distro, this is unreliable and --compat may be required"
  184. if hash dnf &>/dev/null; then
  185. ID="fedora"
  186. RPM_MGR="dnf"
  187. elif hash yum &>/dev/null; then
  188. ID="centos"
  189. RPM_MGR="yum"
  190. COMPAT_SWITCH=1
  191. elif hash apt-get &>/dev/null; then
  192. ID="ubuntu"
  193. elif hash pacman &>/dev/null; then
  194. ID="arch"
  195. else
  196. err "OS detection failed!"
  197. askOk "Continue with manual installation?" || exit 1
  198. ID="unknown"
  199. REPO_INSTALL_SWITCH=0
  200. BUILD_SWITCH=1
  201. LOCAL_INSTALL_SWITCH=1
  202. fi
  203. esac
  204.  
  205. [[ $ID != "unknown" ]] && debug "Using host platform: $ID $VERSION_ID"
  206.  
  207. # Abstract distro-specific package manager commands
  208. case $ID in
  209. fedora|centos)
  210. PKG_INSTALL=(execute sudo "$RPM_MGR" install -y)
  211. PKG_REMOVE=(execute sudo "$RPM_MGR" remove -y)
  212. PKG_UPDATE=(execute sudo "$RPM_MGR" makecache)
  213. PKG_QUERY=(rpm -q)
  214. PKG_INSTALL_LOCAL(){ installMCRPM; }
  215. ;;
  216. debian|ubuntu)
  217. PKG_INSTALL=(execute sudo apt-get -f install -y -q0)
  218. PKG_REMOVE=(execute sudo apt-get remove --auto-remove -y -q0)
  219. PKG_UPDATE=(execute sudo apt-get update -y -q0)
  220. PKG_QUERY=(dpkg -s)
  221. PKG_INSTALL_LOCAL(){ installMCDEB; }
  222. ;;
  223. suse)
  224. PKG_INSTALL=(execute sudo zypper --gpg-auto-import-keys --non-interactive --quiet install --force --no-confirm)
  225. PKG_REMOVE=(execute sudo zypper --non-interactive --quiet remove --clean-deps)
  226. PKG_UPDATE=(execute sudo zypper --non-interactive --quiet refresh jriver)
  227. PKG_QUERY=(rpm -q)
  228. PKG_INSTALL_LOCAL(){ installMCRPM; }
  229. ;;
  230. arch)
  231. PKG_INSTALL=(execute sudo pacman -Sy --noconfirm)
  232. PKG_REMOVE=(execute sudo pacman -Rs --noconfirm)
  233. PKG_UPDATE=(execute sudo pacman -Syy)
  234. PKG_QUERY=(sudo pacman -Qs)
  235. PKG_INSTALL_LOCAL(){ installMCARCH; }
  236. ;;
  237. unknown)
  238. PKG_INSTALL=(:)
  239. PKG_REMOVE=(:)
  240. PKG_UPDATE=(:)
  241. PKG_QUERY=(:)
  242. PKG_INSTALL_LOCAL(){ installMCGENERIC; }
  243. esac
  244. }
  245.  
  246.  
  247. #######################################
  248. # Parses user input and sets sensible defaults
  249. #######################################
  250. parseInput() {
  251. debug "Running: ${FUNCNAME[0]}"
  252.  
  253. declare -g BUILD_SWITCH REPO_INSTALL_SWITCH COMPAT_SWITCH TEST_SWITCH
  254. declare -g LOCAL_INSTALL_SWITCH CREATEREPO_SWITCH UNINSTALL_SWITCH
  255. declare -g YES_SWITCH USER_VERSION_SWITCH USER_ARCH
  256. declare -g RESTOREFILE BETAPASS SERVICE_TYPE
  257. declare -g VNCPASS USER_DISPLAY
  258. declare -ga SERVICES CONTAINERS
  259. declare long_opts short_opts input
  260.  
  261. # Defaults
  262. declare -g BUILD_TARGET="$ID"
  263. declare -g REPO_TARGET="$ID"
  264. declare -g CREATEREPO_USER="$USER"
  265. declare -g SCRIPTDIR=; SCRIPTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
  266. declare -g OUTPUTDIR="$SCRIPTDIR/output"
  267. declare -g CREATEREPO_WEBROOT="/var/www/jriver"
  268. declare -g USER="${SUDO_USER:-$USER}"
  269. declare -g HOME; HOME=$(getent passwd "$USER" | cut -d: -f6)
  270.  
  271. if [[ $# -eq 0 ]] ||
  272. [[ $# -eq 1 && " $1 " =~ ^( --debug | -d | -y | --yes )$ ]] &&
  273. [[ $ID != "unknown" ]]; then
  274. REPO_INSTALL_SWITCH=1
  275. elif [[ $# -eq 1 && " $1 " =~ ^( --compat )$ ]]; then
  276. BUILD_SWITCH=1
  277. LOCAL_INSTALL_SWITCH=1
  278. fi
  279.  
  280. long_opts="install:,build::,outputdir:,mcversion:,restorefile:,betapass:,"
  281. long_opts+="service-type:,service:,services:,"
  282. long_opts+="version,debug,verbose,help,uninstall,tests,"
  283. long_opts+="createrepo::,createrepo-webroot:,createrepo-user:,"
  284. long_opts+="vncpass:,display:,container:,compat,arch:,yes,auto"
  285. short_opts="+i:vb::dhus:c:"
  286.  
  287. # Reset DEBUG and catch with getopt
  288. declare -g DEBUG=0
  289.  
  290. if input=$(getopt -o $short_opts -l $long_opts -- "$@"); then
  291. eval set -- "$input"
  292. while true; do
  293. case $1 in
  294. --install|-i)
  295. shift
  296. case $1 in
  297. local|rpm)
  298. BUILD_SWITCH=1
  299. LOCAL_INSTALL_SWITCH=1
  300. ;;
  301. repo|remote)
  302. REPO_INSTALL_SWITCH=1
  303. ;;
  304. esac
  305. ;;
  306. --build|-b)
  307. BUILD_SWITCH=1
  308. shift && BUILD_TARGET="$1"
  309. ;;
  310. --outputdir)
  311. shift && OUTPUTDIR="$1"
  312. ;;
  313. --mcversion)
  314. shift
  315. MC_VERSION="$1"
  316. USER_VERSION_SWITCH=1
  317. ;;
  318. --arch)
  319. shift && USER_ARCH="$1"
  320. ;;
  321. --restorefile)
  322. shift && RESTOREFILE="$1"
  323. ;;
  324. --betapass)
  325. shift && BETAPASS="$1"
  326. ;;
  327. --service-type)
  328. shift && SERVICE_TYPE="$1"
  329. ;;
  330. --service|-s|--services)
  331. shift && SERVICES+=("$1")
  332. ;;
  333. --createrepo)
  334. BUILD_SWITCH=1
  335. CREATEREPO_SWITCH=1
  336. shift && REPO_TARGET="$1" && BUILD_TARGET="$1"
  337. ;;
  338. --createrepo-webroot)
  339. shift && CREATEREPO_WEBROOT="$1"
  340. ;;
  341. --createrepo-user)
  342. shift && CREATEREPO_USER="$1"
  343. ;;
  344. --vncpass)
  345. shift && VNCPASS="$1"
  346. ;;
  347. --display)
  348. shift && USER_DISPLAY="$1"
  349. ;;
  350. --compat)
  351. COMPAT_SWITCH=1
  352. BUILD_SWITCH=1
  353. ;;
  354. --container|-c)
  355. shift && CONTAINERS+=("$1")
  356. ;;
  357. --yes|-y|--auto)
  358. YES_SWITCH=1
  359. ;;
  360. --version|-v)
  361. echo "Version: $SCRIPTVERSION"
  362. exit 0
  363. ;;
  364. --debug|-d|--verbose)
  365. DEBUG=1
  366. ;;
  367. --help|-h)
  368. printHelp
  369. exit
  370. ;;
  371. --uninstall|-u)
  372. UNINSTALL_SWITCH=1
  373. ;;
  374. --tests)
  375. TEST_SWITCH=1
  376. ;;
  377. --)
  378. shift
  379. break
  380. ;;
  381. esac
  382. shift
  383. done
  384. else
  385. err "Incorrect options provided"
  386. printHelp && exit 1
  387. fi
  388. }
  389.  
  390.  
  391. #######################################
  392. # Uses several methods to determine the latest JRiver MC version
  393. # TODO but how to determine build distro `$DEBIANBASE=bullseye`?
  394. #######################################
  395. setMCVersion() {
  396. debug "Running: ${FUNCNAME[0]}"
  397.  
  398. declare -g MC_VERSION_SOURCE MC_MVERSION MC_ROOT
  399. declare -g MC_PKG MC_RPM MC_STUB MC_STUB_TARGET
  400. declare cnt
  401.  
  402. # User input
  403. if (( USER_VERSION_SWITCH )) &&
  404. [[ $MC_VERSION =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  405. MC_VERSION_SOURCE="user input"
  406. # Containerized package manager
  407. else
  408. echo "Determining latest MC version"
  409. if installPackage --silent buildah &&
  410. hash buildah &>/dev/null &&
  411. cnt=$(buildah from --quiet debian:$DEBIANBASE-slim) &>/dev/null &&
  412. buildah run "$cnt" -- bash -c \
  413. "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 &&
  414. buildah run "$cnt" -- bash -c \
  415. "apt update --allow-insecure-repositories &>/dev/null" &>/dev/null &&
  416. MC_VERSION=$(buildah run "$cnt" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) &>/dev/null &&
  417. [[ $MC_VERSION =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  418. MC_VERSION_SOURCE="containerized package manager"
  419. execute buildah rm "$cnt"
  420. # Webscrape
  421. elif installPackage wget && MC_VERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1) &&
  422. [[ $MC_VERSION =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  423. MC_VERSION_SOURCE="webscrape"
  424. # Hardcoded
  425. else
  426. declare -g MC_VERSION="$MC_VERSION_HARDCODE"
  427. MC_VERSION_SOURCE="hardcoded or MC_VERSION env"
  428. err "Warning! Using hardcoded version number"
  429. fi
  430. fi
  431.  
  432. MC_MVERSION="${MC_VERSION%%.*}"
  433. MC_PKG="mediacenter$MC_MVERSION"
  434. MC_RPM="$OUTPUTDIR/RPMS/x86_64/mediacenter$MC_MVERSION-$MC_VERSION.x86_64.rpm"
  435. MC_ROOT="/usr/lib/jriver/Media Center $MC_MVERSION"
  436. MC_STUB="$MC_ROOT/mc$MC_MVERSION"
  437. MC_STUB_TARGET="/usr/bin/mc$MC_MVERSION"
  438.  
  439. if [[ $MC_VERSION_SOURCE == "user input" ]]; then
  440. # Append explicit package version when user provides --mcversion
  441. case $ID in
  442. fedora|centos|suse)
  443. MC_PKG+="-$MC_VERSION"
  444. ;;
  445. debian|ubuntu)
  446. MC_PKG+="=$MC_VERSION"
  447. ;;
  448. esac
  449. fi
  450. echo "Using MC version $MC_VERSION determined by $MC_VERSION_SOURCE"
  451. [[ $MC_VERSION_SOURCE == "user input" ]] || echo "To override, use --mcversion"
  452. debug "MVERSION: $MC_MVERSION, MC_VERSION: $MC_VERSION, MC_PKG: $MC_PKG, MC_RPM: $MC_RPM"
  453. }
  454.  
  455.  
  456. #######################################
  457. # Installs a package using the system package manager
  458. # Arguments:
  459. # One or more package names
  460. # Options:
  461. # --no-install-check: Do not check if package is already installed
  462. # --no-gpg-check: Disable GPG checks for RPM based distros
  463. # --allow-downgrades: Useful for installing specific MC versions
  464. # --silent, -s: Do not print errors (useful for optional packages)
  465. #######################################
  466. installPackage() {
  467. debug "Running: ${FUNCNAME[0]}" "$@"
  468.  
  469. declare -a pkg_array install_flags
  470. declare long_opts input pkg
  471. declare no_install_check allow_downgrades silent refresh no_gpg_check
  472. declare -A pkg_aliases
  473.  
  474. long_opts="no-install-check,allow-downgrades,no-gpg-check,refresh,silent"
  475.  
  476. if input=$(getopt -o +s -l "$long_opts" -- "$@"); then
  477. eval set -- "$input"
  478. while true; do
  479. case $1 in
  480. --no-install-check)
  481. no_install_check=1
  482. ;;
  483. --allow-downgrades)
  484. allow_downgrades=1
  485. ;;
  486. --no-gpg-check)
  487. no_gpg_check=1
  488. ;;
  489. --refresh)
  490. refresh=1
  491. ;;
  492. --silent|-s)
  493. silent=1
  494. ;;
  495. --)
  496. shift
  497. break
  498. ;;
  499. esac
  500. shift
  501. done
  502. else
  503. err "Incorrect options provided"
  504. exit 1
  505. fi
  506.  
  507. # Package aliases
  508. case $ID in
  509. debian|ubuntu)
  510. pkg_aliases["rpm-build"]="rpm"
  511. pkg_aliases["createrepo_c"]="createrepo"
  512. pkg_aliases["tigervnc-server"]="tigervnc-standalone-server"
  513. ;;
  514. esac
  515.  
  516. # Filter installed packages
  517. for pkg in "$@"; do
  518. if [[ -v pkg_aliases[$pkg] ]]; then
  519. debug "Aliasing $pkg to ${pkg_aliases[$pkg]}"
  520. pkg=${pkg_aliases[$pkg]}
  521. fi
  522. if (( no_install_check )) ||
  523. ! (hash "$pkg" &>/dev/null ||
  524. "${PKG_QUERY[@]}" "$pkg" &>/dev/null); then
  525. pkg_array+=("$pkg")
  526. else
  527. debug "$pkg already installed, skipping installation"
  528. fi
  529. done
  530.  
  531. # Generate distro-specific install flags
  532. case $ID in
  533. debian|ubuntu)
  534. (( allow_downgrades )) && install_flags+=(--allow-downgrades)
  535. ;;
  536. fedora|centos)
  537. (( allow_downgrades )) && install_flags+=(--allowerasing)
  538. (( no_gpg_check )) && install_flags+=(--nogpgcheck)
  539. (( refresh )) && install_flags+=(--refresh)
  540. ;;
  541. suse)
  542. (( no_gpg_check )) &&
  543. install_flags+=(--allow-unsigned-rpm)
  544. ;;
  545. esac
  546.  
  547. # Install packages from package array
  548. if [[ ${#pkg_array[@]} -ge 1 ]]; then
  549. if ! "${PKG_INSTALL[@]}" "${install_flags[@]}" "${pkg_array[@]}"; then
  550. (( silent )) || err "Failed to install ${pkg_array[*]}. Attempting to continue"
  551. return 1
  552. fi
  553. fi
  554. return 0
  555. }
  556.  
  557.  
  558. #######################################
  559. # Installs mesa-va-drivers-freeworld
  560. #######################################
  561. installMesa() {
  562. debug "Running: ${FUNCNAME[0]}"
  563.  
  564. # Currently only necessary in Fedora/CentOS
  565. case $ID in
  566. fedora|centos)
  567. if ! "${PKG_QUERY[@]}" mesa-va-drivers-freeworld &>/dev/null; then
  568. if "${PKG_QUERY[@]}" mesa-va-drivers &>/dev/null; then
  569. if ! execute sudo dnf swap -y \
  570. mesa-va-drivers \
  571. mesa-va-drivers-freeworld; then
  572. err "Package swap failed!"
  573. return 1
  574. fi
  575. else
  576. "${PKG_INSTALL[@]}" mesa-va-drivers-freeworld
  577. fi
  578. fi
  579. if ! "${PKG_QUERY[@]}" mesa-vdpau-drivers-freeworld &>/dev/null; then
  580. if "${PKG_QUERY[@]}" mesa-vdpau-drivers &>/dev/null; then
  581. if ! execute sudo dnf swap -y \
  582. mesa-vdpau-drivers \
  583. mesa-vdpau-drivers-freeworld; then
  584. err "Package swap failed!"
  585. return 1
  586. fi
  587. else
  588. "${PKG_INSTALL[@]}" mesa-va-drivers-freeworld mesa-vdpau-drivers-freeworld
  589. fi
  590. fi
  591. ;;
  592. esac
  593. }
  594.  
  595.  
  596. #######################################
  597. # Installs JRiver Media Center from a remote repository
  598. #######################################
  599. installMCFromRepo() {
  600. debug "Running: ${FUNCNAME[0]}"
  601.  
  602. case $ID in
  603. fedora|centos)
  604. sudo bash -c "cat <<-EOF > /etc/yum.repos.d/jriver.repo
  605. [jriver]
  606. name=JRiver Media Center repo by BryanC
  607. baseurl=https://repos.bryanroessler.com/jriver
  608. gpgcheck=0
  609. EOF"
  610. ;;
  611. debian|ubuntu)
  612. declare repo_dir="/etc/apt/sources.list.d"
  613. [[ -d $repo_dir ]] || execute sudo mkdir -p "$repo_dir"
  614. # Remove existing MC repositories
  615. execute sudo rm -rf "$repo_dir"/mediacenter*.list
  616. installPackage wget
  617. sudo bash -c "cat <<-EOF > $repo_dir/jriver.list
  618. deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $DEBIANBASE main
  619. EOF"
  620. wget -qO- "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" |
  621. sudo tee /etc/apt/trusted.gpg.d/jriver.asc &>/dev/null
  622. ;;
  623. *)
  624. err "An MC repository for $ID is not yet available"
  625. err "Use --install local to install MC on $ID"
  626. return 1
  627. ;;
  628. esac
  629.  
  630. if ! "${PKG_UPDATE[@]}"; then
  631. err "Package update failed!"
  632. return 1
  633. fi
  634.  
  635. # Install mesa-va-drivers-freeworld separately from the RPM using dnf swap
  636. installMesa
  637.  
  638. if ! installPackage \
  639. --no-install-check \
  640. --allow-downgrades \
  641. --no-gpg-check \
  642. "$MC_PKG"; then
  643. err "Package install failed!"
  644. return 1
  645. fi
  646. }
  647.  
  648.  
  649. #######################################
  650. # Acquires the source DEB package from JRiver
  651. #######################################
  652. acquireDeb() {
  653. debug "Running: ${FUNCNAME[0]}"
  654.  
  655. declare -g MC_DEB="$OUTPUTDIR/SOURCES/MediaCenter-$MC_VERSION-${USER_ARCH:-$ARCH}.deb"
  656.  
  657. debug "MC_DEB=$MC_DEB"
  658.  
  659. # If deb file already exists, skip download
  660. if [[ -f $MC_DEB ]]; then
  661. echo "Using existing DEB: $MC_DEB"
  662. return 0
  663. fi
  664.  
  665. if [[ -v BETAPASS ]] &&
  666. echo "Checking beta repo for DEB package" && execute wget -q -O "$MC_DEB" \
  667. "https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/beta/$BETAPASS/MediaCenter-$MC_VERSION-${USER_ARCH:-$ARCH}.deb"; then
  668. echo "Found!"
  669. elif echo "Checking latest repo for DEB package" && execute wget -q -O "$MC_DEB" \
  670. "https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/MediaCenter-$MC_VERSION-${USER_ARCH:-$ARCH}.deb"; then
  671. echo "Found!"
  672. elif echo "Checking test repo for DEB package" && execute wget -q -O "$MC_DEB" \
  673. "https://files.jriver-cdn.com/mediacenter/test/MediaCenter-$MC_VERSION-${USER_ARCH:-$ARCH}.deb"; then
  674. echo "Found!"
  675. else
  676. err "Cannot find DEB file"
  677. exit 1
  678. fi
  679.  
  680. if [[ -f $MC_DEB ]]; then
  681. echo "Downloaded MC $MC_VERSION DEB to $MC_DEB"
  682. else
  683. err "Downloaded DEB file missing or corrupted"
  684. exit 1
  685. fi
  686. }
  687.  
  688.  
  689. #######################################
  690. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  691. #######################################
  692. buildRPM() {
  693. debug "Running: ${FUNCNAME[0]}"
  694.  
  695. declare i rpmbuild_cmd
  696. declare -a requires recommends
  697.  
  698. # skip rebuilding the rpm if it already exists
  699. if [[ -f $MC_RPM ]]; then
  700. echo "$MC_RPM already exists. Skipping build step"
  701. return 0
  702. fi
  703.  
  704. # Load deb dependencies into array
  705. IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MC_DEB" Depends)"
  706. IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MC_DEB" Recommends)"
  707.  
  708. # Clean up formatting
  709. requires=("${requires[@]%%|*}")
  710. requires=("${requires[@]/?:/}")
  711. requires=("${requires[@]# }")
  712. requires=("${requires[@]% }")
  713. requires=("${requires[@]//\(/}")
  714. requires=("${requires[@]//)/}")
  715. recommends=("${recommends[@]%%|*}")
  716. recommends=("${recommends[@]/?:/}")
  717. recommends=("${recommends[@]# }")
  718. recommends=("${recommends[@]% }")
  719. recommends=("${recommends[@]//\(/}")
  720. recommends=("${recommends[@]//)/}")
  721.  
  722. # Translate package names
  723. case $BUILD_TARGET in
  724. fedora|centos)
  725. requires=("${requires[@]/libc6/glibc}")
  726. requires=("${requires[@]/libasound2/alsa-lib}")
  727. requires=("${requires[@]/libuuid1/libuuid}")
  728. requires=("${requires[@]/libx11-6/libX11}")
  729. requires=("${requires[@]/libxext6/libXext}")
  730. requires=("${requires[@]/libxcb1*/libxcb}") # TODO Remove minimum version for MC31 (*)
  731. requires=("${requires[@]/libxdmcp6/libXdmcp}")
  732. requires=("${requires[@]/libstdc++6/libstdc++}")
  733. requires=("${requires[@]/libgtk-3-0/gtk3}")
  734. requires=("${requires[@]/libgl1/mesa-libGL}")
  735. requires=("${requires[@]/libpango-1.0-0/pango}")
  736. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  737. requires=("${requires[@]/libpangox-1.0-0/pango}")
  738. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  739. requires=("${requires[@]/libnss3/nss}")
  740. requires=("${requires[@]/libnspr4/nspr}")
  741. requires=("${requires[@]/libgomp1/libgomp}")
  742. requires=("${requires[@]/libfribidi0/fribidi}")
  743. requires=("${requires[@]/libfontconfig1/fontconfig}")
  744. requires=("${requires[@]/libfreetype6/freetype}")
  745. requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
  746. requires=("${requires[@]/libgbm1/mesa-libgbm}")
  747. requires=("${requires[@]/libva2/libva}")
  748. requires=("${requires[@]/libva-drm2/libva}")
  749. requires=("${requires[@]/libepoxy0/libepoxy}")
  750. requires=("${requires[@]/liblcms2-2/lcms2}")
  751. requires=("${requires[@]/libvulkan1/vulkan-loader}")
  752. requires=("${requires[@]/libepoxy0/libepoxy}")
  753. requires=("${requires[@]/python/python3}")
  754. recommends+=(mesa-va-drivers-freeworld)
  755. ;;
  756. suse)
  757. requires=("${requires[@]/libc6/glibc}")
  758. requires=("${requires[@]/libasound2/alsa-lib}")
  759. requires=("${requires[@]/libx11-6/libX11-6}")
  760. requires=("${requires[@]/libxext6/libXext6}")
  761. requires=("${requires[@]/libxdmcp6/libXdmcp6}")
  762. requires=("${requires[@]/libgtk-3-0/gtk3}")
  763. requires=("${requires[@]/libgl1/Mesa-libGL1}")
  764. requires=("${requires[@]/libpango-1.0-0/pango}")
  765. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  766. requires=("${requires[@]/libpangox-1.0-0/pango}")
  767. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  768. requires=("${requires[@]/libnss3/mozilla-nss}")
  769. requires=("${requires[@]/libnspr4/mozilla-nspr}")
  770. requires=("${requires[@]/libfribidi0/fribidi}")
  771. requires=("${requires[@]/libfontconfig1/fontconfig}")
  772. requires=("${requires[@]/libfreetype6*/freetype}") # Remove minimum version specifier
  773. requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
  774. for i in "${!requires[@]}"; do
  775. [[ ${requires[$i]} == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
  776. done
  777. recommends+=(libvulkan_intel)
  778. recommends+=(libvulkan_radeon)
  779. ;;
  780. esac
  781.  
  782. # Convert array to newline delim'd string (for heredoc)
  783. printf -v requires "Requires: %s\n" "${requires[@]}"
  784. printf -v recommends "Recommends: %s\n" "${recommends[@]}"
  785. # Strip last newline
  786. requires="${requires%?}"
  787. recommends="${recommends%?}"
  788.  
  789. if (( COMPAT_SWITCH )); then
  790. # Strip minimum versions
  791. requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
  792. fi
  793.  
  794. # Create spec file
  795. cat <<-EOF > "$OUTPUTDIR/SPECS/mediacenter.spec"
  796. Name: mediacenter$MC_MVERSION
  797. Version: $MC_VERSION
  798. Release: 1
  799. Summary: JRiver Media Center
  800. Group: Applications/Media
  801. Source0: http://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/MediaCenter-$MC_VERSION-${USER_ARCH:-$ARCH}.deb
  802. BuildArch: x86_64
  803. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
  804.  
  805. AutoReq: 0
  806.  
  807. $requires
  808. $recommends
  809.  
  810. Conflicts: MediaCenter
  811.  
  812. Provides: mediacenter$MC_MVERSION
  813.  
  814. License: Copyright 1998-2023, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  815. URL: http://www.jriver.com/
  816.  
  817. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  818.  
  819. %description
  820. Media Center is more than a world class player.
  821.  
  822. %global __os_install_post %{nil}
  823. %prep
  824.  
  825. %build
  826.  
  827. %install
  828. dpkg -x %{S:0} %{buildroot}
  829.  
  830. %post -p /sbin/ldconfig
  831. %postun -p /sbin/ldconfig
  832.  
  833. %files
  834. %{_bindir}/mediacenter$MC_MVERSION
  835. %{_libdir}/jriver
  836. %{_datadir}
  837. %exclude %{_datadir}/applications/media_center_packageinstaller_$MC_MVERSION.desktop
  838. /etc/security/limits.d/*
  839. EOF
  840.  
  841. # Run rpmbuild
  842. echo "Building MC $MC_VERSION RPM, this may take some time"
  843. rpmbuild_cmd=(
  844. rpmbuild
  845. --define="%_topdir $OUTPUTDIR"
  846. --define="%_libdir /usr/lib"
  847. -bb
  848. "$OUTPUTDIR/SPECS/mediacenter.spec"
  849. )
  850. if execute "${rpmbuild_cmd[@]}" && [[ -f $MC_RPM ]] ; then
  851. echo "Build successful. The RPM file is located at: $MC_RPM"
  852. else
  853. err "Build failed"
  854. # For automation, let's remove the source DEB and reaquire it on next
  855. # run after failure in case it is corrupted or buggy
  856. [[ -f $MC_DEB ]] && echo "Removing source DEB" && rm -f "$MC_DEB"
  857. exit 1
  858. fi
  859. }
  860.  
  861.  
  862. #######################################
  863. # Installs Media Center DEB package and optional compatability fixes
  864. #######################################
  865. installMCDEB() {
  866. debug "Running: ${FUNCNAME[0]}"
  867.  
  868. if (( COMPAT_SWITCH )); then
  869. declare extract_dir && extract_dir="$(mktemp -d)"
  870. pushd "$extract_dir" &>/dev/null || return
  871. hash ar &>/dev/null || installPackage binutils
  872. execute ar x "$MC_DEB"
  873. execute tar xJf "control.tar.xz"
  874. # Remove minimum version specifiers from control file
  875. sed -i 's/ ([^)]*)//g' "control"
  876. sed -i 's/([^)]*)//g' "control" # TODO MC DEB package error
  877. [[ $ID == "ubuntu" && ${VERSION_ID%.*} -le 16 ]] &&
  878. ! grep -q zorin /etc/os-release && # TODO ugly ZorinOS workaround
  879. sed -i 's/libva2/libva1/g' "control"
  880. execute tar -cJf "control.tar.xz" "control" "postinst"
  881. declare -g MC_DEB="${MC_DEB/.deb/.compat.deb}"
  882. execute ar rcs "$MC_DEB" "debian-binary" "control.tar.xz" "data.tar.xz"
  883. popd &>/dev/null || return
  884. execute rm -rf "$extract_dir"
  885. fi
  886.  
  887. installPackage \
  888. --no-install-check \
  889. --no-gpg-check \
  890. --allow-downgrades \
  891. "$MC_DEB"
  892. }
  893.  
  894.  
  895. #######################################
  896. # Installs Media Center RPM package
  897. #######################################
  898. installMCRPM() {
  899. debug "Running: ${FUNCNAME[0]}"
  900.  
  901. # Install mesa-va-freeworld separately from the RPM for dnf swap
  902. installMesa
  903.  
  904. installPackage --no-install-check --no-gpg-check --allow-downgrades "$MC_RPM"
  905. }
  906.  
  907.  
  908. #######################################
  909. # Installs Media Center manually
  910. #######################################
  911. installMCGENERIC() {
  912. debug "Running: ${FUNCNAME[0]}"
  913.  
  914. declare -a raw_files
  915.  
  916. echo "Using raw installation method!"
  917.  
  918. declare extract_dir && extract_dir="$(mktemp -d)"
  919. pushd "$extract_dir" &>/dev/null || return
  920. execute ar x "$MC_DEB"
  921. execute tar xJf "control.tar.xz"
  922. echo "You must install the following dependencies manually:"
  923. grep -i "Depends:" control
  924. readarray -t raw_files < <(tar xJvf data.tar.xz)
  925. # Output to log file
  926. for f in "${raw_files[@]/#./}"; do
  927. echo "$f" >> "$SCRIPTDIR/.uninstall"
  928. done
  929. # Manually install files
  930. for f in "${raw_files[@]}"; do
  931. execute sudo cp -a "$f" "${f/#./}"
  932. done
  933. popd &>/dev/null || return
  934. execute rm -rf "$extract_dir"
  935. return 0
  936. }
  937.  
  938.  
  939. #######################################
  940. # Installs local Media Center PKGBUILD
  941. #######################################
  942. installMCARCH() {
  943. debug "Running: ${FUNCNAME[0]}"
  944.  
  945. [[ -d $OUTPUTDIR/PKGBUILD ]] || execute mkdir -p "$OUTPUTDIR/PKGBUILD"
  946.  
  947. cat <<-EOF > "$OUTPUTDIR/PKGBUILD/mediacenter.pkgbuild"
  948. pkgname=mediacenter$MC_MVERSION
  949. pkgver=$MC_VERSION
  950. pkgrel=1
  951. pkgdesc="The Most Comprehensive Media Software"
  952. arch=('x86_64')
  953. url="http://www.jriver.com/"
  954. license=('custom')
  955. depends=('alsa-lib' 'gcc-libs' 'libx11' 'libxext' 'libxcb' 'libxau' 'libxdmcp' 'util-linux' 'libxext' 'gtk3')
  956. optdepends=(
  957. 'mesa-libgl: nouveau video support'
  958. 'nvidia-libgl: nvidia video support'
  959. 'nvidia-utils: nvidia vulkan support'
  960. 'vulkan-intel: intel vulkan support'
  961. 'vulkan-radeon: amd vulkan support'
  962. 'vorbis-tools: ogg vorbis support'
  963. 'musepack-tools: musepack support'
  964. )
  965. source=("http://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/MediaCenter-$MC_VERSION-${USER_ARCH:-$ARCH}.deb")
  966.  
  967. package() {
  968. cd "\$srcdir"
  969. bsdtar xf data.tar.xz -C "\$pkgdir"
  970. }
  971. EOF
  972.  
  973. pushd "$OUTPUTDIR/PKGBUILD" &>/dev/null || return
  974.  
  975. if ! execute makepkg \
  976. --install \
  977. --syncdeps \
  978. --clean \
  979. --cleanbuild \
  980. --skipinteg \
  981. --force \
  982. --noconfirm \
  983. -p mediacenter.pkgbuild; then
  984. echo "makepkg failed"
  985. exit 1
  986. fi
  987.  
  988. popd &>/dev/null || return
  989. }
  990.  
  991.  
  992. #######################################
  993. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  994. #######################################
  995. runCreaterepo() {
  996. debug "Running: ${FUNCNAME[0]}"
  997.  
  998. declare -a cr_cmd
  999.  
  1000. installPackage createrepo_c
  1001.  
  1002. # If the webroot does not exist, create it
  1003. if [[ ! -d $CREATEREPO_WEBROOT ]]; then
  1004. if ! execute sudo -u "$CREATEREPO_USER" mkdir -p "$CREATEREPO_WEBROOT"; then
  1005. if ! ( execute sudo mkdir -p "$CREATEREPO_WEBROOT" &&
  1006. execute sudo chown -R "$CREATEREPO_USER:$CREATEREPO_USER" "$CREATEREPO_WEBROOT" ); then
  1007. err "Could not create the createrepo-webroot path!"
  1008. err "Make sure that the webroot $CREATEREPO_WEBROOT is writeable by user $CREATEREPO_USER"
  1009. err "Or change the repo ownership with --createrepo-user"
  1010. return 1
  1011. fi
  1012. fi
  1013. fi
  1014.  
  1015. # Copy built rpms to webroot
  1016. if ! ( execute sudo cp -nf "$MC_RPM" "$CREATEREPO_WEBROOT" &&
  1017. execute sudo chown -R "$CREATEREPO_USER:$CREATEREPO_USER" "$CREATEREPO_WEBROOT" ); then
  1018. err "Could not copy $MC_RPM to $CREATEREPO_WEBROOT"
  1019. return 1
  1020. fi
  1021.  
  1022. # Run createrepo
  1023. cr_cmd=(sudo -u "$CREATEREPO_USER" createrepo -q "$CREATEREPO_WEBROOT")
  1024. [[ -d $CREATEREPO_WEBROOT/repodata ]] && cr_cmd+=(--update)
  1025. if ! execute "${cr_cmd[@]}"; then
  1026. cr_cmd=(sudo createrepo -q "$CREATEREPO_WEBROOT")
  1027. [[ -d $CREATEREPO_WEBROOT/repodata ]] && cr_cmd+=(--update)
  1028. if ! (execute "${cr_cmd[@]}" &&
  1029. execute sudo chown -R "$CREATEREPO_USER:$CREATEREPO_USER" "$CREATEREPO_WEBROOT"); then
  1030. err "createrepo failed"
  1031. return 1
  1032. fi
  1033. fi
  1034. }
  1035.  
  1036.  
  1037. #######################################
  1038. # Symlink MC stub
  1039. #######################################
  1040. symlinkStub() {
  1041. debug "Running: ${FUNCNAME[0]}"
  1042.  
  1043. if [[ -f $MC_STUB && ! -e $MC_STUB_TARGET ]]; then
  1044. if ! execute sudo ln -fs "$MC_STUB" "$MC_STUB_TARGET"; then
  1045. err "Symlinking $MC_STUB to $MC_STUB_TARGET failed"
  1046. return 1
  1047. fi
  1048. fi
  1049. }
  1050.  
  1051.  
  1052. #######################################
  1053. # Symlink certificates if they do not exist in default location
  1054. #######################################
  1055. symlinkCerts() {
  1056. debug "Running: ${FUNCNAME[0]}"
  1057.  
  1058. declare mc_cert_link="$MC_ROOT/ca-certificates.crt"
  1059. declare target_cert f
  1060. declare -a source_certs=(
  1061. "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
  1062. "/var/lib/ca-certificates/ca-bundle.pem")
  1063.  
  1064. target_cert=$(readlink -f "$mc_cert_link")
  1065. [[ -f $target_cert ]] && return 0
  1066.  
  1067. for f in "${source_certs[@]}"; do
  1068. if [[ -f $f ]]; then
  1069. if ! execute sudo ln -fs "$f" "$mc_cert_link"; then
  1070. err "Symlinking certificate failed"
  1071. return 1
  1072. fi
  1073. break
  1074. fi
  1075. done
  1076. }
  1077.  
  1078.  
  1079. #######################################
  1080. # Restore the mjr license file from RESTOREFILE or other common locations
  1081. #######################################
  1082. restoreLicense() {
  1083. debug "Running: ${FUNCNAME[0]}"
  1084.  
  1085. declare f newest
  1086.  
  1087. # Glob mjr files from common directories
  1088. shopt -s nullglob
  1089. declare -a mjrfiles=(
  1090. "$SCRIPTDIR"/*.mjr
  1091. "$OUTPUTDIR"/*.mjr
  1092. "$HOME"/[dD]ownloads/*.mjr
  1093. "$HOME"/[dD]ocuments/*.mjr
  1094. )
  1095. shopt -u nullglob
  1096.  
  1097. if [[ ${#mjrfiles[@]} -gt 0 ]]; then
  1098.  
  1099. debug "mjrfiles=(${mjrfiles[*]})"
  1100.  
  1101. # Sort globbed files by time, newest first
  1102. newest=${mjrfiles[0]}
  1103. for f in "${mjrfiles[@]}"; do
  1104. if [[ -f $f && $f -nt $newest ]]; then
  1105. newest=$f
  1106. fi
  1107. done
  1108.  
  1109. debug "Latest mjrfile: $newest"
  1110.  
  1111. for f in "$RESTOREFILE" "$newest"; do
  1112. if [[ -f $f ]]; then
  1113. if execute "mediacenter$MC_MVERSION" "/RestoreFromFile" "$f"; then
  1114. return 0
  1115. fi
  1116. fi
  1117. done
  1118. fi
  1119. }
  1120.  
  1121.  
  1122. #######################################
  1123. # Opens ports using the system firewall tool
  1124. # Arguments:
  1125. # 1. Service name
  1126. # 2. List of ports in firewall-cmd format
  1127. #######################################
  1128. openFirewall() {
  1129. debug "Running: ${FUNCNAME[0]}" "$@"
  1130.  
  1131. declare port
  1132. declare service="$1"
  1133. shift
  1134. declare -a f_ports=("$@") # for firewall-cmd
  1135. declare u_ports="$*"
  1136. declare u_ports="${u_ports// /|}" # concatenate
  1137. u_ports="${u_ports//-/\:}" # for ufw
  1138.  
  1139. if hash firewall-cmd &>/dev/null; then
  1140. if ! sudo firewall-cmd --get-services | grep -q "$service"; then
  1141. execute sudo firewall-cmd --permanent "--new-service=$service"
  1142. execute sudo firewall-cmd --permanent "--service=$service" "--set-description=$service" installed by installJRMC
  1143. execute sudo firewall-cmd --permanent "--service=$service" "--set-short=$service"
  1144. for port in "${f_ports[@]}"; do
  1145. execute sudo firewall-cmd --permanent "--service=$service" "--add-port=$port"
  1146. done
  1147. execute sudo firewall-cmd --add-service "$service" --permanent
  1148. execute sudo firewall-cmd --reload
  1149. fi
  1150. elif hash ufw &>/dev/null; then
  1151. sudo bash -c "cat <<-EOF > /etc/ufw/applications.d/$service
  1152. [$service]
  1153. title=$service
  1154. description=$service installed by installJRMC
  1155. ports=$u_ports
  1156. EOF"
  1157. execute sudo ufw app update "$service"
  1158. execute sudo ufw allow "$service"
  1159. else
  1160. echo "Warning: Install firewall-cmd or ufw to open firewall ports"
  1161. return 1
  1162. fi
  1163. }
  1164.  
  1165.  
  1166. #######################################
  1167. # Create the xvnc or x11vnc password file
  1168. # Arguments:
  1169. # Service type (xvnc, x11vnc)
  1170. #######################################
  1171. setVNCPass() {
  1172. debug "Running: ${FUNCNAME[0]}"
  1173.  
  1174. declare vncpassfile="$HOME/.vnc/jrmc_passwd"
  1175.  
  1176. [[ -d ${vncpassfile%/*} ]] || execute mkdir -p "${vncpassfile%/*}"
  1177.  
  1178. if [[ -f $vncpassfile ]]; then
  1179. if [[ ! -v VNCPASS ]]; then
  1180. err "Refusing to overwrite existing $vncpassfile with an empty password"
  1181. err "Remove existing $vncpassfile or use --vncpass ''"
  1182. return 1
  1183. else
  1184. execute rm -f "$vncpassfile"
  1185. fi
  1186. fi
  1187.  
  1188. if [[ -v VNCPASS ]]; then
  1189. if [[ $1 == "xvnc" ]]; then
  1190. echo "$VNCPASS" | vncpasswd -f > "$vncpassfile"
  1191. elif [[ $1 == "x11vnc" ]]; then
  1192. execute x11vnc -storepasswd "$VNCPASS" "$vncpassfile"
  1193. fi
  1194. return $?
  1195. else
  1196. declare -g NOVNCAUTH=1
  1197. fi
  1198. }
  1199.  
  1200.  
  1201. #######################################
  1202. # Set display and port variables
  1203. #######################################
  1204. setDisplayVars() {
  1205. debug "Running: ${FUNCNAME[0]}"
  1206.  
  1207. declare -g DISPLAY DISPLAYNUM NEXT_DISPLAY
  1208.  
  1209. # Check USER_DISPLAY, else environment DISPLAY, else set to :0
  1210. DISPLAY="${USER_DISPLAY:-${DISPLAY:-:0}}"
  1211. DISPLAYNUM="${DISPLAY#*:}" # strip prefix
  1212. DISPLAYNUM="${DISPLAYNUM%%.*}" # strip suffix
  1213. # Increment each time we run this
  1214. if (( NEXT_DISPLAYNUM )); then
  1215. declare -g NEXT_DISPLAYNUM=$(( NEXT_DISPLAYNUM + 1 ))
  1216. else
  1217. declare -g NEXT_DISPLAYNUM=$(( DISPLAYNUM + 1 ))
  1218. fi
  1219. declare -g NEXT_DISPLAY=":$NEXT_DISPLAYNUM"
  1220. }
  1221.  
  1222.  
  1223. #######################################
  1224. # Create associated service variables based on service name
  1225. # Arguments
  1226. # Pre-defined service name
  1227. #######################################
  1228. setServiceVars() {
  1229. debug "Running: ${FUNCNAME[0]}" "$*"
  1230.  
  1231. declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME
  1232. declare -g USER_STRING DISPLAY_STRING GRAPHICAL_TARGET
  1233. declare -ga RELOAD ENABLE DISABLE IS_ENABLED IS_ACTIVE
  1234. declare -a systemctl_prefix
  1235. declare service_name="$1"
  1236. declare service_type="${SERVICE_TYPE:-${2:-system}}"
  1237. declare service_dir="/usr/lib/systemd/$service_type"
  1238.  
  1239. if [[ $USER == "root" && $service_type == "user" ]]; then
  1240. err "Trying to install user service as root"
  1241. err "Use --service-type service and/or execute installJRMC as non-root user"
  1242. return 1
  1243. fi
  1244.  
  1245. if [[ $service_type == "system" ]]; then
  1246. systemctl_prefix=(sudo systemctl)
  1247. GRAPHICAL_TARGET="graphical.target"
  1248. elif [[ $service_type == "user" ]]; then
  1249. systemctl_prefix=(systemctl --user)
  1250. GRAPHICAL_TARGET="default.target"
  1251. fi
  1252.  
  1253. # systemctl commands
  1254. RELOAD=(execute "${systemctl_prefix[@]}" daemon-reload)
  1255. ENABLE=(execute "${systemctl_prefix[@]}" enable --now)
  1256. DISABLE=(execute "${systemctl_prefix[@]}" disable --now)
  1257. IS_ENABLED=(execute "${systemctl_prefix[@]}" is-enabled -q)
  1258. IS_ACTIVE=(execute "${systemctl_prefix[@]}" is-active -q)
  1259.  
  1260. [[ -d $service_dir ]] || execute sudo mkdir -p "$service_dir"
  1261.  
  1262. # TODO Ubuntu needs these in the service file, fedora (and others?) do not
  1263. case $ID in
  1264. ubuntu|debian)
  1265. DISPLAY_STRING="Environment=XAUTHORITY=$XAUTHORITY"
  1266. ;;
  1267. *)
  1268. DISPLAY_STRING=""
  1269. ;;
  1270. esac
  1271.  
  1272. if [[ $service_type == "system" && $USER != "root" ]]; then
  1273. SERVICE_FNAME="$service_dir/$service_name@.service"
  1274. TIMER_FNAME="$service_dir/$service_name@.timer"
  1275. SERVICE_NAME="$service_name@$USER.service"
  1276. TIMER_NAME="$service_name@$USER.timer"
  1277. USER_STRING="User=%I"
  1278. else
  1279. SERVICE_NAME="$service_name.service"
  1280. TIMER_NAME="$service_name.timer"
  1281. SERVICE_FNAME="$service_dir/$SERVICE_NAME"
  1282. TIMER_FNAME="$service_dir/${TIMER_NAME}"
  1283. USER_STRING=""
  1284. fi
  1285. }
  1286.  
  1287.  
  1288. #######################################
  1289. # Starts and enables (at startup) a JRiver Media Center service
  1290. # Arguments:
  1291. # Passes arguments as startup options to /usr/bin/mediacenter??
  1292. #######################################
  1293. service_jriver-mediacenter() {
  1294. debug "Running: ${FUNCNAME[0]}"
  1295.  
  1296. setServiceVars "${FUNCNAME[0]##*_}" "user"
  1297.  
  1298. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1299. [Unit]
  1300. Description=JRiver Media Center $MC_MVERSION
  1301. After=$GRAPHICAL_TARGET
  1302.  
  1303. [Service]
  1304. Type=simple
  1305. $USER_STRING
  1306. $DISPLAY_STRING
  1307. Environment=DISPLAY=$DISPLAY
  1308. ExecStart=/usr/bin/mediacenter$MC_MVERSION $*
  1309. KillMode=none
  1310. ExecStop=$MC_STUB_TARGET /MCC 20007
  1311. Restart=always
  1312. RestartSec=10
  1313. TimeoutStopSec=30
  1314.  
  1315. [Install]
  1316. WantedBy=$GRAPHICAL_TARGET
  1317. EOF"
  1318.  
  1319. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1320.  
  1321. "${RELOAD[@]}" &&
  1322. "${ENABLE[@]}" "$SERVICE_NAME"
  1323. }
  1324.  
  1325.  
  1326. #######################################
  1327. # Starts and enables (at startup) a JRiver Media Server service
  1328. #######################################
  1329. service_jriver-mediaserver() {
  1330. debug "Running: ${FUNCNAME[0]}"
  1331.  
  1332. setServiceVars "${FUNCNAME[0]##*_}" "user"
  1333.  
  1334. service_jriver-mediacenter "/MediaServer"
  1335. }
  1336.  
  1337.  
  1338. #######################################
  1339. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  1340. # TODO https://github.com/TigerVNC/tigervnc/blob/master/unix/vncserver/HOWTO.md
  1341. #######################################
  1342. service_jriver-xvnc() {
  1343. debug "Running: ${FUNCNAME[0]}"
  1344.  
  1345. setServiceVars "${FUNCNAME[0]##*_}" "system"
  1346. setDisplayVars
  1347. declare -a start_cmd
  1348. declare -g PORT=$(( NEXT_DISPLAYNUM + 5900 ))
  1349.  
  1350. installPackage tigervnc-server
  1351.  
  1352. setVNCPass xvnc
  1353.  
  1354. start_cmd=(
  1355. /usr/bin/vncserver "$NEXT_DISPLAY"
  1356. -geometry 1440x900
  1357. -alwaysshared
  1358. -autokill
  1359. -xstartup "/usr/bin/mediacenter$MC_MVERSION"
  1360. )
  1361.  
  1362. if (( NOVNCAUTH )); then
  1363. start_cmd+=(
  1364. -name "jriver$NEXT_DISPLAY"
  1365. -SecurityTypes None
  1366. )
  1367. else
  1368. start_cmd+=(
  1369. -rfbauth "$HOME/.vnc/jrmc_passwd"
  1370. )
  1371. fi
  1372.  
  1373. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1374. [Unit]
  1375. Description=Remote desktop service (VNC)
  1376. After=multi-user.target
  1377.  
  1378. [Service]
  1379. Type=forking
  1380. $USER_STRING
  1381. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
  1382. ExecStart=${start_cmd[*]}
  1383. ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
  1384. Restart=always
  1385.  
  1386. [Install]
  1387. WantedBy=multi-user.target
  1388. EOF"
  1389.  
  1390. "${RELOAD[@]}"
  1391.  
  1392. if ! "${ENABLE[@]}" "$SERVICE_NAME"; then
  1393. err "vncserver failed to start on DISPLAY $NEXT_DISPLAY"
  1394. # Allow to increment 10 times before breaking
  1395. max=$(( DISPLAYNUM + 10 ))
  1396. while [[ $NEXT_DISPLAYNUM -lt $max ]]; do
  1397. echo "Incrementing DISPLAY and retrying"
  1398. service_jriver-xvnc && return
  1399. done
  1400. return 1
  1401. else
  1402. echo "Xvnc running on localhost:$PORT"
  1403. openFirewall "jriver-xvnc" "$PORT/tcp"
  1404. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1405. return 0
  1406. fi
  1407. }
  1408.  
  1409.  
  1410. #######################################
  1411. # Starts and enables (at startup) x11vnc screen sharing for the local desktop
  1412. #######################################
  1413. service_jriver-x11vnc() {
  1414. debug "Running: ${FUNCNAME[0]}"
  1415.  
  1416. setServiceVars "${FUNCNAME[0]##*_}" "user"
  1417. setDisplayVars
  1418.  
  1419. declare -a start_cmd
  1420. declare -g PORT=$(( DISPLAYNUM + 5900 ))
  1421.  
  1422. installPackage x11vnc
  1423.  
  1424. setVNCPass x11vnc
  1425.  
  1426. # If .Xauthority file is missing, generate a dummy for x11vnc -auth guess
  1427. if [[ ! -f "$HOME/.Xauthority" ]]; then
  1428. [[ $XDG_SESSION_TYPE == "wayland" ]] &&
  1429. askOk "Unsupported Wayland session detected for x11vnc, continue?" || return 1
  1430. debug "Generating $HOME/.Xauthority"
  1431. execute touch "$HOME/.Xauthority"
  1432. execute chmod 644 "$HOME/.Xauthority"
  1433. xauth generate "$DISPLAY" . trusted
  1434. xauth add "$HOST$DISPLAY" . "$(xxd -l 16 -p /dev/urandom)"
  1435. fi
  1436.  
  1437. start_cmd=(
  1438. /usr/bin/x11vnc
  1439. -display "$DISPLAY"
  1440. -noscr
  1441. -auth guess
  1442. -forever
  1443. -bg
  1444. )
  1445.  
  1446. if (( NOVNCAUTH )); then
  1447. start_cmd+=(-nopw)
  1448. else
  1449. start_cmd+=(-rfbauth "$HOME/.vnc/jrmc_passwd")
  1450. fi
  1451.  
  1452. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1453. [Unit]
  1454. Description=x11vnc
  1455. After=$GRAPHICAL_TARGET
  1456.  
  1457. [Service]
  1458. $USER_STRING
  1459. Type=forking
  1460. Environment=DISPLAY=$DISPLAY
  1461. ExecStart=${start_cmd[*]}
  1462. Restart=always
  1463. RestartSec=10
  1464.  
  1465. [Install]
  1466. WantedBy=$GRAPHICAL_TARGET
  1467. EOF"
  1468.  
  1469. openFirewall "jriver-x11vnc" "$PORT/tcp"
  1470.  
  1471. "${RELOAD[@]}" &&
  1472. "${ENABLE[@]}" "$SERVICE_NAME" &&
  1473. echo "x11vnc running on localhost:$PORT"
  1474. }
  1475.  
  1476.  
  1477. #######################################
  1478. # Starts and enables (at startup) an hourly service to build the latest version of
  1479. # JRiver Media Center RPM from the source DEB and create/update an RPM repository
  1480. #######################################
  1481. service_jriver-createrepo() {
  1482. debug "Running: ${FUNCNAME[0]}"
  1483.  
  1484. if [[ $CREATEREPO_USER != "$USER" ]]; then
  1485. USER="root" setServiceVars "${FUNCNAME[0]##*_}" "system"
  1486. else
  1487. setServiceVars "${FUNCNAME[0]##*_}" "system"
  1488. fi
  1489.  
  1490. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1491. [Unit]
  1492. Description=Builds JRiver Media Center RPM, moves it to the repo dir, and runs createrepo
  1493.  
  1494. [Service]
  1495. $USER_STRING
  1496. ExecStart=$SCRIPTDIR/installJRMC --outputdir=$OUTPUTDIR --createrepo=$REPO_TARGET --createrepo-webroot=$CREATEREPO_WEBROOT --createrepo-user=$CREATEREPO_USER
  1497.  
  1498. [Install]
  1499. WantedBy=multi-user.target
  1500. EOF"
  1501.  
  1502. sudo bash -c "cat <<-EOF > $TIMER_FNAME
  1503. [Unit]
  1504. Description=Run JRiver MC rpmbuild hourly
  1505.  
  1506. [Timer]
  1507. OnCalendar=hourly
  1508. Persistent=true
  1509.  
  1510. [Install]
  1511. WantedBy=timers.target
  1512. EOF"
  1513.  
  1514. "${RELOAD[@]}" &&
  1515. "${ENABLE[@]}" "$TIMER_NAME"
  1516. }
  1517.  
  1518.  
  1519. #######################################
  1520. # CONTAINERS
  1521. #######################################
  1522. # container_jriver-createrepo() {
  1523. # :
  1524. # }
  1525.  
  1526.  
  1527. # container_jriver-xvnc() {
  1528. # :
  1529. # }
  1530.  
  1531.  
  1532. # container_jriver-mediacenter() {
  1533.  
  1534. # installPackage buildah podman
  1535.  
  1536. # if ! CNT=$(buildah from debian:$DEBIANBASE-slim); then
  1537. # echo "Bad base image for container, skipping"
  1538. # return 1
  1539. # fi
  1540.  
  1541. # brc() { buildah run "$CNT" bash -c "$*"; }
  1542.  
  1543. # brc "add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg"
  1544.  
  1545. # # Install JRiver
  1546. # brc "
  1547. # add-pkg ca-certificates gnupg &&
  1548. # add-pkg --virtual build-dependencies wget &&
  1549. # wget -qO- http://dist.jriver.com/mediacenter@jriver.com.gpg.key | tee /etc/apt/trusted.gpg.d/jriver.asc &&
  1550. # wget -O /etc/apt/sources.list.d/mediacenter${MC_MVERSION}.list http://dist.jriver.com/latest/mediacenter/mediacenter${MC_MVERSION}.list &&
  1551. # apt update &&
  1552. # add-pkg mediacenter${MC_MVERSION} &&
  1553. # del-pkg build-dependencies
  1554. # "
  1555.  
  1556. # buildah config "$CNT" \
  1557. # --author "bryanroessler@gmail.com" \
  1558. # --label maintainer="$MAINTAINER" \
  1559. # --env TZ="$TZ" \
  1560. # --workingdir /app \
  1561. # --cmd "mediacenter$MC_MVERSION"
  1562.  
  1563.  
  1564. # # EXPOSE 5800 5900 52100 52101 52199 1900/udp
  1565.  
  1566. # podman_create_cmd=(
  1567. # podman create
  1568. # --name "mediacenter$MC_MVERSION"
  1569. # )
  1570.  
  1571. # podman_create_cmd+=(-v "$HOME/.jriver:/root/.jriver")
  1572. # podman_create_cmd+=(-v "$DOWNLOAD_ROOT:/downloads:z")
  1573. # podman_create_cmd+=(-v "$MONITOR_ROOT/nzbs:/nzbs")
  1574. # podman_create_cmd+=(-p "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1575.  
  1576. # # mkcdirs() {
  1577. # # declare dir
  1578. # # for dir in "$@"; do
  1579. # # if [[ ! -d "$dir" ]]; then
  1580. # # if ! mkdir -p "$dir"; then
  1581. # # err "Could not create directory $dir, check your permissions"
  1582. # # fi
  1583. # # fi
  1584. # # if ! chcon -t container_file_t -R "$dir"; then
  1585. # # err "Could not set container_file_t attribute for $dir, check your permissions"
  1586. # # fi
  1587. # # done
  1588. # # }
  1589.  
  1590. # # mkcdirs "$HOME/.jriver"
  1591.  
  1592.  
  1593. # brc sh -s <<-EOF
  1594. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &>/dev/null
  1595. # EOF
  1596.  
  1597. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MC_MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MC_MVERSION.list"
  1598.  
  1599. # brc apt update -y -q0
  1600.  
  1601. # brc add-pkg "mediacenter$MC_MVERSION"
  1602.  
  1603. # brc del-pkg .build-deps
  1604. # }
  1605.  
  1606.  
  1607. #######################################
  1608. # Detects if MC is installed on btrfs and disables CoW
  1609. #######################################
  1610. disableCoW() {
  1611. debug "Running: ${FUNCNAME[0]}"
  1612.  
  1613. declare dir
  1614. declare mc_user_path="$HOME/.jriver"
  1615.  
  1616. for dir in "$MC_ROOT" "$mc_user_path"; do
  1617. [[ -d $dir ]] || execute mkdir -p "$dir"
  1618. if [[ $(stat -f -c %T "$dir") == "btrfs" ]] &&
  1619. ! lsattr -d "$dir" | cut -f1 -d" " | grep -q C &&
  1620. execute sudo chattr +C "$dir"; then
  1621. echo "Disabled btrfs CoW for $dir directory"
  1622. fi
  1623. done
  1624. }
  1625.  
  1626.  
  1627. #######################################
  1628. # Migrate major versions
  1629. #######################################
  1630. migrateLibrary() {
  1631. debug "Running: ${FUNCNAME[0]}"
  1632.  
  1633. declare mc_user_path="$HOME/.jriver"
  1634. declare current_config_path="$mc_user_path/Media Center $MC_MVERSION"
  1635. declare previous_config_path="$mc_user_path/Media Center $(( MC_MVERSION - 1 ))"
  1636.  
  1637. if [[ ! -d $current_config_path ]] &&
  1638. [[ -d $previous_config_path ]] &&
  1639. mkdir -p "$current_config_path"; then
  1640. echo "Migrating $previous_config_path to $current_config_path"
  1641. cp -fa "$previous_config_path"/* "$current_config_path"
  1642. fi
  1643. }
  1644.  
  1645.  
  1646. #######################################
  1647. # Completely uninstalls MC, services, and firewall rules
  1648. #######################################
  1649. uninstall() {
  1650. debug "Running: ${FUNCNAME[0]}"
  1651.  
  1652. declare service unit f i
  1653.  
  1654. echo "Stopping and removing all Media Center services"
  1655. for service in $(compgen -A "function" "service"); do
  1656. service="${service##service_}"
  1657. for i in user system; do
  1658. setServiceVars "$service" "$i";
  1659. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1660. if "${IS_ACTIVE[@]}" "$unit" ||
  1661. "${IS_ENABLED[@]}" "$unit"; then
  1662. "${DISABLE[@]}" "$unit"
  1663. fi
  1664. done
  1665. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1666. [[ -f $f ]] &&
  1667. execute sudo rm -f "$f"
  1668. done
  1669. "${RELOAD[@]}"
  1670. unset f
  1671. done
  1672. for f in /etc/systemd/system/jriver-*; do
  1673. execute sudo rm -f "$f"
  1674. done
  1675. unset f
  1676. done
  1677.  
  1678. echo "Removing repo files"
  1679. sudo rm -rf \
  1680. "/etc/yum.repos.d/jriver.repo" \
  1681. /etc/apt/sources.list.d/{jriver,mediacenter}*.list # also remove legacy repo files
  1682. if [[ $ID == "suse" ]]; then
  1683. execute sudo zypper --non-interactive removerepo jriver
  1684. fi
  1685.  
  1686. echo "Removing firewall rules"
  1687. if hash firewall-cmd &>/dev/null; then
  1688. execute sudo firewall-cmd --permanent --remove-service=jriver
  1689. execute sudo firewall-cmd --permanent --delete-service=jriver
  1690. execute sudo firewall-cmd --reload
  1691. elif hash ufw &>/dev/null; then
  1692. execute sudo ufw delete allow jriver
  1693. [[ -f "/etc/ufw/applications.d/jriver" ]] &&
  1694. execute sudo rm -f /etc/ufw/applications.d/jriver
  1695. fi
  1696.  
  1697. echo "Uninstalling JRiver Media Center package"
  1698. if "${PKG_REMOVE[@]}" "$MC_PKG"; then
  1699. echo "JRiver Media Center has been completely uninstalled"
  1700. echo "To remove your MC library: rm -rf $HOME/.jriver"
  1701. elif [[ $? -eq 100 ]]; then
  1702. err "JRiver Media Center package '$MC_PKG' is not present and was not uninstalled"
  1703. else
  1704. err "Could not remove Media Center package"
  1705. fi
  1706.  
  1707. if [[ -f $SCRIPTDIR/.uninstall ]]; then
  1708. echo "Removing files from .uninstall log"
  1709. while read -r p; do
  1710. [[ -d $p ]] && execute sudo rm -rf "$p"
  1711. done < "$SCRIPTDIR/.uninstall"
  1712. mv "$SCRIPTDIR/.uninstall" "$SCRIPTDIR/.uninstall.bk"
  1713. fi
  1714.  
  1715. if [[ -e $MC_STUB_TARGET ]]; then
  1716. echo "Removing $MC_STUB_TARGET"
  1717. execute sudo rm -f "$MC_STUB_TARGET"
  1718. fi
  1719. return 0
  1720. }
  1721.  
  1722.  
  1723. tests() {
  1724. # To test on Mint/16.04: sudo apt install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1725. : # TODO
  1726. }
  1727.  
  1728.  
  1729. main() {
  1730. debug "Running: ${FUNCNAME[0]} $*"
  1731.  
  1732. init
  1733.  
  1734. parseInput "$@"
  1735.  
  1736. debug "Debugging on"
  1737. debug "installJRMC version: $SCRIPTVERSION"
  1738.  
  1739. if ((TEST_SWITCH)); then
  1740. echo "Running tests, all other options are skipped"
  1741. tests
  1742. exit
  1743. fi
  1744.  
  1745. setMCVersion
  1746.  
  1747. if (( UNINSTALL_SWITCH )); then
  1748. if askOk "Do you really want to uninstall JRiver Media Center?"; then
  1749. uninstall
  1750. else
  1751. echo "Uninstall canceled"
  1752. fi
  1753. exit
  1754. fi
  1755.  
  1756. # Install external repos
  1757. case $ID in
  1758. ubuntu)
  1759. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  1760. echo "Adding universe repository"
  1761. if ! execute sudo add-apt-repository -y universe; then
  1762. err "Adding universe repository failed"
  1763. fi
  1764. fi
  1765. ;;
  1766. centos)
  1767. if ! hash dpkg &>/dev/null; then
  1768. echo "Adding EPEL repository"
  1769. installPackage epel-release
  1770. fi
  1771. if ! "${PKG_QUERY[@]}" rpmfusion-free-release &>/dev/null; then
  1772. installPackage --no-install-check \
  1773. "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1774. fi
  1775. ;;
  1776. fedora)
  1777. if ! "${PKG_QUERY[@]}" rpmfusion-free-release &>/dev/null; then
  1778. installPackage --no-install-check \
  1779. "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  1780. fi
  1781. ;;
  1782. esac
  1783.  
  1784. if (( REPO_INSTALL_SWITCH )); then
  1785. echo "Installing JRiver Media Center from remote repository"
  1786. if installMCFromRepo; then
  1787. echo "JRiver Media Center installed successfully from remote repository"
  1788. symlinkCerts
  1789. migrateLibrary
  1790. restoreLicense
  1791. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1792. disableCoW
  1793. else
  1794. err "JRiver Media Center installation from remote repository failed"
  1795. return 1
  1796. fi
  1797. fi
  1798.  
  1799. if (( BUILD_SWITCH )) && [[ $ID != "arch" ]]; then
  1800. installPackage "wget"
  1801. [[ -d $OUTPUTDIR/SOURCES ]] || execute mkdir -p "$OUTPUTDIR/SOURCES"
  1802. acquireDeb
  1803. if [[ $BUILD_TARGET =~ (centos|fedora|suse) ||
  1804. $REPO_TARGET =~ (centos|fedora|suse) ]]; then
  1805. installPackage "dpkg" "rpm-build"
  1806. [[ -d $OUTPUTDIR/SPECS ]] || execute mkdir -p "$OUTPUTDIR/SPECS"
  1807. buildRPM
  1808. fi
  1809. fi
  1810.  
  1811. if (( LOCAL_INSTALL_SWITCH )); then
  1812. if PKG_INSTALL_LOCAL; then
  1813. echo "JRiver Media Center installed successfully from local package"
  1814. else
  1815. err "JRiver Media Center local package installation failed"
  1816. return 1
  1817. fi
  1818. symlinkCerts
  1819. migrateLibrary
  1820. restoreLicense
  1821. openFirewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1822. disableCoW
  1823. fi
  1824.  
  1825. if (( CREATEREPO_SWITCH )); then
  1826. if runCreaterepo; then
  1827. echo "Successfully updated repo"
  1828. else
  1829. err "Repo creation failed"
  1830. fi
  1831. fi
  1832.  
  1833. if [[ ${#SERVICES[@]} -gt 0 ]]; then
  1834. declare service
  1835. for service in "${SERVICES[@]}"; do
  1836. if ! "service_$service"; then
  1837. if [[ $? -eq 127 ]]; then
  1838. err "Service $service does not exist, check service name"
  1839. else
  1840. err "Failed to create $service service"
  1841. fi
  1842. else
  1843. echo "Started and enabled $service service"
  1844. fi
  1845. done
  1846. unset service
  1847. fi
  1848.  
  1849. # for _container in "${CONTAINERS[@]}"; do
  1850. # if ! "_container_$_container"; then
  1851. # if [[ $? -eq 127 ]]; then
  1852. # err "Container $_container does not exist, check container name"
  1853. # else
  1854. # err "Failed to create container: $_container"
  1855. # fi
  1856. # fi
  1857. # done
  1858. }
  1859.  
  1860. # Roughly turn debugging on, reparse in getInput() with getopt
  1861. [[ " $* " =~ ( --debug | -d ) ]] && declare -g DEBUG=1
  1862.  
  1863. main "$@"
  1864.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement