installJRMC 50 KB

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