installJRMC 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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. }
  219. #######################################
  220. # Use several methods to determine the latest JRiver MC version
  221. #######################################
  222. getLatestVersion() {
  223. debug "Running: ${FUNCNAME[0]}"
  224. declare -g MCVERSION BASE="buster" # For container method
  225. #declare -g BASE_NEXT="bullseye" # TODO possibly use for fallback to smooth upgrades
  226. declare boardurl="https://yabb.jriver.com/interact/index.php/board,71.0.html" # MC28 (Buster), for fallback webscrape
  227. # Containerized package manager
  228. # TODO but how to determine build distro ($BASE=buster)?
  229. if installPackage --silent buildah &&
  230. cnt=$(buildah from debian:$BASE) &>/dev/null &&
  231. buildah run "$cnt" -- bash -c \
  232. "echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $BASE main' > /etc/apt/sources.list 2>&1" &&
  233. buildah run "$cnt" -- bash -c \
  234. "apt-get update --allow-insecure-repositories &>/dev/null" &&
  235. MCVERSION=$(buildah run "$cnt" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) &&
  236. [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]] &&
  237. VERSION_SOURCE="containerized package manager"; then
  238. buildah rm "$cnt" &>/dev/null
  239. # Webscrape
  240. elif installPackage wget && MCVERSION=$(wget -qO- "$boardurl" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
  241. VERSION_SOURCE="webscrape"
  242. else
  243. MCVERSION="28.0.100"
  244. VERSION_SOURCE="hardcoded version"
  245. err "Warning! Using hardcoded version number"
  246. fi
  247. }
  248. #######################################
  249. # Installs a package using the system package manager
  250. # Arguments:
  251. # One or more package names
  252. # Options:
  253. # --skip-check-installed: Do not check if package is already installed
  254. # --nogpgcheck: Disable GPG checks for RPM based distros
  255. # --silent, -s: Do not report errors (useful if package is not strictly required and errors are noisy)
  256. #######################################
  257. installPackage() {
  258. debug "Running: ${FUNCNAME[0]}" "$@"
  259. declare -a pkg_array install_flags
  260. declare pkg skip_check_installed silent _return pkg_install_cmd
  261. if _input=$(getopt -o +s -l skip-check-installed,nogpgcheck,silent -- "$@"); then
  262. eval set -- "$_input"
  263. while true; do
  264. case "$1" in
  265. --skip-check-installed)
  266. skip_check_installed=1
  267. ;;
  268. --nogpgcheck)
  269. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  270. install_flags+=(--nogpgcheck)
  271. elif [[ "$ID" =~ ^opensuse.* ]]; then
  272. install_flags+=(--allow-unsigned-rpm)
  273. fi
  274. ;;
  275. --silent|-s)
  276. silent=1
  277. ;;
  278. --)
  279. shift
  280. break
  281. ;;
  282. esac
  283. shift
  284. done
  285. else
  286. err "Incorrect options provided"
  287. exit 1
  288. fi
  289. # Aliases
  290. if [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  291. declare -A PKG_ALIASES
  292. PKG_ALIASES["xorg-x11-utils"]="xorg-x11"
  293. PKG_ALIASES["rpm-build"]="rpm"
  294. PKG_ALIASES["createrepo_c"]="createrepo"
  295. PKG_ALIASES["tigervnc-server"]="tigervnc-standalone-server"
  296. fi
  297. for pkg in "$@"; do
  298. if [[ ! -v skip_check_installed && -v PKG_ALIASES[$pkg] ]]; then
  299. pkg=${PKG_ALIASES[$pkg]}
  300. fi
  301. # Check if already installed
  302. if (( skip_check_installed )) || ! (hash $pkg &>/dev/null || pkg_query "$pkg" &>/dev/null); then
  303. pkg_array+=("$pkg")
  304. fi
  305. done
  306. # Install packages from package array
  307. if [[ ${#pkg_array[@]} -ge 1 ]]; then
  308. pkg_install_cmd="pkg_install ${install_flags[*]} ${pkg_array[*]}"
  309. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  310. if ! eval "$pkg_install_cmd" && ! (( silent )); then
  311. err "Failed to install ${pkg_array[*]}. Attempting to continue..."
  312. return 1
  313. fi
  314. fi
  315. return 0
  316. }
  317. #######################################
  318. # Add the JRiver repository files
  319. #######################################
  320. addRepo() {
  321. debug "Running: ${FUNCNAME[0]}"
  322. echo "Adding JRiver repository"
  323. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  324. sudo bash -c 'cat <<- EOF > /etc/yum.repos.d/jriver.repo
  325. [jriver]
  326. name=JRiver Media Center repo by BryanC
  327. baseurl=https://repos.bryanroessler.com/jriver
  328. gpgcheck=0
  329. EOF'
  330. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  331. # MVERSION depends on $BASE unless --mcversion is passed
  332. installPackage --silent wget
  333. declare sources_dir="/etc/apt/sources.list.d"
  334. [[ ! -d "$sources_dir" ]] && sudo mkdir -p "$sources_dir"
  335. sudo bash -c "cat <<- EOF > $sources_dir/mediacenter$MVERSION.list
  336. deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $BASE main
  337. EOF"
  338. #echo "deb [trusted=yes arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $BASE main" > "$sources_dir/mediacenter$MVERSION.list" 2>&1
  339. #sudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" &>/dev/null
  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. echo "Installing JRiver Media Center $MCVERSION from repository."
  351. echo "Future updates will be handled by your package manager."
  352. if ! debug; then
  353. echo "This may take a few minutes to complete."
  354. echo "Use --debug for verbose output."
  355. fi
  356. addRepo
  357. # Update package list
  358. pkg_update_cmd="pkg_update"
  359. debug "$pkg_update_cmd" || pkg_update_cmd+=" &>/dev/null"
  360. if ! eval "$pkg_update_cmd"; then
  361. err "Package update failed!"
  362. exit 1
  363. fi
  364. pkg_install_cmd="installPackage --skip-check-installed --nogpgcheck $MCPKG"
  365. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  366. eval "$pkg_install_cmd"
  367. }
  368. #######################################
  369. # Acquire the source DEB package from JRiver's servers
  370. #######################################
  371. acquireDeb() {
  372. debug "Running: ${FUNCNAME[0]}"
  373. declare -g MCDEB="$OUTPUTDIR/SOURCES/MediaCenter-$MCVERSION-amd64.deb"
  374. # If necessary, create SOURCES dir
  375. [[ ! -d "$OUTPUTDIR/SOURCES" ]] && mkdir -p "$OUTPUTDIR/SOURCES"
  376. # If deb file already exists, skip download
  377. if [[ -f "$MCDEB" ]]; then
  378. echo "Using local DEB file: $MCDEB"
  379. return 0
  380. fi
  381. if [[ -v BETAPASS ]]; then
  382. echo "Checking beta repo..."
  383. if wget -q -O "$MCDEB" \
  384. "https://files.jriver.com/mediacenter/channels/v$MVERSION/beta/$BETAPASS/MediaCenter-$MCVERSION-amd64.deb"; then
  385. echo "Found!"
  386. fi
  387. elif echo "Checking test repo..." && wget -q -O "$MCDEB" \
  388. "https://files.jriver.com/mediacenter/test/MediaCenter-$MCVERSION-amd64.deb"; then
  389. echo "Found!"
  390. # Else check latest repo
  391. elif echo "Checking latest repo..." && wget -q -O "$MCDEB" \
  392. "https://files.jriver.com/mediacenter/channels/v$MVERSION/latest/MediaCenter-$MCVERSION-amd64.deb"; then
  393. echo "Found!"
  394. else
  395. err "Cannot find DEB file."
  396. exit 1
  397. fi
  398. if [[ ! -f "$MCDEB" ]]; then
  399. err "Downloaded DEB file missing or corrupted."
  400. exit 1
  401. fi
  402. }
  403. #######################################
  404. # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  405. #######################################
  406. buildRPM() {
  407. debug "Running: ${FUNCNAME[0]}"
  408. declare id i rpmbuild_cmd
  409. declare -a requires recommends
  410. declare -A dupes
  411. declare -g MCRPM="$OUTPUTDIR/RPMS/x86_64/MediaCenter-$MCVERSION.x86_64.rpm"
  412. # skip rebuilding the rpm if it already exists
  413. if [[ -f "$MCRPM" ]]; then
  414. echo "$MCRPM already exists. Skipping build step."
  415. return 0
  416. fi
  417. [[ ! -d "$OUTPUTDIR/SPECS" ]] && mkdir -p "$OUTPUTDIR/SPECS"
  418. # Use --target parameter override
  419. id="${TARGET:-$ID}"
  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"
  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 "Cancelling uninstall..."
  1073. exit 0
  1074. fi
  1075. debug "Stopping and removing all associated 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. debug "Removing repo files"
  1103. [[ -f "/etc/yum.repos.d/jriver.repo" ]] &&
  1104. sudo rm -f "/etc/yum.repos.d/jriver.repo"
  1105. [[ -f "/etc/apt/sources.list.d/jriver.list" ]] &&
  1106. sudo rm -f "/etc/apt/sources.list.d/jriver.list"
  1107. if [[ "$ID" =~ ^opensuse.* ]]; then
  1108. sudo zypper rr jriver &>/dev/null
  1109. fi
  1110. debug "Removing firewall rules"
  1111. if hash firewall-cmd 2>/dev/null; then
  1112. if [[ -v debug ]]; then
  1113. debug "firewall_cmd --permanent --remove-service=jriver"
  1114. firewall_cmd --permanent --remove-service=jriver
  1115. debug "firewall_cmd --permanent --delete-service=jriver"
  1116. firewall_cmd --permanent --delete-service=jriver
  1117. debug "firewall_cmd --reload"
  1118. firewall_cmd --reload
  1119. else
  1120. firewall_cmd --permanent --remove-service=jriver &>/dev/null
  1121. firewall_cmd --permanent --delete-service=jriver &>/dev/null
  1122. firewall_cmd --reload &>/dev/null
  1123. fi
  1124. elif hash ufw 2>/dev/null; then
  1125. firewall_cmd="firewall_cmd delete allow jriver"
  1126. debug "$firewall_cmd" || firewall_cmd+=" &>/dev/null"
  1127. eval "$firewall_cmd"
  1128. [[ -f "/etc/ufw/applications.d/jriver" ]] &&
  1129. sudo rm -f /etc/ufw/applications.d/jriver
  1130. fi
  1131. debug "Uninstalling Media Center package"
  1132. mc_pkg_rm_cmd="pkg_remove $MCPKG"
  1133. debug "$mc_pkg_rm_cmd" || mc_pkg_rm_cmd+=" &>/dev/null"
  1134. if eval "$mc_pkg_rm_cmd"; then
  1135. echo "JRiver Media Center has been completely uninstalled."
  1136. echo "To remove your library files, run: rm -rf $HOME/.jriver"
  1137. echo "To remove your rpmbuild output files, run: rm -rf $OUTPUTDIR"
  1138. exit 0
  1139. else
  1140. exit $?
  1141. fi
  1142. }
  1143. tests() {
  1144. # To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
  1145. exit $?
  1146. }
  1147. main() {
  1148. debug "Running: ${FUNCNAME[0]}"
  1149. declare -g VERSION_SOURCE MCVERSION MVERSION MCPKG
  1150. getOS
  1151. # Some distros need external repos installed for MC libraries
  1152. if [[ "$ID" == "ubuntu|neon" ]]; then
  1153. echo "Adding universe repository"
  1154. if ! grep ^deb /etc/apt/sources.list|grep -q universe; then
  1155. sudo add-apt-repository universe
  1156. fi
  1157. elif [[ "$ID" == "centos" ]]; then
  1158. echo "Adding EPEL repository"
  1159. installPackage epel-release
  1160. fi
  1161. # Distro-specific commands
  1162. if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
  1163. pkg_install(){ sudo dnf install -y "$@"; }
  1164. pkg_remove(){ sudo dnf remove -y "$@"; }
  1165. pkg_update(){ sudo dnf makecache; }
  1166. pkg_query(){ rpm -q "$@"; }
  1167. firewall_cmd(){ sudo firewall-cmd "$@"; }
  1168. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  1169. pkg_install(){ sudo apt-get install -y -q0 "$@"; }
  1170. pkg_remove(){ sudo apt-get remove --auto-remove -y -q0 "$@"; }
  1171. pkg_update(){ sudo apt-get update -y -q0; }
  1172. pkg_query(){ dpkg -s "$@"; }
  1173. firewall_cmd(){ sudo ufw "$@"; }
  1174. elif [[ "$ID" =~ ^opensuse.* ]]; then
  1175. pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; }
  1176. pkg_remove(){ sudo zypper --non-interactive -q remove --clean-deps "$@"; }
  1177. pkg_update(){ sudo zypper --non-interactive -q refresh jriver; }
  1178. pkg_query(){ rpm -q "$@"; }
  1179. firewall_cmd(){ sudo firewall-cmd "$@"; }
  1180. fi
  1181. parseInput "$@"
  1182. # Select MC version to work with
  1183. if [[ -v MCVERSION ]]; then
  1184. VERSION_SOURCE="user input"
  1185. else
  1186. getLatestVersion
  1187. fi
  1188. [[ ! "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]] && err "Invalid version number" && exit 1
  1189. echo "Using MC version $MCVERSION determined by $VERSION_SOURCE"
  1190. [[ "$VERSION_SOURCE" != "user input" ]] && echo "To override, use --mcversion"
  1191. # Extract major version number
  1192. MVERSION="${MCVERSION%%.*}"
  1193. # Set target package name
  1194. if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
  1195. MCPKG="MediaCenter"
  1196. [[ "$VERSION_SOURCE" == "user input" ]] && MCPKG="$MCPKG-$MCVERSION"
  1197. elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint|neon)$ ]]; then
  1198. MCPKG="mediacenter$MVERSION"
  1199. [[ "$VERSION_SOURCE" == "user input" ]] && MCPKG="$MCPKG=$MCVERSION"
  1200. fi
  1201. if (( UNINSTALL_SWITCH )); then
  1202. uninstall
  1203. exit $?
  1204. fi
  1205. if (( REPO_INSTALL_SWITCH )); then
  1206. if [[ "$ID" =~ ^opensuse.*$ ]]; then
  1207. echo "A SUSE repository is not yet available."
  1208. echo "Use --install rpm to build and install a SUSE RPM instead."
  1209. exit 1
  1210. fi
  1211. if installMCFromRepo; then
  1212. echo "JRiver Media Center installed successfully"
  1213. else
  1214. err "JRiver Media Center installation failed"
  1215. exit 1
  1216. fi
  1217. symlinkCerts
  1218. restoreLicense
  1219. openFirewall "jriver"
  1220. fi
  1221. if (( DEB_INSTALL_SWITCH )); then
  1222. acquireDeb
  1223. if (( COMPAT_SWITCH )); then
  1224. declare extract_dir && extract_dir="$(mktemp -d)"
  1225. ar x --output "$extract_dir" "$MCDEB"
  1226. tar -xJf "$extract_dir/control.tar.xz" -C "$extract_dir"
  1227. # Remove minimum version specifiers from control file
  1228. sed -i 's/ ([^)]*)//g' "$extract_dir/control"
  1229. sed -i 's/([^)]*)//g' "$extract_dir/control" # MC DEB package error
  1230. tar -cJf "$extract_dir/control.tar.xz" \
  1231. -C "$extract_dir" "control" "postinst"
  1232. declare mcdeb="$MCDEB.compat"
  1233. ar rcs "$mcdeb" "$extract_dir/debian-binary" "$extract_dir/control.tar.xz" "$extract_dir/data.tar.xz"
  1234. rm -rf "$extract_dir"
  1235. fi
  1236. pkg_install_cmd="installPackage --skip-check-installed --nogpgcheck ${mcdeb:-$MCDEB}"
  1237. debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
  1238. eval "$pkg_install_cmd"
  1239. fi
  1240. if (( RPM_BUILD_SWITCH )); then
  1241. installPackage "wget" "dpkg" "rpm-build"
  1242. acquireDeb
  1243. buildRPM
  1244. fi
  1245. if (( RPM_INSTALL_SWITCH )); then
  1246. #rpm --upgrade "$MCRPM"
  1247. if installPackage --skip-check-installed --nogpgcheck "$MCRPM"; then
  1248. echo "JRiver Media Center installed successfully"
  1249. else
  1250. err "JRiver Media Center installation failed"
  1251. exit 1
  1252. fi
  1253. symlinkCerts
  1254. restoreLicense
  1255. openFirewall "jriver"
  1256. fi
  1257. if (( CREATEREPO_SWITCH )); then
  1258. runCreaterepo
  1259. exit $?
  1260. fi
  1261. if [[ "${#SERVICES[@]}" -gt 0 ]]; then
  1262. declare service
  1263. for service in "${SERVICES[@]}"; do
  1264. if ! "service_$service"; then
  1265. if [[ $? -eq 127 ]]; then
  1266. err "Service $service does not exist, check your service name"
  1267. else
  1268. err "Failed to create service: $service"
  1269. fi
  1270. fi
  1271. done
  1272. fi
  1273. # for _container in "${CONTAINERS[@]}"; do
  1274. # if ! "_container_$_container"; then
  1275. # if [[ $? -eq 127 ]]; then
  1276. # err "Container $_container does not exist, check your container name"
  1277. # else
  1278. # err "Failed to create container: $_container"
  1279. # fi
  1280. # fi
  1281. # done
  1282. }
  1283. main "$@"