installJRMC 60 KB

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