installJRMC 60 KB

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