installJRMC 57 KB

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