installJRMC 58 KB

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