installJRMC 57 KB

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