installJRMC 60 KB

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