installJRMC 56 KB

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