installJRMC 50 KB

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