installJRMC 58 KB

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