installJRMC 57 KB

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