installJRMC 59 KB

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