installJRMC 60 KB

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