installJRMC 59 KB

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