installJRMC 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. #!/usr/bin/env bash
  2. # This script will install JRiver Media Center and associated services
  3. # on Fedora, CentOS, Debian, and Ubuntu
  4. #
  5. # Copyright (c) 2021 Bryan C. Roessler
  6. # This software is released under the Apache License.
  7. # https://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # See installJRMC --help or printHelp() below
  10. #
  11. # TODO (v2)
  12. # 1. Raspberry Pi OS support
  13. # 2. Interactive installation (ncurses?)
  14. # 3. Additional containerization (createrepo and rpmbuild)
  15. # 4. Tests
  16. #
  17. # BUGS
  18. # 1. No createrepo on Mint
  19. shopt -s extglob
  20. declare -g SCRIPTVERSION="1.0b6"
  21. declare -g OUTPUTDIR="$PWD/output"
  22. declare -g CREATEREPO_WEBROOT="/var/www/jriver"
  23. declare -g USER; USER="${USER:-$(id -un)}"
  24. declare -g USER_HOME; USER_HOME=$(grep "$USER" < /etc/passwd | cut -d":" -f6)
  25. # MC version
  26. # MCVERSION="28.0.87" # to set manually, if unset use automatic latest check
  27. printHelp() {
  28. debug "Running: ${FUNCNAME[0]}"
  29. cat <<- 'EOF'
  30. USAGE:
  31. installJRMC [[OPTION] [VALUE]]...
  32. If no options (besides -d) are provided, the script will default to '--install repo'.
  33. OPTIONS
  34. --install, -i repo|rpm|deb
  35. repo: Install MC from repository, updates are handled by the system package manager
  36. rpm: Build and install RPM locally (RPM-based distros only)
  37. deb: Download and install offcial MC package locally (useful with --compat flag for older distros)
  38. --build
  39. Build RPM from source DEB but do not install. Optional TARGET parameter enables RPM crossbuilding (ex. 'opensuse', 'fedora', 'centos')
  40. --target opensuse|fedora|centos
  41. Cross-build RPM or createrepo for target distro
  42. --mcversion VERSION
  43. Specify the MC version, ex. "28.0.94" (Default: latest)
  44. --outputdir PATH
  45. Generate rpmbuild output in this directory (Default: ./output)
  46. --restorefile RESTOREFILE
  47. Restore file location for automatic license registration (Default: skip registration)
  48. --betapass PASSWORD
  49. Enter beta team password for access to beta builds
  50. --service, -s SERVICE
  51. See SERVICES section below for a list of possible services to install
  52. --service-type user|system
  53. Starts services at boot (system) or at user login (user) (Default: boot)
  54. --container, -c CONTAINER (TODO: Under construction)
  55. See CONTAINERS section below for a list of possible services to install
  56. --createrepo
  57. Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos
  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. --compat
  63. Build/install RPM without minimum library specifiers
  64. --version, -v
  65. Print this script version and exit
  66. --debug, -d
  67. Print debug output
  68. --help, -h
  69. Print help dialog and exit
  70. --uninstall, -u
  71. Uninstall JRiver MC, remove services, and remove firewall rules (does not remove library files)
  72. SERVICES
  73. jriver-mediaserver
  74. Enable and start a mediaserver systemd service (requires an existing X server)
  75. jriver-mediacenter
  76. Enable and start a mediacenter systemd service (requires an existing X server)
  77. jriver-x11vnc
  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
  82. Enable and start a new Xvnc session running JRiver Media Center
  83. --vncpass PASSWORD
  84. Set vnc password for x11vnc/Xvnc access. If no password is set, the script
  85. will either use existing password stored in ~/.vnc/jrmc_passwd or use no password
  86. --display DISPLAY
  87. Display to start x11vnc/Xvnc (Default: The current display (x11vnc) or the
  88. current display incremented by 1 (Xvnc))
  89. jriver-createrepo
  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. # Helpers
  97. debug() { (( DEBUG )) && [[ $# -gt 0 ]] && echo "Debug: $*"; }
  98. err() { echo "Error: $*" >&2; }
  99. askOk() {
  100. declare response
  101. read -r -p "$* [y/N]" response
  102. [[ "${response,,}" =~ ^(yes|y)$ ]]
  103. return $?
  104. }
  105. getOS() {
  106. if [[ -e "/etc/os-release" ]]; then
  107. source "/etc/os-release"
  108. else
  109. err "/etc/os-release not found"
  110. err "Your OS is unsupported"
  111. printHelp && exit 1
  112. fi
  113. debug "Platform: $ID $VERSION_ID"
  114. }
  115. # ifSudo() {
  116. # declare user="root"
  117. # if [[ $# == 0 ]]; then
  118. # [[ "$USER" == "root" ]]
  119. # return $?
  120. # elif [[ $# -eq 2 && "$1" == "-u" ]]; then
  121. # user="$2"
  122. # [[ "$USER" == "$user" ]]
  123. # return $?
  124. # elif [[ $# -gt 2 && "$1" == "-u" ]]; then
  125. # user="$2"
  126. # shift 2
  127. # fi
  128. # if [[ "$user" == "$USER" ]]; then
  129. # "$@"
  130. # else
  131. # sudo -u "$user" "$@"
  132. # fi
  133. # }
  134. parseInput() {
  135. debug "Running: ${FUNCNAME[0]}"
  136. declare -g RPM_BUILD_SWITCH REPO_INSTALL_SWITCH COMPAT_SWITCH CREATEREPO_SWITCH UNINSTALL_SWITCH DEB_INSTALL_SWITCH
  137. declare -g TARGET OUTPUTDIR MCVERSION RESTOREFILE BETAPASS SERVICE_TYPE VNCPASS USER_DISPLAY CREATEREPO_WEBROOT CREATEREPO_USER
  138. declare -ga SERVICES CONTAINERS
  139. if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$1" =~ ^(--debug|-d)$ ]]; then
  140. echo "No options passed, defaulting to repo installation method"
  141. REPO_INSTALL_SWITCH=1
  142. fi
  143. if _input=$(getopt -o +i:vdhus:c: -l install:,build,target:,outputdir:,mcversion:,restorefile:,betapass:,service-type:,service:,version,debug,help,uninstall,createrepo,createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests,compat -- "$@"); then
  144. eval set -- "$_input"
  145. while true; do
  146. case "$1" in
  147. --install|-i)
  148. shift
  149. case "$1" in
  150. rpm)
  151. RPM_BUILD_SWITCH=1
  152. RPM_INSTALL_SWITCH=1
  153. ;;
  154. deb)
  155. DEB_INSTALL_SWITCH=1
  156. ;;
  157. repo)
  158. REPO_INSTALL_SWITCH=1
  159. ;;
  160. esac
  161. ;;
  162. --build)
  163. RPM_BUILD_SWITCH=1
  164. ;;
  165. --target)
  166. shift && TARGET="$1"
  167. ;;
  168. --outputdir)
  169. shift && OUTPUTDIR="$1"
  170. ;;
  171. --mcversion)
  172. shift && MCVERSION="$1"
  173. ;;
  174. --restorefile)
  175. shift && RESTOREFILE="$1"
  176. ;;
  177. --betapass)
  178. shift && BETAPASS="$1"
  179. ;;
  180. --service-type)
  181. shift && SERVICE_TYPE="$1"
  182. ;;
  183. --service|-s)
  184. shift && SERVICES+=("$1")
  185. ;;
  186. --createrepo)
  187. RPM_BUILD_SWITCH=1
  188. CREATEREPO_SWITCH=1
  189. ;;
  190. --createrepo-webroot)
  191. shift && CREATEREPO_WEBROOT="$1"
  192. ;;
  193. --createrepo-user)
  194. shift && CREATEREPO_USER="$1"
  195. ;;
  196. --vncpass)
  197. shift && VNCPASS="$1"
  198. ;;
  199. --display)
  200. shift && USER_DISPLAY="$1"
  201. ;;
  202. --compat)
  203. COMPAT_SWITCH=1
  204. ;;
  205. --container|-c)
  206. shift && CONTAINERS+=("$1")
  207. ;;
  208. --version|-v)
  209. echo "Version: $SCRIPTVERSION"
  210. exit 0
  211. ;;
  212. --debug|-d)
  213. echo "Debugging on"
  214. echo "installJRMC version: $SCRIPTVERSION"
  215. DEBUG=1
  216. ;;
  217. --help|-h)
  218. printHelp && exit $?
  219. ;;
  220. --uninstall|-u)
  221. UNINSTALL_SWITCH=1
  222. ;;
  223. --tests)
  224. echo "Running tests, all other options are skipped"
  225. tests
  226. ;;
  227. --)
  228. shift
  229. break
  230. ;;
  231. esac
  232. shift
  233. done
  234. else
  235. err "Incorrect options provided"
  236. printHelp && exit 1
  237. fi
  238. }
  239. #######################################
  240. # Use several methods to determine the latest JRiver MC version
  241. #######################################
  242. getLatestVersion() {
  243. debug "Running: ${FUNCNAME[0]}"
  244. declare -g MCVERSION BASE BOARDURL
  245. declare cnt
  246. # Latest defaults
  247. BASE="buster" # For container method
  248. BOARDURL="https://yabb.jriver.com/interact/index.php/board,71.0.html" # MC28 (Buster), for fallback webscrape
  249. #BASE_next="bullseye" # TODO use for fallback to smooth upgrades
  250. # Use a containerized package manager
  251. # TODO but how to determine build distro ($BASE=buster)?
  252. installPackage --silent buildah
  253. if cnt=$(buildah from debian:$BASE) &>/dev/null; then
  254. buildah run "$cnt" -- bash -c \
  255. "echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $BASE main' > /etc/apt/sources.list 2>&1"
  256. buildah run "$cnt" -- bash -c \
  257. "apt-get update --allow-insecure-repositories &>/dev/null"
  258. if MCVERSION=$(buildah run "$cnt" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) \
  259. && [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
  260. version_source="containerized package manager"
  261. fi
  262. buildah rm "$cnt" &>/dev/null
  263. return 0
  264. fi
  265. # Scrape from Interact
  266. installPackage wget
  267. if MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
  268. version_source="webscrape"
  269. else
  270. err "$BOARDURL could not be parsed"
  271. err "MC version could not be determined"
  272. err "Specify a version manually using --mcversion"
  273. exit 1
  274. fi
  275. }
  276. #######################################
  277. # Installs a package using the system package manager
  278. # Arguments:
  279. # One or more package names
  280. # Options:
  281. # --nocheck: Do not check if package is already installed
  282. # --nogpgcheck: Disable GPG checks for RPM based distros
  283. # --silent, -s: Do not report errors (useful if package is not strictly required and errors are noisy)
  284. #######################################
  285. installPackage() {
  286. debug "Running: ${FUNCNAME[0]}" "$@"
  287. declare -a pkg_array install_flags
  288. declare pkg nocheck silent _return pkg_install_cmd
  289. if _input=$(getopt -o +s -l nocheck,nogpgcheck,nobest,silent -- "$@"); then
  290. eval set -- "$_input"
  291. while true; do
  292. case "$1" in
  293. --nocheck)
  294. nocheck=1
  295. ;;
  296. --nogpgcheck)
  297. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  298. install_flags+=("--nogpgcheck")
  299. elif [[ "$ID" =~ ^opensuse.* ]]; then
  300. install_flags+=("--allow-unsigned-rpm")
  301. fi
  302. ;;
  303. --nobest)
  304. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  305. install_flags+=("--nobest")
  306. fi
  307. ;;
  308. --silent|-s)
  309. silent=1
  310. ;;
  311. --)
  312. shift
  313. break
  314. ;;
  315. esac
  316. shift
  317. done
  318. else
  319. err "Incorrect options provided"
  320. exit 1
  321. fi
  322. # Aliases
  323. if [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  324. declare -A PKG_ALIASES
  325. PKG_ALIASES["xorg-x11-utils"]="xorg-x11"
  326. PKG_ALIASES["rpm-build"]="rpm"
  327. PKG_ALIASES["createrepo_c"]="createrepo"
  328. PKG_ALIASES["tigervnc-server"]="tigervnc-standalone-server"
  329. fi
  330. for pkg in "$@"; do
  331. if [[ ! -v nocheck && -v PKG_ALIASES[$pkg] ]]; then
  332. pkg=${PKG_ALIASES[$pkg]}
  333. fi
  334. # Check if already installed
  335. if (( nocheck )) || ([[ ! -x $(command -v $pkg) ]] \
  336. && ! pkg_query "$pkg" &>/dev/null); then
  337. pkg_array+=("$pkg")
  338. fi
  339. done
  340. # Install packages from package array
  341. if [[ ${#pkg_array[@]} -ge 1 ]]; then
  342. pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}"
  343. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  344. if ! eval "$pkg_install_cmd" && (( silent )); then
  345. err "Failed to install ${pkg_array[*]}. Attempting to continue..."
  346. fi
  347. fi
  348. }
  349. #######################################
  350. # Add the JRiver repository files
  351. #######################################
  352. addRepo() {
  353. debug "Running: ${FUNCNAME[0]}"
  354. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  355. sudo bash -c 'cat <<- EOF > /etc/yum.repos.d/jriver.repo
  356. [jriver]
  357. name=JRiver Media Center repo by BryanC
  358. baseurl=https://repos.bryanroessler.com/jriver
  359. gpgcheck=0
  360. EOF'
  361. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  362. # MVERSION depends on $BASE unless --mcversion is passed
  363. installPackage wget
  364. wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | sudo apt-key add - &>/dev/null
  365. sudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" &>/dev/null
  366. elif [[ "$ID" =~ ^opensuse.* ]]; then
  367. sudo zypper addrepo --no-gpgcheck "https://repos.bryanroessler.com/jriver" jriver &>/dev/null
  368. fi
  369. }
  370. #######################################
  371. # Installs JRiver Media Center from a repository
  372. #######################################
  373. installMCFromRepo() {
  374. debug "Running: ${FUNCNAME[0]}"
  375. echo "Installing JRiver Media Center $MCVERSION from repository."
  376. echo "Future updates will be handled by your package manager."
  377. if ! debug; then
  378. echo "This may take a few minutes to complete."
  379. echo "Use --debug for verbose output."
  380. fi
  381. addRepo
  382. # Update package list
  383. debug "$pkg_update_cmd" || pkg_update_cmd+=" &>/dev/null"
  384. if ! eval "$pkg_update_cmd"; then
  385. err "Package update failed!"
  386. exit 1
  387. fi
  388. pkg_install_cmd="installPackage --nocheck --nogpgcheck $MCPKG"
  389. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  390. eval "$pkg_install_cmd"
  391. }
  392. #######################################
  393. # Acquire the source DEB package from JRiver's servers
  394. #######################################
  395. acquireDeb() {
  396. debug "Running: ${FUNCNAME[0]}"
  397. declare -g MCDEB="$OUTPUTDIR/SOURCES/MediaCenter-$MCVERSION-amd64.deb"
  398. # If necessary, create SOURCES dir
  399. [[ ! -d "$OUTPUTDIR/SOURCES" ]] && mkdir -p "$OUTPUTDIR/SOURCES"
  400. # If deb file already exists, skip download
  401. if [[ -f "$MCDEB" ]]; then
  402. echo "Using local DEB file: $MCDEB"
  403. return 0
  404. fi
  405. if [[ -v BETAPASS ]]; then
  406. echo "Checking beta repo..."
  407. if wget -q -O "$MCDEB" \
  408. "https://files.jriver.com/mediacenter/channels/v$MVERSION/beta/$BETAPASS/MediaCenter-$MCVERSION-amd64.deb"; then
  409. echo "Found!"
  410. fi
  411. elif echo "Checking test repo..." && wget -q -O "$MCDEB" \
  412. "https://files.jriver.com/mediacenter/test/MediaCenter-$MCVERSION-amd64.deb"; then
  413. echo "Found!"
  414. # Else check latest repo
  415. elif echo "Checking latest repo..." && wget -q -O "$MCDEB" \
  416. "https://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb"; then
  417. echo "Found!"
  418. else
  419. err "Cannot find DEB file."
  420. exit 1
  421. fi
  422. if [[ ! -f "$MCDEB" ]]; then
  423. err "Downloaded DEB file missing or corrupted."
  424. exit 1
  425. fi
  426. }
  427. #######################################
  428. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  429. #######################################
  430. buildRPM() {
  431. debug "Running: ${FUNCNAME[0]}"
  432. declare id i rpmbuild_cmd
  433. declare -a requires recommends
  434. declare -A dupes
  435. declare -g MCRPM="$OUTPUTDIR/RPMS/x86_64/MediaCenter-$MCVERSION.x86_64.rpm"
  436. # skip rebuilding the rpm if it already exists
  437. if [[ -f "$MCRPM" ]]; then
  438. echo "$MCRPM already exists. Skipping build step."
  439. return 0
  440. fi
  441. [[ ! -d "$OUTPUTDIR/SPECS" ]] && mkdir -p "$OUTPUTDIR/SPECS"
  442. # Use --target parameter override
  443. id="${TARGET:-$ID}"
  444. # Load deb dependencies into array
  445. IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MCDEB" Depends)"
  446. IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MCDEB" Recommends)"
  447. # Clean up formatting
  448. requires=("${requires[@]%%|*}")
  449. requires=("${requires[@]/?:/}")
  450. requires=("${requires[@]# }")
  451. requires=("${requires[@]% }")
  452. requires=("${requires[@]//\(/}")
  453. requires=("${requires[@]//)/}")
  454. recommends=("${recommends[@]%%|*}")
  455. recommends=("${recommends[@]/?:/}")
  456. recommends=("${recommends[@]# }")
  457. recommends=("${recommends[@]% }")
  458. recommends=("${recommends[@]//\(/}")
  459. recommends=("${recommends[@]//)/}")
  460. # Translate package names
  461. case "$id" in
  462. fedora|centos)
  463. requires=("${requires[@]/libc6/glibc}")
  464. requires=("${requires[@]/libasound2/alsa-lib}")
  465. requires=("${requires[@]/libuuid1/libuuid}")
  466. requires=("${requires[@]/libx11-6/libX11}")
  467. requires=("${requires[@]/libxext6/libXext}")
  468. requires=("${requires[@]/libxcb1/libxcb}")
  469. requires=("${requires[@]/libxdmcp6/libXdmcp}")
  470. requires=("${requires[@]/libstdc++6/libstdc++}")
  471. requires=("${requires[@]/libgtk-3-0/gtk3}")
  472. requires=("${requires[@]/libgl1/mesa-libGL}")
  473. requires=("${requires[@]/libpango-1.0-0/pango}")
  474. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  475. requires=("${requires[@]/libpangox-1.0-0/pango}")
  476. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  477. requires=("${requires[@]/libnss3/nss}")
  478. requires=("${requires[@]/libnspr4/nspr}")
  479. requires=("${requires[@]/libgomp1/libgomp}")
  480. requires=("${requires[@]/libfribidi0/fribidi}")
  481. requires=("${requires[@]/libfontconfig1/fontconfig}")
  482. requires=("${requires[@]/libfreetype6/freetype}")
  483. requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
  484. requires=("${requires[@]/libgbm1/mesa-libgbm}")
  485. requires=("${requires[@]/libva2/libva}")
  486. requires=("${requires[@]/libepoxy0/libepoxy}")
  487. requires=("${requires[@]/liblcms2-2/lcms2}")
  488. requires=("${requires[@]/libvulkan1/vulkan-loader}")
  489. requires=("${requires[@]/libepoxy0/libepoxy}")
  490. ;;
  491. opensuse*)
  492. requires=("${requires[@]/libc6/glibc}")
  493. requires=("${requires[@]/libasound2/alsa-lib}")
  494. requires=("${requires[@]/libx11-6/libX11-6}")
  495. requires=("${requires[@]/libxext6/libXext6}")
  496. requires=("${requires[@]/libxdmcp6/libXdmcp6}")
  497. requires=("${requires[@]/libgtk-3-0/gtk3}")
  498. requires=("${requires[@]/libgl1/Mesa-libGL1}")
  499. requires=("${requires[@]/libpango-1.0-0/pango}")
  500. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  501. requires=("${requires[@]/libpangox-1.0-0/pango}")
  502. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  503. requires=("${requires[@]/libnss3/mozilla-nss}")
  504. requires=("${requires[@]/libnspr4/mozilla-nspr}")
  505. requires=("${requires[@]/libfribidi0/fribidi}")
  506. requires=("${requires[@]/libfontconfig1/fontconfig}")
  507. requires=("${requires[@]/libfreetype6*/freetype}") # Remove minimum version specifier
  508. requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
  509. for i in "${!requires[@]}"; do
  510. [[ "${requires[$i]}" == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
  511. done
  512. recommends+=("libvulkan_intel")
  513. recommends+=("libvulkan_radeon")
  514. ;;
  515. esac
  516. # Remove duplicates
  517. for i in "${requires[@]}"; do
  518. if [[ ! -v dupes[${i%% *}] ]]; then
  519. tmp+=("$i")
  520. fi
  521. dupes["${i%% *}"]=1
  522. done
  523. requires=("${tmp[@]}")
  524. # Convert array to newline delim'd string (for heredoc)
  525. printf -v requires "Requires: %s\n" "${requires[@]}"
  526. printf -v recommends "Recommends: %s\n" "${recommends[@]}"
  527. # Strip last newline
  528. requires="${requires%?}"
  529. recommends="${recommends%?}"
  530. if (( COMPAT_SWITCH )); then
  531. # Strip minimum versions
  532. requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
  533. fi
  534. # Create spec file
  535. cat <<- EOF > "$OUTPUTDIR/SPECS/mediacenter.spec"
  536. Name: MediaCenter
  537. Version: $MCVERSION
  538. Release: 1
  539. Summary: JRiver Media Center
  540. Group: Applications/Media
  541. Source0: http://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb
  542. BuildArch: x86_64
  543. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
  544. AutoReq: 0
  545. $requires
  546. $recommends
  547. Provides: mediacenter$MVERSION
  548. License: Copyright 1998-2022, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  549. URL: http://www.jriver.com/
  550. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  551. %description
  552. Media Center is more than a world class player.
  553. %global __os_install_post %{nil}
  554. %prep
  555. %build
  556. %install
  557. dpkg -x %{S:0} %{buildroot}
  558. %post -p /sbin/ldconfig
  559. %postun -p /sbin/ldconfig
  560. %files
  561. %{_bindir}/mediacenter$MVERSION
  562. %{_libdir}/jriver
  563. %{_datadir}
  564. %exclude %{_datadir}/applications/media_center_packageinstaller_$MVERSION.desktop
  565. /etc/security/limits.d/*
  566. EOF
  567. # Run rpmbuild
  568. echo "Building version $MCVERSION, please wait..."
  569. rpmbuild_cmd="rpmbuild --define=\"%_topdir $OUTPUTDIR\" --define=\"%_libdir /usr/lib\" -bb $OUTPUTDIR/SPECS/mediacenter.spec"
  570. debug "$rpmbuild_cmd" || rpmbuild_cmd+=" &>/dev/null"
  571. if eval "$rpmbuild_cmd" && [[ -f "$MCRPM" ]] ; then
  572. echo "Build successful. The RPM file is located at: $MCRPM"
  573. else
  574. err "Build failed."
  575. # For automation, let's remove the source DEB and reaquire it on next run
  576. # after failure in case it is corrupted or buggy
  577. [[ -f "$MCDEB" ]] && echo "Removing source DEB" && rm -f "$MCDEB"
  578. exit 1
  579. fi
  580. }
  581. #######################################
  582. # Copy the RPM to createrepo-webroot and runs createrepo as the createrepo-user
  583. #######################################
  584. runCreaterepo() {
  585. debug "Running: ${FUNCNAME[0]}"
  586. declare cr_cmd cr_cp_cmd cr_mkdir_cmd cr_chown_cmd
  587. declare cr_user="${CREATEREPO_USER:-'www-data'}"
  588. installPackage createrepo_c
  589. # If the webroot does not exist, create it
  590. if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then
  591. cr_mkdir_cmd="sudo -u $cr_user mkdir -p $CREATEREPO_WEBROOT"
  592. debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
  593. if ! eval "$cr_mkdir_cmd"; then
  594. cr_mkdir_cmd="sudo mkdir -p $CREATEREPO_WEBROOT"
  595. debug "$cr_mkdir_cmd" || cr_mkdir_cmd+=" &>/dev/null"
  596. cr_chown_cmd="sudo chown -R $cr_user:$cr_user $CREATEREPO_WEBROOT"
  597. debug "$cr_chown_cmd" || cr_chown_cmd+=" &>/dev/null"
  598. if ! ( eval "$cr_mkdir_cmd" && eval "$cr_chown_cmd" ); then
  599. err "Could not create the createrepo-webroot path!"
  600. err "Make sure that the webroot $CREATEREPO_WEBROOT is writeable by user $cr_user"
  601. err "Or change the repo ownership with --createrepo-user"
  602. return 1
  603. fi
  604. fi
  605. fi
  606. # Copy built rpms to webroot
  607. cr_cp_cmd="sudo cp -nf $MCRPM $CREATEREPO_WEBROOT"
  608. cr_chown_cmd="sudo chown -R $cr_user:$cr_user $CREATEREPO_WEBROOT"
  609. debug "$cr_cp_cmd" || cr_cp_cmd+=" &>/dev/null"
  610. debug "$cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null"
  611. if ! ( eval "$cr_cp_cmd" && eval "$cr_chown_cmd" ); then
  612. err "Could not copy $MCRPM to $CREATEREPO_WEBROOT"
  613. return 1
  614. fi
  615. # Run createrepo
  616. cr_cmd="sudo -u $cr_user createrepo -q $CREATEREPO_WEBROOT"
  617. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
  618. debug "$cr_cmd" || cr_cmd+=" &>/dev/null"
  619. if ! eval "$cr_cmd"; then
  620. cr_cmd="sudo createrepo -q $CREATEREPO_WEBROOT"
  621. [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_cmd+=" --update"
  622. cr_chown_cmd="sudo chown -R $cr_user:$cr_user $CREATEREPO_WEBROOT"
  623. debug "$cr_cmd" || cr_cmd+=" &>/dev/null"
  624. debug "$cr_chown_cmd" || cr_cp_cmd+=" &>/dev/null"
  625. if ! ( eval "$cr_cmd" && eval "$cr_chown_cmd"); then
  626. err "Createrepo failed"
  627. return 1
  628. fi
  629. fi
  630. echo "Successfully updated repo"
  631. }
  632. #######################################
  633. # Symlink certificates where JRiver Media Center expects them to be on Fedora/CentOS
  634. #######################################
  635. symlinkCerts() {
  636. debug "Running: ${FUNCNAME[0]}"
  637. if [[ ! -f /etc/ssl/certs/ca-certificates.crt &&
  638. -f /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ]]; then
  639. ln_cmd="sudo ln -s /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/ssl/certs/ca-certificates.crt"
  640. debug "$ln_cmd" || ln_cmd+=" &>/dev/null"
  641. if ! exec "$ln_cmd"; then
  642. err "Symlinking certificates failed"
  643. return 1
  644. fi
  645. fi
  646. }
  647. #######################################
  648. # Automatically restore the mjr license file if it is found next to
  649. # installJRMC or RESTOREFILE is set
  650. #######################################
  651. restoreLicense() {
  652. debug "Running: ${FUNCNAME[0]}"
  653. declare _mjr
  654. # Allow user to put the mjr file next to installJRMC
  655. if [[ ! -v RESTOREFILE ]]; then
  656. for _mjr in "$PWD"/*.mjr; do
  657. [[ $_mjr -nt $RESTOREFILE ]] && RESTOREFILE="$_mjr"
  658. done
  659. fi
  660. # Restore license
  661. if [[ -f "$RESTOREFILE" ]]; then
  662. if ! "mediacenter$MVERSION" /RestoreFromFile "$RESTOREFILE"; then
  663. err "Automatic license restore failed"
  664. return 1
  665. fi
  666. fi
  667. }
  668. #######################################
  669. # Opens ports using the system firewall tool
  670. # Arguments
  671. # Pre-defined service to enable
  672. #######################################
  673. openFirewall() {
  674. debug "Running: ${FUNCNAME[0]}" "$@"
  675. # Create OS-specific port rules based on argument (service) name
  676. declare -a _f_ports # for firewall-cmd
  677. declare _u_ports # for ufw
  678. if [[ "$1" == "jriver" ]]; then
  679. _f_ports=("52100-52200/tcp" "1900/udp")
  680. _u_ports="52100:52200/tcp|1900/udp"
  681. elif [[ "$1" =~ ^(jriver-x11vnc|jriver-xvnc)$ ]]; then
  682. _f_ports=("$_port/tcp" "1900/udp")
  683. _u_ports="$_port/tcp|1900/udp"
  684. fi
  685. # Open the ports
  686. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  687. installPackage firewalld
  688. if ! firewall_cmd --get-services | grep -q "$1"; then
  689. firewall_cmd --permanent --new-service="$1" &>/dev/null
  690. firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" &>/dev/null
  691. firewall_cmd --permanent --service="$1" --set-short="$1" &>/dev/null
  692. for _f_port in "${_f_ports[@]}"; do
  693. firewall_cmd --permanent --service="$1" --add-port="$_f_port" &>/dev/null
  694. done
  695. firewall_cmd --add-service "$1" --permanent &>/dev/null
  696. firewall_cmd --reload &>/dev/null
  697. fi
  698. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmin|neon)$ ]]; then
  699. # Debian ufw package state is broken on fresh installations
  700. installPackage ufw
  701. if [[ ! -f "/etc/ufw/applications.d/$1" ]]; then
  702. sudo bash -c "cat <<- EOF > /etc/ufw/applications.d/$1
  703. [$1]
  704. title=$1
  705. description=$1 installed by installJRMC
  706. ports=$_u_ports
  707. EOF"
  708. fi
  709. firewall_cmd app update "$1"
  710. firewall_cmd allow "$1" &>/dev/null
  711. fi
  712. # shellcheck disable=SC2181 # More concise
  713. if [[ $? -ne 0 ]]; then
  714. err "Firewall ports could not be opened"
  715. return 1
  716. fi
  717. }
  718. #######################################
  719. # Create the x11vnc password file
  720. #######################################
  721. setX11VNCPass() {
  722. debug "Running: ${FUNCNAME[0]}"
  723. _vncpassfile="$HOME/.vnc/jrmc_passwd"
  724. [[ ! -d "${_vncpassfile%/*}" ]] && mkdir -p "${_vncpassfile%/*}"
  725. if [[ -f "$_vncpassfile" ]]; then
  726. if [[ ! -v VNCPASS ]]; then
  727. err "Refusing to overwrite existing $_vncpassfile with an empty password"
  728. err "Remove existing $_vncpassfile or set --vncpass to use an empty password"
  729. exit 1
  730. else
  731. rm -f "$_vncpassfile"
  732. fi
  733. fi
  734. if [[ -v VNCPASS ]]; then
  735. if ! x11vnc -storepasswd "$VNCPASS" "$_vncpassfile"; then
  736. err "Could not create VNC password file"
  737. return 1
  738. fi
  739. else
  740. _novncauth="true"
  741. fi
  742. }
  743. #######################################
  744. # Create the Xvnc password file
  745. #######################################
  746. setVNCPass() {
  747. debug "Running: ${FUNCNAME[0]}"
  748. declare _vncpassfile="$HOME/.vnc/jrmc_passwd"
  749. [[ ! -d "${_vncpassfile%/*}" ]] && mkdir -p "${_vncpassfile%/*}"
  750. if [[ -f "$_vncpassfile" ]]; then
  751. if [[ ! -v VNCPASS ]]; then
  752. err "Refusing to overwrite existing $_vncpassfile with an empty password"
  753. err "Remove existing $_vncpassfile or set --vncpass to use an empty password"
  754. exit 1
  755. else
  756. rm -f "$_vncpassfile"
  757. fi
  758. fi
  759. if [[ -v VNCPASS ]]; then
  760. if ! echo "$VNCPASS" | vncpasswd -f > "$_vncpassfile"; then
  761. err "Could not create VNC password file"
  762. return 1
  763. fi
  764. else
  765. _novncauth="true"
  766. fi
  767. }
  768. #######################################
  769. # Set display and port variables
  770. #######################################
  771. setDisplay() {
  772. debug "Running: ${FUNCNAME[0]}"
  773. declare -g DISPLAY DISPLAYNUM NEXT_DISPLAY NEXT_DISPLAYNUM
  774. # Check USER_DISPLAY, else environment DISPLAY, else set to :0 by default
  775. DISPLAY="${USER_DISPLAY:-${DISPLAY:-0}}"
  776. DISPLAYNUM="${DISPLAY#*:}" # strip prefix
  777. DISPLAYNUM="${DISPLAYNUM%%.*}" # strip suffix
  778. NEXT_DISPLAYNUM=$(( DISPLAYNUM + 1 ))
  779. NEXT_DISPLAY=":$NEXT_DISPLAYNUM"
  780. }
  781. #######################################
  782. # Create associated service variables based on service name
  783. #######################################
  784. setServiceVars() {
  785. debug "Running: ${FUNCNAME[0]}"
  786. declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME USER_STRING EXEC_USER
  787. declare service_system_dir="/usr/lib/systemd/system"
  788. declare service_user_dir="$USER_HOME/.config/systemd/user"
  789. declare service_type="${SERVICE_TYPE:-system}"
  790. if [[ "$USER" == "root" && "$service_type" == "user" ]]; then
  791. err "Trying to install user service as root"
  792. err "Use --service-type service and/or execute installJRMC as non-root user"
  793. return 1
  794. fi
  795. if [[ "$service_type" == "system" ]]; then
  796. service_dir="$service_system_dir"
  797. EXEC_USER="root"
  798. systemctl_reload_cmd(){ sudo systemctl daemon-reload; }
  799. systemctl_enable_cmd(){ sudo systemctl enable --now "$@"; }
  800. systemctl_disable_cmd(){ sudo systemctl disable --now "$@"; }
  801. systemctl_is_enabled_cmd(){ sudo systemctl is-enabled -q "$@"; }
  802. systemctl_is_active_cmd(){ sudo systemctl is-active -q "$@"; }
  803. elif [[ "$service_type" == "user" ]]; then
  804. service_dir="$service_user_dir"
  805. EXEC_USER="$USER"
  806. systemctl_reload_cmd(){ systemctl --user daemon-reload; }
  807. systemctl_enable_cmd(){ systemctl --user enable --now "$@"; }
  808. systemctl_disable_cmd(){ systemctl --user disable --now "$@"; }
  809. systemctl_is_enabled_cmd(){ systemctl --user is-enabled -q "$@"; }
  810. systemctl_is_active(){ sudo systemctl is-active -q "$@"; }
  811. fi
  812. [[ ! -d "$service_dir" ]] && sudo -u "$EXEC_USER" mkdir -p "$service_dir"
  813. if [[ "$USER" == "root" || "$service_type" == "user" ]]; then
  814. SERVICE_NAME="${1}.service"
  815. TIMER_NAME="${1}.timer"
  816. SERVICE_FNAME="$service_dir/${SERVICE_NAME}"
  817. TIMER_FNAME="$service_dir/${TIMER_NAME}"
  818. USER_STRING=""
  819. else
  820. SERVICE_FNAME="$service_dir/${1}@.service"
  821. TIMER_FNAME="$service_dir/${1}@.timer"
  822. SERVICE_NAME="${1}@$USER.service"
  823. TIMER_NAME="${1}@$USER.timer"
  824. USER_STRING="User=%I"
  825. fi
  826. }
  827. #######################################
  828. # Starts and enables (at startup) a JRiver Media Center service
  829. # Arguments:
  830. # Passes arguments as startup options to /usr/bin/mediacenter??
  831. #######################################
  832. service_jriver-mediacenter() {
  833. debug "Running: ${FUNCNAME[0]}"
  834. sudo -u "$EXEC_USER" bash -c "cat <<- EOF > $SERVICE_FNAME
  835. [Unit]
  836. Description=JRiver Media Center $MVERSION
  837. After=graphical.target
  838. [Service]
  839. $USER_STRING
  840. Type=simple
  841. Environment=DISPLAY=$DISPLAY
  842. Environment=XAUTHORITY=$XAUTHORITY
  843. ExecStart=/usr/bin/mediacenter$MVERSION $*
  844. Restart=always
  845. RestartSec=10
  846. KillSignal=SIGHUP
  847. TimeoutStopSec=30
  848. [Install]
  849. WantedBy=graphical.target
  850. EOF"
  851. systemctl_reload_cmd &&
  852. systemctl_enable_cmd "$SERVICE_NAME" &&
  853. openFirewall "jriver"
  854. }
  855. #######################################
  856. # Starts and enables (at startup) a JRiver Media Server service
  857. #######################################
  858. service_jriver-mediaserver() {
  859. debug "Running: ${FUNCNAME[0]}"
  860. service_jriver-mediacenter "/MediaServer"
  861. }
  862. #######################################
  863. # Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  864. #######################################
  865. service_jriver-xvnc() {
  866. debug "Running: ${FUNCNAME[0]}"
  867. declare start_cmd
  868. declare port=$(( NEXT_DISPLAYNUM + 5900 ))
  869. installPackage tigervnc-server
  870. setVNCPass
  871. if [[ -v _novncauth ]]; then
  872. start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -name jriver$NEXT_DISPLAY -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$MVERSION"
  873. else
  874. start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$MVERSION"
  875. fi
  876. sudo -u "$EXEC_USER" bash -c "cat <<- EOF > $SERVICE_FNAME
  877. [Unit]
  878. Description=Remote desktop service (VNC)
  879. After=syslog.target network.target
  880. [Service]
  881. Type=simple
  882. $USER_STRING
  883. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
  884. ExecStart=$start_cmd
  885. ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
  886. Restart=always
  887. [Install]
  888. WantedBy=default.target
  889. EOF"
  890. systemctl_reload_cmd &&
  891. systemctl_enable_cmd "$SERVICE_NAME" &&
  892. echo "Xvnc running on localhost:$port" &&
  893. openFirewall "jriver-xvnc" &&
  894. openFirewall "jriver"
  895. }
  896. #######################################
  897. # Starts and enables (at startup) JRiver Media Server and x11vnc sharing the local desktop
  898. #######################################
  899. service_jriver-x11vnc() {
  900. debug "Running: ${FUNCNAME[0]}"
  901. declare start_cmd
  902. declare port=$(( DISPLAYNUM + 5900 ))
  903. installPackage x11vnc
  904. setX11VNCPass
  905. # Get current desktop resolution
  906. # TODO: may need to break this out into its own function and get smarter at identifying multi-monitors
  907. # _getResolution() {
  908. # debug "Running: ${FUNCNAME[0]}"
  909. # installPackage xorg-x11-utils
  910. # _res=$(xdpyinfo | grep dimensions | awk '{print $2}')
  911. # }
  912. # _getResolution
  913. if [[ -v _novncauth ]]; then
  914. start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -nopw"
  915. else
  916. start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd"
  917. fi
  918. sudo -u "$EXEC_USER" bash -c "cat <<-EOF > $SERVICE_FNAME
  919. [Unit]
  920. Description=x11vnc
  921. After=multi.service
  922. [Service]
  923. $USER_STRING
  924. Type=forking
  925. Environment=DISPLAY=$DISPLAY
  926. ExecStart=$start_cmd
  927. Restart=always
  928. RestartSec=10
  929. [Install]
  930. WantedBy=default.target
  931. EOF"
  932. systemctl_reload_cmd &&
  933. systemctl_enable_cmd "$SERVICE_NAME" &&
  934. echo "x11vnc running on localhost:$port" &&
  935. openFirewall "jriver-x11vnc"
  936. }
  937. #######################################
  938. # Starts and enables (at startup) an hourly service to build the latest version of JRiver Media
  939. # Center RPM from the source DEB and create/update an RPM repository
  940. #######################################
  941. service_jriver-createrepo() {
  942. debug "Running: ${FUNCNAME[0]}"
  943. declare id="${TARGET:-$ID}"
  944. sudo -u "$EXEC_USER" bash -c "cat <<-EOF > $SERVICE_FNAME
  945. [Unit]
  946. Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo
  947. [Service]
  948. $USER_STRING
  949. ExecStart=$PWD/installJRMC --target $id --outputdir $OUTPUTDIR --createrepo --createrepo-webroot $CREATEREPO_WEBROOT --createrepo-user $CREATEREPO_USER
  950. [Install]
  951. WantedBy=default.target
  952. EOF"
  953. sudo -u "$EXEC_USER" bash -c "cat <<-EOF > $TIMER_FNAME
  954. [Unit]
  955. Description=Run JRiver MC rpmbuild hourly
  956. [Timer]
  957. OnCalendar=hourly
  958. Persistent=true
  959. [Install]
  960. WantedBy=timers.target
  961. EOF"
  962. systemctl_reload_cmd &&
  963. systemctl_enable_cmd "$TIMER_NAME"
  964. }
  965. #######################################
  966. # CONTAINERS
  967. #######################################
  968. # container_jriver-createrepo() {
  969. # :
  970. # }
  971. # container_jriver-xvnc() {
  972. # :
  973. # }
  974. # container_jriver-mediacenter() {
  975. # installPackage buildah podman
  976. # # Eventually try to switch to Debian
  977. # # if ! CNT=$(buildah from debian:$BASE); then
  978. # # echo "Bad base image for container $CNAME, skipping"
  979. # # continue
  980. # # fi
  981. # if ! CNT=$(buildah from jlesage/baseimage-gui:debian-10-v3.5.7); then
  982. # echo "Bad base image for container $CNAME, skipping"
  983. # continue
  984. # fi
  985. # buildah run "$CNT" add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg
  986. # # #BASEIMAGE=jlesage/baseimage-gui:debian-10-v3.5.7
  987. # # JRIVER_RELEASE=28
  988. # # JRIVER_TAG=stable
  989. # # ARCH=amd64
  990. # # REBUILD_MIN=22
  991. # # REBUILD_MAX=120
  992. # # # JRiver Version tag (latest, stable or beta)
  993. # # ARG jriver_tag
  994. # # # JRiver Release Version (25, 26 etc.)
  995. # # ARG jriver_release
  996. # # # Image Version of the build
  997. # # ARG image_version
  998. # # # .deb download URL, if set to "repository" the JRiver repository will be used
  999. # # ARG deb_url
  1000. # # RUN add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1 ffmpeg
  1001. # # Install JRiver
  1002. # RUN \
  1003. # add-pkg --virtual build-dependencies wget &&
  1004. # # Install from Repository
  1005. # if [ "${deb_url}" = "repository" ]; then \
  1006. # echo "Installing JRiver from repository ${jriver_release}:${jriver_tag}" &&
  1007. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &&
  1008. # wget http://dist.jriver.com/${jriver_tag}/mediacenter/mediacenter${jriver_release}.list -O /etc/apt/sources.list.d/mediacenter${jriver_release}.list &&
  1009. # apt-get update &&
  1010. # add-pkg mediacenter${jriver_release}; \
  1011. # # Install from .deb URL
  1012. # else \
  1013. # echo "Installing JRiver from URL: ${deb_url}" &&
  1014. # wget -q -O "jrivermc.deb" ${deb_url} &&
  1015. # add-pkg "./jrivermc.deb"; \
  1016. # fi &&
  1017. # # Cleanup
  1018. # del-pkg build-dependencies &&
  1019. # rm -rf /tmp/* /tmp/.[!.]*
  1020. # # Add rootfs
  1021. # COPY rootfs/ /
  1022. # VOLUME ["/config"]
  1023. # # Application Icon
  1024. # RUN \
  1025. # APP_ICON_URL=https://gitlab.com/shiomax/jrivermc-docker/raw/master/assets/Application.png &&
  1026. # install_app_icon.sh "$APP_ICON_URL"
  1027. # # Various configuration vars
  1028. # ENV KEEP_APP_RUNNING=1 \
  1029. # DISPLAY_WIDTH=1280 \
  1030. # DISPLAY_HEIGHT=768 \
  1031. # APP_NAME="JRiver MediaCenter ${jriver_release}" \
  1032. # MAXIMIZE_POPUPS=0 \
  1033. # S6_KILL_GRACETIME=8000
  1034. # # Modify startapp.sh and rc.xml with JRiver version
  1035. # RUN sed-patch s/%%MC_VERSION%%/${jriver_release}/g \
  1036. # /startapp.sh &&
  1037. # sed-patch s/%%MC_VERSION%%/${jriver_release}/g \
  1038. # /etc/xdg/openbox/rc.xml
  1039. # EXPOSE 5800 5900 52100 52101 52199 1900/udp
  1040. # # Metadata.
  1041. # LABEL \
  1042. # org.label-schema.name="jrivermc${jriver_release}" \
  1043. # org.label-schema.description="Docker image for JRiver Media Center ${jriver_release}." \
  1044. # org.label-schema.version="${image_version}" \
  1045. # org.label-schema.vcs-url="https://gitlab.com/shiomax/jrivermc-docker" \
  1046. # org.label-schema.schema-version="1.0"
  1047. # installPackage buildah podman
  1048. # cnt=$(buildah from docker.io/jlesage/baseimage-gui:debian-10)
  1049. # podman_create_cmd=("podman" "create" "--name" "$CNAME")
  1050. # buildah_config_cmd=("buildah" "config" \
  1051. # "--author" "bryanroessler@gmail.com" \
  1052. # "--label" "maintainer=$MAINTAINER" \
  1053. # "--env" "TZ=$TZ" \
  1054. # "--workingdir" "/app" \
  1055. # "--cmd" "mediacenter$MVERSION")
  1056. # mkcdirs() {
  1057. # declare dir
  1058. # for dir in "$@"; do
  1059. # if [[ ! -d "$dir" ]]; then
  1060. # if ! mkdir -p "$dir"; then
  1061. # err "Could not create directory $dir, check your permissions"
  1062. # fi
  1063. # fi
  1064. # if ! chcon -t container_file_t -R "$dir"; then
  1065. # err "Could not set container_file_t attribute for $dir, check your permissions"
  1066. # fi
  1067. # done
  1068. # }
  1069. # mkcdirs "$HOME/.jriver"
  1070. # podman_create_cmd+=("-v" "$HOME/.jriver:/root/.jriver")
  1071. # podman_create_cmd+=("-v" "$DOWNLOAD_ROOT:/downloads:z")
  1072. # podman_create_cmd+=("-v" "$MONITOR_ROOT/nzbs:/nzbs")
  1073. # podman_create_cmd+=("-p" "${CONTAINER[HOST_PORT]}:${CONTAINER[CONTAINER_PORT]}")
  1074. # brc() { buildah run "$1" "${@:2}" || return 1; }
  1075. # brc add-pkg gnupg2 libxss1 wmctrl xdotool ca-certificates inotify-tools libgbm1
  1076. # brc add-pkg --virtual .build-deps wget
  1077. # brc sh -s <<- EOF
  1078. # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &>/dev/null
  1079. # EOF
  1080. # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list"
  1081. # brc apt-get update -y -q0
  1082. # brc add-pkg "mediacenter$MVERSION"
  1083. # brc del-pkg .build-deps
  1084. # }
  1085. uninstall() {
  1086. debug "Running: ${FUNCNAME[0]}"
  1087. declare service unit f
  1088. if ! askOk "Do you really want to uninstall JRiver Media Center"; then
  1089. echo "Cancelling uninstall..."
  1090. exit 0
  1091. fi
  1092. debug "Stopping and removing all associated Media Center services"
  1093. for service in $(compgen -A "function" "service"); do
  1094. service="${service##service_}"
  1095. SERVICE_TYPE=system setServiceVars "$service";
  1096. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1097. if systemctl_is_active_cmd "$unit" &>/dev/null ||
  1098. systemctl_is_enabled_cmd "$unit" &>/dev/null; then
  1099. debug "Disabling $unit"
  1100. systemctl_disable_cmd "$unit"
  1101. fi
  1102. done
  1103. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1104. [[ -f "$f" ]] && debug "Removing $f" && sudo rm -f "$f"
  1105. done
  1106. SERVICE_TYPE=user setServiceVars "$service";
  1107. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1108. if systemctl_is_active_cmd "$unit" &>/dev/null ||
  1109. systemctl_is_enabled_cmd "$unit" &>/dev/null; then
  1110. debug "Disabling $unit"
  1111. systemctl_disable_cmd "$unit"
  1112. fi
  1113. done
  1114. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1115. [[ -f "$f" ]] && debug "Removing $f" && sudo rm -f "$f"
  1116. done
  1117. systemctl_reload_cmd
  1118. done
  1119. debug "Removing repo files"
  1120. [[ -f "/etc/yum.repos.d/jriver.repo" ]] &&
  1121. sudo rm -f "/etc/yum.repos.d/jriver.repo"
  1122. [[ -f "/etc/apt/sources.list.d/jriver.list" ]] &&
  1123. sudo rm -f "/etc/apt/sources.list.d/jriver.list"
  1124. if [[ "$ID" =~ ^opensuse.* ]]; then
  1125. sudo zypper rr jriver &>/dev/null
  1126. fi
  1127. debug "Removing firewall rules"
  1128. if [[ -x $(command -v firewall-cmd) ]]; then
  1129. if [[ -v debug ]]; then
  1130. debug "firewall_cmd --permanent --remove-service=jriver"
  1131. firewall_cmd --permanent --remove-service=jriver
  1132. debug "firewall_cmd --permanent --delete-service=jriver"
  1133. firewall_cmd --permanent --delete-service=jriver
  1134. debug "firewall_cmd --reload"
  1135. firewall_cmd --reload
  1136. else
  1137. firewall_cmd --permanent --remove-service=jriver &>/dev/null
  1138. firewall_cmd --permanent --delete-service=jriver &>/dev/null
  1139. firewall_cmd --reload &>/dev/null
  1140. fi
  1141. elif [[ -x $(command -v ufw) ]]; then
  1142. firewall_cmd="firewall_cmd delete allow jriver"
  1143. debug "$firewall_cmd" || firewall_cmd+=" &>/dev/null"
  1144. eval "$firewall_cmd"
  1145. [[ -f "/etc/ufw/applications.d/jriver" ]] &&
  1146. sudo rm -f /etc/ufw/applications.d/jriver
  1147. fi
  1148. debug "Uninstalling Media Center package"
  1149. mc_pkg_rm_cmd="pkg_remove $MCPKG"
  1150. debug "$mc_pkg_rm_cmd" || mc_pkg_rm_cmd+=" &>/dev/null"
  1151. if eval "$mc_pkg_rm_cmd"; then
  1152. echo "JRiver Media Center has been completely uninstalled."
  1153. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1154. echo "To remove your rpmbuild output files, run: rm -rf $OUTPUTDIR"
  1155. exit 0
  1156. else
  1157. exit $?
  1158. fi
  1159. }
  1160. tests() {
  1161. # To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1162. exit $?
  1163. }
  1164. main() {
  1165. debug "Running: ${FUNCNAME[0]}"
  1166. declare version_source
  1167. declare -g MCVERSION MVERSION MCPKG
  1168. getOS
  1169. # Some distros need external repos installed for MC libraries
  1170. if [[ "$ID" == "ubuntu|neon" ]]; then
  1171. echo "Adding universe repository"
  1172. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  1173. sudo add-apt-repository universe
  1174. fi
  1175. elif [[ "$ID" == "centos" ]]; then
  1176. echo "Adding EPEL repository"
  1177. installPackage epel-release
  1178. fi
  1179. # Distro-specific commands
  1180. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  1181. pkg_install(){ sudo dnf install -y "$@"; }
  1182. pkg_remove(){ sudo dnf remove -y "$@"; }
  1183. pkg_update(){ sudo dnf makecache; }
  1184. pkg_query(){ rpm -q "$@"; }
  1185. firewall_cmd(){ sudo firewall-cmd "$@"; }
  1186. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  1187. pkg_install(){ sudo apt-get install -y -q0 "$@"; }
  1188. pkg_remove(){ sudo apt-get remove --auto-remove -y -q0 "$@"; }
  1189. pkg_update(){ sudo apt-get update -y -q0; }
  1190. pkg_query(){ dpkg -s "$@"; }
  1191. firewall_cmd(){ sudo ufw "$@"; }
  1192. elif [[ "$ID" =~ ^opensuse.* ]]; then
  1193. pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; }
  1194. pkg_remove(){ sudo zypper --non-interactive -q remove --clean-deps "$@"; }
  1195. pkg_update(){ sudo zypper --non-interactive -q refresh jriver; }
  1196. pkg_query(){ rpm -q "$@"; }
  1197. firewall_cmd(){ sudo firewall-cmd "$@"; }
  1198. fi
  1199. parseInput "$@"
  1200. # Select MC version to work with
  1201. if [[ -v MCVERSION ]]; then
  1202. version_source="user input"
  1203. else
  1204. getLatestVersion
  1205. fi
  1206. [[ ! "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]] && err "Invalid version number" && exit 1
  1207. echo "Using MC version $MCVERSION determined by $version_source"
  1208. [[ "$version_source" != "user input" ]] && echo "To override, use --mcversion"
  1209. # Extract major version number
  1210. MVERSION="${MCVERSION%%.*}"
  1211. # Set target package name
  1212. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  1213. MCPKG="MediaCenter"
  1214. [[ "$version_source" == "user input" ]] && MCPKG="$MCPKG-$MCVERSION"
  1215. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  1216. MCPKG="mediacenter$MVERSION"
  1217. [[ "$version_source" == "user input" ]] && MCPKG="$MCPKG=$MCVERSION"
  1218. fi
  1219. if (( UNINSTALL_SWITCH )); then
  1220. uninstall
  1221. exit $?
  1222. fi
  1223. if (( REPO_INSTALL_SWITCH )); then
  1224. if [[ "$ID" =~ ^opensuse.*$ ]]; then
  1225. echo "A SUSE repository is not yet available."
  1226. echo "Use --install rpm to build and install a SUSE RPM instead."
  1227. exit 1
  1228. fi
  1229. if installMCFromRepo; then
  1230. echo "JRiver Media Center installed successfully"
  1231. else
  1232. err "JRiver Media Center installation failed"
  1233. exit 1
  1234. fi
  1235. symlinkCerts
  1236. restoreLicense
  1237. openFirewall "jriver"
  1238. fi
  1239. if (( DEB_INSTALL_SWITCH )); then
  1240. acquireDeb
  1241. if (( COMPAT_SWITCH )); then
  1242. declare extract_dir && extract_dir="$(mktemp -d)"
  1243. ar x --output "$extract_dir" "$MCDEB"
  1244. tar -xJf "$extract_dir/control.tar.xz" -C "$extract_dir"
  1245. # Remove minimum version specifiers from control file
  1246. sed -i 's/ ([^)]*)//g' "$extract_dir/control"
  1247. sed -i 's/([^)]*)//g' "$extract_dir/control" # MC DEB package error
  1248. tar -cJf "$extract_dir/control.tar.xz" \
  1249. -C "$extract_dir" "control" "postinst"
  1250. declare mcdeb="$MCDEB.compat"
  1251. ar rcs "$mcdeb" "$extract_dir/debian-binary" "$extract_dir/control.tar.xz" "$extract_dir/data.tar.xz"
  1252. rm -rf "$extract_dir"
  1253. fi
  1254. pkg_install_cmd="installPackage --nocheck --nogpgcheck ${mcdeb:-$MCDEB}"
  1255. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  1256. eval "$pkg_install_cmd"
  1257. fi
  1258. if (( RPM_BUILD_SWITCH )); then
  1259. installPackage "wget" "dpkg" "rpm-build"
  1260. acquireDeb
  1261. buildRPM
  1262. fi
  1263. if (( RPM_INSTALL_SWITCH )); then
  1264. #rpm --upgrade "$MCRPM"
  1265. if installPackage --nocheck --nogpgcheck "$MCRPM"; then
  1266. echo "JRiver Media Center installed successfully"
  1267. else
  1268. err "JRiver Media Center installation failed"
  1269. exit 1
  1270. fi
  1271. symlinkCerts
  1272. restoreLicense
  1273. openFirewall "jriver"
  1274. fi
  1275. if (( CREATEREPO_SWITCH )); then
  1276. runCreaterepo
  1277. exit $?
  1278. fi
  1279. if [[ "${#SERVICES[@]}" -gt 0 ]]; then
  1280. declare service
  1281. setDisplay
  1282. for service in "${SERVICES[@]}"; do
  1283. if ! setServiceVars "$service"; then
  1284. continue
  1285. fi
  1286. if ! "service_$service"; then
  1287. if [[ $? -eq 127 ]]; then
  1288. err "Service $service does not exist, check your service name"
  1289. else
  1290. err "Failed to create service: $service"
  1291. fi
  1292. fi
  1293. done
  1294. fi
  1295. # for _container in "${CONTAINERS[@]}"; do
  1296. # if ! "_container_$_container"; then
  1297. # if [[ $? -eq 127 ]]; then
  1298. # err "Container $_container does not exist, check your container name"
  1299. # else
  1300. # err "Failed to create container: $_container"
  1301. # fi
  1302. # fi
  1303. # done
  1304. }
  1305. main "$@"