installJRMC 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013
  1. #!/usr/bin/env bash
  2. # @file installJRMC
  3. # @brief Installs JRiver Media Center and associated services
  4. # @description See installJRMC --help or print_help() below for usage
  5. # Copyright (c) 2021-2025 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. # * Interactive (ncurses) mode
  11. # * Additional containerization (createrepo and rpmbuild)
  12. #
  13. # BUGS
  14. # * No createrepo on Mint
  15. #
  16. # NOTES
  17. # * Be careful with tabs in heredocs
  18. # * Avoid execute() for stdout
  19. #
  20. # Allow indirection to match service names to their functions
  21. # shellcheck disable=SC2317
  22. shopt -s extglob
  23. declare -g SCRIPT_VERSION="1.34.4"
  24. declare -g MC_VERSION="34.0.42" # do find all replace (hardcoded fallback)
  25. declare -g MC_REPO="bookworm" # should match the MC_VERSION
  26. declare -g BOARD_ID="89.0" # MC34 board ID for automatic version detection
  27. declare -gi SELF_UPDATE_SWITCH=1 # 0 to disable installJRMC self-update
  28. declare -g SCRIPT_URL="https://git.bryanroessler.com/bryan/installJRMC/raw/master/installJRMC" # self-update URL
  29. # declare -g SCRIPT_URL="https://raw.githubusercontent.com/cryobry/installJRMC/refs/heads/master/installJRMC" # backup URL
  30. declare -gi DEBUG=${DEBUG:-0} # set default debug and allow DEBUG env override (default: disabled)
  31. # @description Print help text
  32. print_help() {
  33. debug "${FUNCNAME[0]}()"
  34. cat <<-EOF
  35. SEE:
  36. README.md for more information
  37. USAGE:
  38. installJRMC [[OPTION] [VALUE]]...
  39. installJRMC defaults to --install=repo on platforms with a JRiver repository and --install=local on all others.
  40. Specifying --build, --createrepo, --service, or --uninstall disables the default install method.
  41. OPTIONS
  42. --install, -i repo|local
  43. repo: Install MC from repository, updates are handled by the system package manager
  44. local: Build and install MC locally from official source package
  45. --build[=suse|fedora|centos|mandriva]
  46. Build RPM from source DEB but do not install
  47. Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
  48. --compat
  49. Build/install MC locally without minimum dependency version requirements
  50. --mcversion VERSION
  51. Specify the MC version, ex. "$MC_VERSION" or "${MC_VERSION%%.*}" (default: latest release)
  52. --arch VERSION
  53. Specify the target MC architecture, ex. "amd64", "arm64", etc (default: host)
  54. --mcrepo REPO
  55. Specify the MC repository, ex. "bullseye", "bookworm", "noble", etc (default: auto)
  56. --outputdir PATH
  57. Generate reusable installJRMC output in this PATH (default: ./output)
  58. --restorefile MJR_FILE
  59. Restore file location for automatic license registration
  60. --betapass PASSWORD
  61. Enter beta team password for access to beta builds
  62. --service, -s SERVICE
  63. See SERVICES section below for a list of possible services to install
  64. --service-type user|system
  65. Starts services at boot (system) or at user login (user) (default: per service, see SERVICES)
  66. --container, -c CONTAINER (TODO: Under construction)
  67. See CONTAINERS section below for a list of possible services to install
  68. --createrepo[=suse|fedora|centos|mandriva]
  69. Build rpm, copy to webroot, and run createrepo.
  70. Use in conjunction with --build=TARGET for crossbuilding repos
  71. Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
  72. --createrepo-webroot PATH
  73. Specify the webroot directory to install the repo (default: /var/www/jriver)
  74. --createrepo-user USER
  75. Specify the web server user if it differs from \$USER
  76. --no-update
  77. Disable automatic installJRMC self-update
  78. --uninstall, -u
  79. Uninstall JRiver MC, remove services, containers, and firewall rules (does not remove library files)
  80. --yes, -y, --auto
  81. Assume yes response to questions
  82. --version, -v
  83. Print installJRMC version and exit
  84. --debug, -d
  85. Print debug output
  86. --help, -h
  87. Print help dialog and exit
  88. SERVICES
  89. jriver-mediaserver (default --service-type=user)
  90. Enable and start a mediaserver systemd service (requires an existing X server)
  91. jriver-mediacenter (user)
  92. Enable and start a mediacenter systemd service (requires an existing X server)
  93. jriver-x11vnc (user)
  94. Enable and start x11vnc for the local desktop (requires an existing X server)
  95. Usually combined with jriver-mediaserver or jriver-mediacenter services
  96. --vncpass and --display are optional (see below)
  97. jriver-xvnc (system)
  98. Enable and start a new Xvnc session running JRiver Media Center
  99. --vncpass PASSWORD
  100. Set the vnc password for x11vnc/Xvnc access. If no password is set, installJRMC
  101. will either use existing password stored in \$HOME/.vnc/jrmc_passwd or else no password
  102. --display DISPLAY
  103. Display to use for x11vnc/Xvnc (default: The current display (x11vnc) or the
  104. current display incremented by 1 (Xvnc))
  105. jriver-createrepo (system)
  106. Install hourly service to build latest MC RPM and run createrepo
  107. EOF
  108. }
  109. # @description Parses user input and sets sensible defaults
  110. # @arg $@ User input
  111. parse_input() {
  112. debug "${FUNCNAME[0]}()" "$@"
  113. declare -gi BUILD_SWITCH REPO_INSTALL_SWITCH LOCAL_INSTALL_SWITCH \
  114. CONTAINER_INSTALL_SWITCH CREATEREPO_SWITCH SNAP_INSTALL_SWITCH \
  115. APPIMAGE_INSTALL_SWITCH COMPAT_SWITCH UNINSTALL_SWITCH YES_SWITCH DEBUG=0
  116. declare -g USER_MC_VERSION USER_MC_MVERSION USER_MC_RELEASE USER_MC_REPO USER_ARCH MJR_FILE \
  117. BETAPASS SERVICE_TYPE VNCPASS USER_DISPLAY BUILD_TARGET CREATEREPO_TARGET
  118. local long_opts short_opts input
  119. long_opts="install:,build::,outputdir:,mcversion:,arch:,mcrepo:,compat,"
  120. long_opts+="restorefile:,betapass:,"
  121. long_opts+="service-type:,service:,services:,"
  122. long_opts+="version,debug,verbose,help,uninstall,yes,auto,no-update,"
  123. long_opts+="createrepo::,createrepo-webroot:,createrepo-user:,"
  124. long_opts+="vncpass:,display:,container:"
  125. short_opts="+i:b::s:c:uyvdh"
  126. if input=$(getopt -o $short_opts -l $long_opts -- "$@"); then
  127. eval set -- "$input"
  128. while true; do
  129. case $1 in
  130. --install|-i) shift;
  131. case $1 in
  132. local|rpm|deb) BUILD_SWITCH=1 LOCAL_INSTALL_SWITCH=1 ;;
  133. repo|remote) REPO_INSTALL_SWITCH=1 ;;
  134. container) CONTAINER_INSTALL_SWITCH=1 ;;
  135. snap) SNAP_INSTALL_SWITCH=1 ;;
  136. appimage) APPIMAGE_INSTALL_SWITCH=1 ;;
  137. *) err "Invalid --install option passed"; exit 1 ;;
  138. esac
  139. ;;
  140. --build|-b) BUILD_SWITCH=1; shift; BUILD_TARGET="$1" ;;
  141. --outputdir) shift; OUTPUT_DIR="$1" ;;
  142. --mcversion) shift;
  143. if [[ $1 =~ ^([0-9]+)(\.[0-9]+\.[0-9]+)?(-([0-9]+))?$ ]]; then
  144. # Major version is required
  145. USER_MC_MVERSION="${BASH_REMATCH[1]}"
  146. # Set default release to 1 if not provided
  147. USER_MC_RELEASE="${BASH_REMATCH[4]:-1}"
  148. # If we get the full version, use it
  149. [[ -n ${BASH_REMATCH[2]} ]] && USER_MC_VERSION="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
  150. # Set major version defaults
  151. case "$USER_MC_MVERSION" in
  152. 34) MC_VERSION="${USER_MC_VERSION:-$MC_VERSION}" MC_REPO="bookworm" BOARD_ID="89.0" ;;
  153. 33) MC_VERSION="${USER_MC_VERSION:-33.0.72}" MC_REPO="bullseye" BOARD_ID="86.0" ;;
  154. 32) MC_VERSION="${USER_MC_VERSION:-32.0.58}" MC_REPO="bullseye" BOARD_ID="83.0" ;;
  155. 31) MC_VERSION="${USER_MC_VERSION:-31.0.83}" MC_REPO="bullseye" BOARD_ID="80.0" ;;
  156. 30) MC_VERSION="${USER_MC_VERSION:-30.0.96}" MC_REPO="buster" BOARD_ID="76.0" ;;
  157. 29) MC_VERSION="${USER_MC_VERSION:-29.0.91}" MC_REPO="buster" BOARD_ID="74.0" ;;
  158. 28) MC_VERSION="${USER_MC_VERSION:-28.0.110}" MC_REPO="buster" BOARD_ID="71.0" ;;
  159. 27) MC_VERSION="${USER_MC_VERSION:-27.0.88}" MC_REPO="buster" BOARD_ID="67.0" ;;
  160. 26) MC_VERSION="${USER_MC_VERSION:-26.0.107}" MC_REPO="jessie" BOARD_ID="64.0" ;;
  161. 25) MC_VERSION="${USER_MC_VERSION:-25.0.114}" MC_REPO="jessie" BOARD_ID="62.0" ;;
  162. 24) MC_VERSION="${USER_MC_VERSION:-24.0.78}" MC_REPO="jessie" BOARD_ID="58.0" ;;
  163. 23) MC_VERSION="${USER_MC_VERSION:-23.0.104}" MC_REPO="jessie" BOARD_ID="54.0" ;;
  164. 22) MC_VERSION="${USER_MC_VERSION:-22.0.102}" MC_REPO="jessie" BOARD_ID="51.0" ;;
  165. 21) MC_VERSION="${USER_MC_VERSION:-21.0.90}" MC_REPO="jessie" BOARD_ID="44.0" ;;
  166. 20) MC_VERSION="${USER_MC_VERSION:-20.0.131}" MC_REPO="jessie" BOARD_ID="35.0";;
  167. *) err "Bad --mcversion"; print_help; exit 1 ;;
  168. esac
  169. else
  170. err "Bad --mcversion"; print_help; exit 1
  171. fi
  172. ;;
  173. --arch) shift; USER_ARCH="$1" ;;
  174. --mcrepo) shift; USER_MC_REPO="$1" ;;
  175. --restorefile) shift; MJR_FILE="$1"; [[ -f $MJR_FILE ]] || err "Specified license $MJR_FILE missing." ;;
  176. --betapass) shift; BETAPASS="$1" ;;
  177. --service-type) shift; SERVICE_TYPE="$1" ;;
  178. --service|-s|--services) shift; SERVICES+=("$1") ;;
  179. --createrepo) shift; CREATEREPO_TARGET="$1"; BUILD_TARGET="$1"
  180. BUILD_SWITCH=1; CREATEREPO_SWITCH=1 ;;
  181. --createrepo-webroot) shift; CREATEREPO_WEBROOT="$1" ;;
  182. --createrepo-user) shift; CREATEREPO_USER="$1" ;;
  183. --vncpass) shift; VNCPASS="$1" ;;
  184. --display) shift; USER_DISPLAY="$1" ;;
  185. --compat) COMPAT_SWITCH=1; BUILD_SWITCH=1 ;;
  186. --no-update) SELF_UPDATE_SWITCH=0 ;;
  187. --container|-c) shift; CONTAINERS+=("$1") ;;
  188. --yes|-y|--auto) YES_SWITCH=1 ;;
  189. --version|-v) echo "Version: $SCRIPT_VERSION"; exit 0 ;;
  190. --debug|-d|--verbose) DEBUG=1 ;;
  191. --help|-h) print_help; exit 0 ;;
  192. --uninstall|-u) UNINSTALL_SWITCH=1 ;;
  193. --) shift; break ;;
  194. esac
  195. shift
  196. done
  197. else
  198. err "Incorrect option provided, see installJRMC --help"; exit 1
  199. fi
  200. # Set some default conditions
  201. if ! ((UNINSTALL_SWITCH || BUILD_SWITCH || CREATEREPO_SWITCH || LOCAL_INSTALL_SWITCH
  202. || CONTAINER_INSTALL_SWITCH || SNAP_INSTALL_SWITCH || APPIMAGE_INSTALL_SWITCH)) &&
  203. [[ ${#SERVICES[@]} -eq 0 && ${#CONTAINERS[@]} -eq 0 ]]; then
  204. debug "Defaulting to --install=repo"
  205. REPO_INSTALL_SWITCH=1
  206. fi
  207. if [[ -n $BETA_PASS ]] && ((REPO_INSTALL_SWITCH)); then
  208. echo "Warning: not all repositories have beta channels"
  209. echo "If the MC package is unavailable, try using --mcrepo to select another repository"
  210. fi
  211. }
  212. # @description Perform OS detection and generate OS-specific functions
  213. # @see parse_input
  214. init() {
  215. debug "${FUNCNAME[0]}()" "$@"
  216. declare -g USER
  217. declare -g SCRIPT_PATH; SCRIPT_PATH=$(readlink -f "${BASH_SOURCE[0]}")
  218. declare -g SCRIPT_DIR; SCRIPT_DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
  219. declare -g OUTPUT_DIR="$SCRIPT_DIR/output"
  220. declare -g CREATEREPO_WEBROOT="/var/www/jriver"
  221. declare -g CREATEREPO_USER="$USER" # can be root
  222. declare -g ID VERSION_ID ARCH MC_ARCH NAME
  223. declare -g MC_MVERSION MC_RELEASE MC_PKG MC_RPM MC_ROOT
  224. declare -ga PKG_INSTALL PKG_REMOVE PKG_UPDATE PKG_QUERY
  225. declare -ga SERVICES CONTAINERS
  226. parse_input "$@"
  227. # Try to save users from themselves
  228. if [[ $EUID -eq 0 ]]; then
  229. err "Running as root but attempting to continue"
  230. ask_ok "Continue as root user (not recommended)?" || exit 1
  231. elif [[ -n $SUDO_USER ]]; then
  232. err "Sudo detected, installJRMC should not be run with sudo but attempting to continue"
  233. ask_ok "Continue as user $SUDO_USER (unsupported and may result in permission issues)?" || exit 1
  234. USER="${SUDO_USER:-$USER}"
  235. fi
  236. # Run the self-updater if enabled
  237. ((SELF_UPDATE_SWITCH)) && update "$@"
  238. fix_permissions "$HOME/.jriver" "$USER"
  239. # Get host information
  240. [[ -f /etc/os-release ]] && source /etc/os-release
  241. # Detect host architecture and translate to MC convention
  242. if ARCH=$(uname -m); then
  243. case $ARCH in
  244. x86_64) MC_ARCH="amd64" ;;
  245. aarch64) MC_ARCH="arm64" ;;
  246. *) MC_ARCH="$ARCH" ;;
  247. esac
  248. else
  249. ARCH="x86_64"
  250. MC_ARCH="amd64"
  251. err "Failed to detect host arch, using default: $ARCH"
  252. fi
  253. echo "Host: $ID $VERSION_ID $ARCH"
  254. # Parse user-provided architecture, allow either convention
  255. if [[ -n $USER_ARCH ]]; then
  256. case $USER_ARCH in
  257. x86_64|amd64) ARCH="x86_64"; MC_ARCH="amd64" ;;
  258. aarch64|arm64) ARCH="aarch64"; MC_ARCH="arm64" ;;
  259. *) ARCH="$USER_ARCH" ;;
  260. esac
  261. fi
  262. # Normalize ID and set host-specific vars
  263. case $ID in
  264. debian|fedora|centos) ;;
  265. rhel|almalinux) ID="centos" ;;
  266. linuxmint|neon|zorin|*ubuntu*) ID="ubuntu" ;;
  267. raspbian) ID="debian" ;;
  268. *mandriva*) ID="mandriva"
  269. if ((REPO_INSTALL_SWITCH)); then
  270. debug "Automatically using --install=local for Mandriva"
  271. REPO_INSTALL_SWITCH=0
  272. BUILD_SWITCH=1
  273. LOCAL_INSTALL_SWITCH=1
  274. fi ;;
  275. manjaro|arch) ID="arch"
  276. if ((REPO_INSTALL_SWITCH)); then
  277. debug "Automatically using --install=local for Arch"
  278. REPO_INSTALL_SWITCH=0
  279. BUILD_SWITCH=1
  280. LOCAL_INSTALL_SWITCH=1
  281. fi ;;
  282. *suse*) ID="suse"
  283. if ((REPO_INSTALL_SWITCH)); then
  284. debug "Automatically using --install=local for SUSE"
  285. REPO_INSTALL_SWITCH=0
  286. BUILD_SWITCH=1
  287. LOCAL_INSTALL_SWITCH=1
  288. fi ;;
  289. *) err "Auto-detecting distro, this is unreliable and --compat may be required"
  290. for cmd in dnf yum apt-get pacman; do
  291. if command -v "$cmd" &>/dev/null; then
  292. case "$cmd" in
  293. dnf) ID="fedora" ;;
  294. yum) ID="centos"; COMPAT_SWITCH=1 ;;
  295. apt-get) ID="ubuntu" ;;
  296. pacman) ID="arch" ;;
  297. esac
  298. break
  299. fi
  300. done
  301. if [[ -z $ID ]]; then
  302. err "OS detection failed!"
  303. if ask_ok "Continue with manual installation?"; then
  304. debug "Automatically using --install=local for unknown distro"
  305. ID="unknown"
  306. REPO_INSTALL_SWITCH=0
  307. BUILD_SWITCH=1
  308. LOCAL_INSTALL_SWITCH=1
  309. else
  310. exit 1
  311. fi
  312. fi ;;
  313. esac
  314. # Set distro-specific package manager commands for normalized IDs
  315. case $ID in
  316. fedora|centos|mandriva)
  317. local rpm_mgr
  318. rpm_mgr=$(command -v dnf &>/dev/null && echo "dnf" || echo "yum")
  319. PKG_INSTALL=(sudo "$rpm_mgr" install -y)
  320. PKG_REMOVE=(sudo "$rpm_mgr" remove -y)
  321. PKG_UPDATE=(sudo "$rpm_mgr" makecache)
  322. PKG_QUERY=(rpm -q)
  323. PKG_INSTALL_LOCAL() { install_mc_rpm; }
  324. ;;
  325. debian|ubuntu)
  326. PKG_INSTALL=(sudo apt-get -f install --install-recommends -y -q0)
  327. PKG_REMOVE=(sudo apt-get remove --auto-remove -y -q0)
  328. PKG_UPDATE=(sudo apt-get update -y -q0)
  329. PKG_QUERY=(dpkg -s)
  330. PKG_INSTALL_LOCAL() { install_mc_deb "$@"; }
  331. ;;
  332. suse)
  333. PKG_INSTALL=(sudo zypper --gpg-auto-import-keys --non-interactive --quiet install --force --force-resolution --replacefiles --no-confirm)
  334. PKG_REMOVE=(sudo zypper --non-interactive --quiet remove --clean-deps)
  335. PKG_UPDATE=(sudo zypper --non-interactive --quiet refresh jriver)
  336. PKG_QUERY=(rpm -q)
  337. PKG_INSTALL_LOCAL() { install_mc_rpm; }
  338. ;;
  339. arch)
  340. PKG_INSTALL=(sudo pacman -Sy --noconfirm)
  341. PKG_REMOVE=(sudo pacman -Rs --noconfirm)
  342. PKG_UPDATE=(sudo pacman -Syy)
  343. PKG_QUERY=(sudo pacman -Qs)
  344. PKG_INSTALL_LOCAL() { install_mc_arch; }
  345. ;;
  346. unknown)
  347. PKG_INSTALL=(:)
  348. PKG_REMOVE=(:)
  349. PKG_UPDATE=(:)
  350. PKG_QUERY=(:)
  351. PKG_INSTALL_LOCAL() { install_mc_generic; }
  352. ;;
  353. esac
  354. # Set default targets
  355. BUILD_TARGET="${BUILD_TARGET:-$ID}"
  356. CREATEREPO_TARGET="${CREATEREPO_TARGET:-$ID}"
  357. # Repo selection
  358. # Match repo to the host on MC31+ unless overriden by user
  359. if [[ $ID =~ debian|ubuntu && "${USER_MC_MVERSION:-${MC_VERSION%%.*}}" -ge 31 ]]; then
  360. MC_REPO=${UBUNTU_CODENAME:-${VERSION_CODENAME:-$MC_REPO}}
  361. fi
  362. MC_REPO="${USER_MC_REPO:-$MC_REPO}" # allow user override
  363. echo "MC source -> target: $MC_REPO $MC_ARCH -> $BUILD_TARGET $ARCH"
  364. # Retrieves the latest MC version number if we need it
  365. if ((BUILD_SWITCH || LOCAL_INSTALL_SWITCH || CREATEREPO_SWITCH)); then
  366. get_latest_mc_version
  367. fi
  368. # Set MC version variables
  369. MC_VERSION="${USER_MC_VERSION:-$MC_VERSION}"
  370. MC_RELEASE="${USER_MC_RELEASE:-1}"
  371. MC_MVERSION="${USER_MC_MVERSION:-${MC_VERSION%%.*}}"
  372. MC_PKG="mediacenter$MC_MVERSION"
  373. MC_RPM="$OUTPUT_DIR/RPMS/$ARCH/mediacenter$MC_MVERSION-$MC_VERSION-$MC_RELEASE.$ARCH.rpm"
  374. MC_ROOT="/usr/lib/jriver/Media Center $MC_MVERSION"
  375. # Generate explicit package name
  376. if [[ -n $USER_MC_VERSION ]]; then
  377. # Append explicit package version when user provides --mcversion
  378. case $ID in
  379. fedora|centos|suse|mandriva) MC_PKG+="-$MC_VERSION" ;;
  380. debian|ubuntu) MC_PKG+="=$MC_VERSION" ;;
  381. esac
  382. fi
  383. }
  384. # @description Determines the latest JRiver MC version using several methods
  385. get_latest_mc_version() {
  386. debug "${FUNCNAME[0]}()"
  387. local mc_version_source
  388. # User --mcversion
  389. if [[ -n $USER_MC_VERSION ]]; then
  390. mc_version_source="user input"
  391. # Containerized package manager
  392. elif create_mc_apt_container &&
  393. MC_VERSION=$(sudo buildah run "$CNT" -- apt-cache policy "mediacenter${USER_MC_MVERSION:-${MC_VERSION%%.*}}" | awk '/Candidate:/ {sub(/-.*/, "", $2); print $2}' | sort -V | tail -n1) &&
  394. execute sudo buildah rm "$CNT" &&
  395. [[ $MC_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  396. mc_version_source="containerized package manager"
  397. # Fallback to webscrape
  398. elif MC_VERSION=$(download "https://yabb.jriver.com/interact/index.php/board,$BOARD_ID.html" "-" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1) &&
  399. [[ $MC_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  400. mc_version_source="webscrape"
  401. # Fallback to hardcoded value
  402. else
  403. mc_version_source="hardcoded"
  404. echo "Warning! Using hardcoded version number"
  405. fi
  406. echo "Selected MC version $MC_VERSION from the $MC_REPO repo (via $mc_version_source)"
  407. }
  408. # @description Installs a package using the system package manager
  409. # @arg $1 array One or more package names
  410. # @option --no-install-check Do not check if package is already installed
  411. # @option --no-gpg-check Disable GPG checks for RPM based distros
  412. # @option --allow-downgrades Useful for installing specific MC versions
  413. # @option --silent | -s Do not print errors (useful for optional packages)
  414. install_package() {
  415. debug "${FUNCNAME[0]}()" "$@"
  416. local -a pkg_array install_flags
  417. local -A pkg_aliases
  418. local input pkg _pkg
  419. local -i no_install_check=0 allow_downgrades=0 silent=0 refresh=0 no_gpg_check=0 reinstall=0
  420. local long_opts="no-install-check,allow-downgrades,no-gpg-check,refresh,reinstall,silent"
  421. local -a pkg_install=("${PKG_INSTALL[@]}")
  422. input=$(getopt -o +s -l "$long_opts" -- "$@") || { err "Incorrect options provided"; exit 1; }
  423. eval set -- "$input"
  424. while true; do
  425. case $1 in
  426. --no-install-check) no_install_check=1 ;;
  427. --allow-downgrades) allow_downgrades=1 ;;
  428. --no-gpg-check) no_gpg_check=1 ;;
  429. --refresh) refresh=1 ;;
  430. --reinstall) reinstall=1 ;;
  431. --silent|-s) silent=1 ;;
  432. --) shift; break ;;
  433. esac
  434. shift
  435. done
  436. # Define distribution-specific package aliases
  437. case $ID in
  438. debian|ubuntu) pkg_aliases=(
  439. [rpm-build]="rpm"
  440. [createrepo_c]="createrepo"
  441. [tigervnc-server]="tigervnc-standalone-server"
  442. ) ;;
  443. suse) pkg_aliases=(
  444. [buildah]="buildah fuse-overlayfs"
  445. ) ;;
  446. mandriva) pkg_aliases=(
  447. [dpkg]="dpkg gnutar"
  448. ) ;;
  449. esac
  450. # Filter out already installed packages to create pkg_array
  451. for pkg in "$@"; do
  452. # Use alias if present, otherwise just pkg itself
  453. pkg_names=("$pkg")
  454. if [[ -v pkg_aliases[$pkg] ]]; then
  455. debug "Aliasing $pkg to ${pkg_aliases[$pkg]}"
  456. IFS=' ' read -ra pkg_names <<< "${pkg_aliases[$pkg]}"
  457. fi
  458. for p in "${pkg_names[@]}"; do
  459. if (( no_install_check )) ||
  460. ! { command -v "$p" &>/dev/null || "${PKG_QUERY[@]}" "$p" &>/dev/null; }; then
  461. pkg_array+=("$p")
  462. else
  463. debug "$p is already installed, skipping installation"
  464. fi
  465. done
  466. done
  467. # Generate installation flags based on the distribution
  468. case $ID in
  469. debian|ubuntu)
  470. ((allow_downgrades)) && install_flags+=(--allow-downgrades)
  471. ((reinstall)) && install_flags+=(--reinstall) ;;
  472. fedora|centos|mandriva)
  473. ((allow_downgrades)) && install_flags+=(--allowerasing)
  474. ((no_gpg_check)) && install_flags+=(--nogpgcheck)
  475. ((refresh)) && install_flags+=(--refresh)
  476. # Only add reinstall flag for mediacenter package
  477. if ((reinstall)) && [[ ${#pkg_array[@]} -eq 1 ]] && "${PKG_QUERY[@]}" "mediacenter$MC_MVERSION" &>/dev/null; then
  478. pkg_install=("${pkg_install[@]/install/reinstall}")
  479. fi
  480. ;;
  481. suse)
  482. ((no_gpg_check)) && install_flags+=(--allow-unsigned-rpm) ;;
  483. esac
  484. # Install packages
  485. if [[ ${#pkg_array[@]} -gt 0 ]]; then
  486. if ! execute "${pkg_install[@]}" "${install_flags[@]}" "${pkg_array[@]}"; then
  487. ((silent)) || err "Failed to install ${pkg_array[*]}"
  488. return 1
  489. fi
  490. fi
  491. return 0
  492. }
  493. # @description install host-specific external repos
  494. install_external_repos() {
  495. debug "${FUNCNAME[0]}()"
  496. case $ID in
  497. ubuntu)
  498. if ! grep -E '^deb|^Components' /etc/apt/sources.list /etc/apt/sources.list.d/* | grep -q universe; then
  499. echo "Adding universe repository"
  500. if ! execute sudo add-apt-repository -y universe; then
  501. err "Adding universe repository failed"
  502. fi
  503. fi
  504. ;;
  505. centos)
  506. if ! command -v dpkg &>/dev/null; then
  507. echo "Adding EPEL repository"
  508. if ! install_package epel-release; then
  509. # If epel-release is not available, install it manually
  510. install_package --no-install-check \
  511. "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${VERSION_ID%%.*}.noarch.rpm"
  512. fi
  513. fi
  514. if ! "${PKG_QUERY[@]}" rpmfusion-free-release &>/dev/null; then
  515. echo "Installing the RPMFusion repository"
  516. install_package --no-install-check \
  517. "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-${VERSION_ID%%.*}.noarch.rpm"
  518. fi
  519. # Install mesa-va-drivers-freeworld separately from the RPM using dnf swap
  520. # install_mesa_freeworld # no longer provided by RPMFusion for EL9, etc.
  521. ;;
  522. fedora)
  523. if ! "${PKG_QUERY[@]}" rpmfusion-free-release &>/dev/null; then
  524. echo "Installing the RPMFusion repository"
  525. install_package --no-install-check \
  526. "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
  527. fi
  528. ;;
  529. suse) : # TODO may be needed if X11_XOrg is made unavailable in default repos
  530. # if ! zypper repos | grep -q "X11_XOrg"; then
  531. # echo "Installing the X11 repository"
  532. # execute sudo zypper --non-interactive --quiet addrepo \
  533. # "https://download.opensuse.org/repositories/X11:/XOrg/${NAME// /_}/X11:XOrg.repo"
  534. # execute sudo zypper --non-interactive --quiet refresh
  535. # fi
  536. ;;
  537. mandriva)
  538. local branch
  539. branch=$(grep ^PRETTY_NAME= /etc/os-release | tr -d '"' | rev | cut -d' ' -f1 | rev | tr '[:upper:]' '[:lower:]')
  540. execute sudo dnf config-manager --set-enabled "${branch}-${ARCH}-extra"
  541. ;;
  542. esac
  543. }
  544. # @description Installs mesa-va-drivers-freeworld on Fedora
  545. install_mesa_freeworld() {
  546. debug "${FUNCNAME[0]}()"
  547. local pkg freeworld_pkg
  548. case $ID in
  549. fedora)
  550. for pkg in mesa-va-drivers mesa-vdpau-drivers mesa-vulkan-drivers; do
  551. freeworld_pkg="${pkg}-freeworld"
  552. if ! "${PKG_QUERY[@]}" "$freeworld_pkg" &>/dev/null; then
  553. if "${PKG_QUERY[@]}" "$pkg" &>/dev/null; then
  554. if ! execute sudo dnf swap -y "$pkg" "$freeworld_pkg"; then
  555. err "Package swap failed for $pkg!"
  556. fi
  557. else
  558. "${PKG_INSTALL[@]}" "$freeworld_pkg"
  559. fi
  560. fi
  561. done
  562. ;;
  563. esac
  564. }
  565. # @description Installs JRiver Media Center from a remote repository
  566. install_mc_repo() {
  567. debug "${FUNCNAME[0]}()"
  568. local repo_file repo_text channel
  569. case $ID in
  570. fedora|centos)
  571. repo_file="/etc/yum.repos.d/jriver.repo"
  572. read -r -d '' repo_text <<-EOF
  573. [jriver]
  574. name=JRiver Media Center by BryanC
  575. baseurl=https://repos.bryanroessler.com/jriver
  576. gpgcheck=0
  577. EOF
  578. ;;
  579. debian|ubuntu)
  580. [[ -n $BETAPASS ]] && channel="beta" || channel="latest"
  581. local major_version="${VERSION_ID%%.*}"
  582. local keyfile="/usr/share/keyrings/jriver-com-archive-keyring.gpg"
  583. if [[ ($ID == "ubuntu" && $major_version -ge 24) ||
  584. ($ID == "debian" && (-z $major_version || $major_version -ge 12)) ]]; then
  585. if [[ $channel == "beta" ]]; then
  586. repo_file="/etc/apt/sources.list.d/jriver-beta.sources"
  587. else
  588. repo_file="/etc/apt/sources.list.d/jriver.sources"
  589. fi
  590. # Remove deprecated repo files
  591. old_repo_files=(
  592. "/etc/apt/sources.list.d/jriver.list"
  593. "/etc/apt/sources.list.d/jriver-beta.list"
  594. "/etc/apt/sources.list.d/jriver_beta.list"
  595. )
  596. for f in "${old_repo_files[@]}"; do
  597. [[ -f $f ]] && execute sudo rm -f "$f"
  598. done
  599. read -r -d '' repo_text <<-EOF
  600. Types: deb
  601. URIs: https://dist.jriver.com/$channel/mediacenter/
  602. Signed-By: $keyfile
  603. Suites: $MC_REPO
  604. Components: main
  605. Architectures: amd64 armhf arm64
  606. EOF
  607. else
  608. if [[ $channel == "beta" ]]; then
  609. execute sudo rm -f "/etc/apt/sources.list.d/jriver_beta.list"
  610. repo_file="/etc/apt/sources.list.d/jriver-beta.list"
  611. else
  612. repo_file="/etc/apt/sources.list.d/jriver.list"
  613. fi
  614. repo_text="deb [signed-by=$keyfile arch=amd64,armhf,arm64] https://dist.jriver.com/$channel/mediacenter/ $MC_REPO main"
  615. fi
  616. echo "Installing JRiver Media Center GPG key"
  617. download "https://dist.jriver.com/mediacenter@jriver.com.gpg.key" "-" |
  618. gpg --dearmor | sudo tee "$keyfile" &>/dev/null
  619. ;;
  620. *)
  621. err "An MC repository for $ID is not yet available"
  622. err "Use --install=local to install MC on $ID"
  623. return 1
  624. ;;
  625. esac
  626. # Remove existing repository file if it exists
  627. [[ -f $repo_file ]] && execute sudo rm -f "$repo_file"
  628. echo "Adding MC repository file: $repo_file"
  629. debug "$repo_text"
  630. sudo tee "$repo_file" &>/dev/null <<< "$repo_text"
  631. # Add older repository for libwebkit2gtk-4.0-37, etc, on newer Debian/Ubuntu
  632. if add_temp_repo; then
  633. trap 'execute sudo rm -f "$TEMP_REPO_FILE"' EXIT
  634. else
  635. err "Failed to add temporary repository"
  636. return 1
  637. fi
  638. execute "${PKG_UPDATE[@]}" || { err "Package update failed!"; return 1; }
  639. echo "Installing $MC_PKG package"
  640. if ! install_package \
  641. --no-install-check \
  642. --allow-downgrades \
  643. --no-gpg-check \
  644. --reinstall \
  645. "$MC_PKG"; then
  646. err "Package install failed!"
  647. return 1
  648. fi
  649. # Unset the trap and remove temporary legacy repository
  650. trap - EXIT
  651. [[ -f $TEMP_REPO_FILE ]] && execute sudo rm -f "$TEMP_REPO_FILE"
  652. return 0
  653. }
  654. # @description Acquires the source DEB package from JRiver
  655. acquire_deb() {
  656. debug "${FUNCNAME[0]}()"
  657. declare -g MC_DEB MC_SOURCE
  658. local fname mnt
  659. [[ -d $OUTPUT_DIR/SOURCES ]] || execute mkdir -p "$OUTPUT_DIR/SOURCES"
  660. # Usually JRiver excludes the release number from the filename
  661. # but in some cases (test builds) it may be included
  662. if [[ $MC_RELEASE -gt 1 ]]; then
  663. fname="MediaCenter-$MC_VERSION-$MC_RELEASE-$MC_ARCH.deb"
  664. else
  665. fname="MediaCenter-$MC_VERSION-$MC_ARCH.deb"
  666. fi
  667. MC_DEB="$OUTPUT_DIR/SOURCES/$fname"
  668. MC_SOURCE="https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/$fname"
  669. # If deb file already exists, skip download
  670. if [[ -f $MC_DEB ]]; then
  671. if [[ $(stat -c%s "$MC_DEB") -lt 10000000 ]]; then
  672. echo "Removing existing DEB under 10MB: $MC_DEB"
  673. execute rm -f "$MC_DEB"
  674. else
  675. echo "Using existing DEB: $MC_DEB"
  676. return 0
  677. fi
  678. fi
  679. # Download the deb file using the containerized package manager
  680. if ! { create_mc_apt_container "apt-get download --allow-unauthenticated mediacenter$MC_MVERSION &>/dev/null" &&
  681. mnt="$(sudo buildah mount "$CNT")" &&
  682. execute sudo find "$mnt" -maxdepth 1 -type f -name "*.deb" -exec cp {} "$MC_DEB" \; &&
  683. [[ -f $MC_DEB ]] &&
  684. execute sudo buildah umount "$CNT" &&
  685. execute sudo buildah rm "$CNT"; }; then
  686. debug "Failed to download DEB using containerized package manager"
  687. echo "Using legacy download method"
  688. # Define the repository search order
  689. local -a repos
  690. [[ -n $BETAPASS ]] && repos=("https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/beta/$BETAPASS/$fname")
  691. repos+=(
  692. "https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/$fname"
  693. "https://files.jriver-cdn.com/mediacenter/test/$fname")
  694. # Loop through the repositories and attempt to download
  695. for repo in "${repos[@]}"; do
  696. echo -n "$repo --> "
  697. if download "$repo" "$MC_DEB"; then
  698. echo "Found!"
  699. MC_SOURCE="$repo"
  700. break
  701. fi
  702. echo "Not found"
  703. done
  704. fi
  705. # Return if the download was successful
  706. [[ -f $MC_DEB ]]
  707. }
  708. # @description Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
  709. build_rpm() {
  710. debug "${FUNCNAME[0]}()"
  711. local i rpmbuild_cmd stub
  712. local -a requires recommends
  713. local spec_file="$OUTPUT_DIR/SPECS/mediacenter$MC_MVERSION-$MC_VERSION-$MC_RELEASE-$BUILD_TARGET-$ARCH.spec"
  714. # skip rebuilding the rpm if it already exists
  715. debug "Checking for existing MC RPM: $MC_RPM"
  716. if [[ -f $MC_RPM && -f $spec_file ]]; then
  717. echo "Skipping build step: .spec and ouput RPM already exist"
  718. debug "RPM .spec file: $spec_file"
  719. debug "RPM: $MC_RPM"
  720. echo "Remove either to force rebuild"
  721. return 0
  722. fi
  723. # Load deb dependencies into array
  724. IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MC_DEB" Depends)"
  725. IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MC_DEB" Recommends)"
  726. # Clean up formatting
  727. requires=("${requires[@]%%|*}")
  728. requires=("${requires[@]/?:/}")
  729. requires=("${requires[@]# }")
  730. requires=("${requires[@]% }")
  731. requires=("${requires[@]//\(/}")
  732. requires=("${requires[@]//)/}")
  733. recommends=("${recommends[@]%%|*}")
  734. recommends=("${recommends[@]/?:/}")
  735. recommends=("${recommends[@]# }")
  736. recommends=("${recommends[@]% }")
  737. recommends=("${recommends[@]//\(/}")
  738. recommends=("${recommends[@]//)/}")
  739. # Translate package names
  740. case $BUILD_TARGET in
  741. fedora|centos)
  742. requires=("${requires[@]/libc6/glibc}")
  743. requires=("${requires[@]/libasound2/alsa-lib}")
  744. requires=("${requires[@]/libuuid1/libuuid}")
  745. requires=("${requires[@]/libx11-6/libX11}")
  746. requires=("${requires[@]/libxext6/libXext}")
  747. requires=("${requires[@]/libxcb1*/libxcb}") # TODO Remove minimum version for MC31 (*)
  748. requires=("${requires[@]/libxau6/libXau}")
  749. requires=("${requires[@]/libxdmcp6/libXdmcp}")
  750. requires=("${requires[@]/libstdc++6/libstdc++}")
  751. requires=("${requires[@]/libgtk-3-0/gtk3}")
  752. requires=("${requires[@]/libegl1/mesa-libEGL}")
  753. requires=("${requires[@]/libgl1/mesa-libGL}")
  754. requires=("${requires[@]/libgles2/libglvnd-gles}")
  755. requires=("${requires[@]/libgbm1/mesa-libgbm}")
  756. requires=("${requires[@]/libegl-mesa0/mesa-libEGL}")
  757. requires=("${requires[@]/libvulkan1/vulkan-loader}")
  758. requires=("${requires[@]/libpango1.0-0/pango}")
  759. requires=("${requires[@]/libpango-1.0-0/pango}")
  760. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  761. requires=("${requires[@]/libpangox-1.0-0/pango}")
  762. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  763. requires=("${requires[@]/libnss3/nss}")
  764. requires=("${requires[@]/libnspr4/nspr}")
  765. requires=("${requires[@]/libgomp1/libgomp}")
  766. requires=("${requires[@]/libfribidi0/fribidi}")
  767. requires=("${requires[@]/libfontconfig1/fontconfig}")
  768. requires=("${requires[@]/libfreetype6/freetype}")
  769. requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
  770. requires=("${requires[@]/libva2/libva}")
  771. requires=("${requires[@]/libva-drm2/libva}")
  772. requires=("${requires[@]/libepoxy0/libepoxy}")
  773. requires=("${requires[@]/liblcms2-2/lcms2}")
  774. requires=("${requires[@]/libwebkit2gtk-4.0*/webkit2gtk4.0}")
  775. requires=("${requires[@]/libwebkit2gtk-4.1*/webkit2gtk4.1}")
  776. requires=("${requires[@]/libsdbus-c++1/sdbus-cpp}")
  777. recommends=("${recommends[@]/fdkaac/fdk-aac-free}")
  778. recommends+=("mesa-va-drivers-freeworld|mesa-va-drivers")
  779. recommends+=("mesa-vulkan-drivers-freeworld|mesa-vulkan-drivers")
  780. recommends+=("mesa-vdpau-driver-freeworld|mesa-vdpau-driver")
  781. ;;
  782. suse)
  783. requires=("${requires[@]/libc6/glibc}")
  784. requires=("${requires[@]/libasound2/alsa-lib}")
  785. requires=("${requires[@]/libx11-6/libX11-6}")
  786. requires=("${requires[@]/libxext6/libXext6}")
  787. requires=("${requires[@]/libxdmcp6/libXdmcp6}")
  788. requires=("${requires[@]/libgtk-3-0/gtk3}")
  789. requires=("${requires[@]/libgl1/Mesa-libGL1}")
  790. requires=("${requires[@]/libpango-1.0-0/pango}")
  791. requires=("${requires[@]/libpangoft2-1.0-0/pango}")
  792. requires=("${requires[@]/libpangox-1.0-0/pango}")
  793. requires=("${requires[@]/libpangoxft-1.0-0/pango}")
  794. requires=("${requires[@]/libnss3/mozilla-nss}")
  795. requires=("${requires[@]/libnspr4/mozilla-nspr}")
  796. requires=("${requires[@]/libfribidi0/fribidi}")
  797. requires=("${requires[@]/libfontconfig1/fontconfig}")
  798. requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
  799. requires=("${requires[@]/libwebkit2gtk-4.0*/libwebkit2gtk-4_0-37}")
  800. requires=("${requires[@]/libwebkit2gtk-4.1*/libwebkit2gtk-4_1-0}")
  801. for i in "${!requires[@]}"; do
  802. [[ ${requires[$i]} == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
  803. [[ ${requires[$i]} == "libsdbus-c++1" ]] && unset -v 'requires[i]'
  804. done
  805. recommends+=(libvulkan1)
  806. recommends+=(libvulkan_intel)
  807. recommends+=(libvulkan_radeon)
  808. recommends+=(libvulkan_nouveau)
  809. ;;
  810. mandriva)
  811. requires=("${requires[@]/libc6/glibc}")
  812. requires=("${requires[@]/libasound2/lib64asound2}")
  813. requires=("${requires[@]/libuuid1/lib64uuid1}")
  814. requires=("${requires[@]/libx11-6/lib64x11_6}")
  815. requires=("${requires[@]/libxext6/lib64xext6}")
  816. requires=("${requires[@]/libxcb1/lib64xcb1}")
  817. requires=("${requires[@]/libxdmcp6/lib64xdmcp6}")
  818. requires=("${requires[@]/libstdc++6/lib64stdc++6}")
  819. requires=("${requires[@]/libgtk-3-0/lib64gtk3_0}")
  820. requires=("${requires[@]/libgl1/lib64GL1}")
  821. requires=("${requires[@]/libgles2/lib64GLESv2_2}")
  822. requires=("${requires[@]/libegl-mesa0/lib64EGL_mesa0}")
  823. requires=("${requires[@]/libpango1.0-0/lib64pango1.0_0}")
  824. requires=("${requires[@]/libpango-1.0-0/lib64pango1.0_0}")
  825. requires=("${requires[@]/libpangoft2-1.0-0/lib64pangoft2_1.0_0}")
  826. requires=("${requires[@]/libpango-cairo-1.0-0/lib64pangocairo1.0_0}")
  827. requires=("${requires[@]/libpangoxft-1.0-0/lib64pangoxft1.0_0}")
  828. requires=("${requires[@]/libnss3/lib64nss3}")
  829. requires=("${requires[@]/libnspr4/lib64nspr4}")
  830. requires=("${requires[@]/libgomp1/lib64gomp1}")
  831. requires=("${requires[@]/libfribidi0/lib64fribidi0}")
  832. requires=("${requires[@]/libfontconfig1/lib64fontconfig}")
  833. requires=("${requires[@]/libfreetype6/lib64freetype6}")
  834. requires=("${requires[@]/libharfbuzz0b/lib64harfbuzz}")
  835. requires=("${requires[@]/libgbm1/lib64gbm1}")
  836. requires=("${requires[@]/libva2/lib64va2}")
  837. requires=("${requires[@]/libva-drm2/lib64va-drm2}")
  838. requires=("${requires[@]/libvulkan1/lib64vulkan1}")
  839. requires=("${requires[@]/mesa-vulkan-drivers/lib64dri-drivers}")
  840. requires=("${requires[@]/vulkan-icd/vulkan-loader}")
  841. requires=("${requires[@]/libwebkit2gtk-4.1-0/lib64webkit2gtk4.1}")
  842. recommends=("${recommends[@]/musepack-tools/mppenc}")
  843. for i in "${!recommends[@]}"; do
  844. [[ ${recommends[$i]} == "fdkaac" ]] && unset -v 'recommends[i]'
  845. done
  846. ;;
  847. esac
  848. # Convert array to newline delim'd string (for heredoc)
  849. printf -v requires "Requires: %s\n" "${requires[@]}"
  850. printf -v recommends "Recommends: %s\n" "${recommends[@]}"
  851. # Strip last newline
  852. requires="${requires%?}"
  853. recommends="${recommends%?}"
  854. if ((COMPAT_SWITCH)); then
  855. # Strip minimum versions
  856. requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
  857. fi
  858. # Exclude MC stub executable <= MC31
  859. if [[ $MC_MVERSION -le 31 ]]; then
  860. stub=""
  861. else
  862. stub="%{_bindir}/mc$MC_MVERSION"
  863. fi
  864. # Create spec file
  865. cat <<-EOF > "$spec_file"
  866. Name: mediacenter$MC_MVERSION
  867. Version: $MC_VERSION
  868. Release: $MC_RELEASE
  869. Summary: JRiver Media Center
  870. Group: Applications/Media
  871. Source0: $MC_SOURCE
  872. %define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}-%%{release}.%%{ARCH}.rpm
  873. AutoReq: 0
  874. $requires
  875. $recommends
  876. Conflicts: MediaCenter
  877. Provides: mediacenter$MC_MVERSION
  878. License: Copyright 1998-$(date +%Y), JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
  879. URL: https://www.jriver.com/
  880. %define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
  881. %description
  882. Media Center is more than a world class player.
  883. %global __os_install_post %{nil}
  884. %prep
  885. %build
  886. %install
  887. dpkg -x %{S:0} %{buildroot}
  888. %post -p /sbin/ldconfig
  889. %postun -p /sbin/ldconfig
  890. %files
  891. %{_bindir}/mediacenter$MC_MVERSION
  892. $stub
  893. %{_libdir}/jriver
  894. %{_datadir}
  895. %exclude %{_datadir}/applications/media_center_packageinstaller_$MC_MVERSION.desktop
  896. /etc/security/limits.d/*
  897. EOF
  898. # Run rpmbuild
  899. echo "Building $MC_RPM, this may take some time"
  900. rpmbuild_cmd=(
  901. rpmbuild
  902. --define="_topdir $OUTPUT_DIR"
  903. --define="_libdir /usr/lib"
  904. --target="$ARCH"
  905. -bb
  906. "$spec_file"
  907. )
  908. execute "${rpmbuild_cmd[@]}" && [[ -f $MC_RPM ]]
  909. }
  910. # @description Installs Media Center via DEB package w/ optional compatability fixes
  911. install_mc_deb() {
  912. debug "${FUNCNAME[0]}()" "$@"
  913. if ((COMPAT_SWITCH)); then
  914. local extract_dir; extract_dir="$(mktemp -d)"
  915. pushd "$extract_dir" &>/dev/null || return
  916. command -v ar &>/dev/null || { install_package binutils || return 1; }
  917. execute ar x "$MC_DEB"
  918. execute tar xJf "control.tar.xz"
  919. # Remove minimum version specifiers from control file
  920. execute sed -i 's/ ([^)]*)//g' control
  921. # Remove libwebkit2gtk and their fantastic package versioning strategy
  922. execute sed -E -i 's/,[[:space:]]*libwebkit2gtk[^,]*(,|\?)?//g' control
  923. # TODO workaround for legacy ZorinOS
  924. if [[ $ID == "ubuntu" && ${VERSION_ID%.*} -le 16 ]] &&
  925. grep -q zorin /etc/os-release; then
  926. execute sed -i 's/libva2/libva1/g' control
  927. fi
  928. execute tar -cJf "control.tar.xz" "control" "postinst"
  929. declare -g MC_DEB="${MC_DEB/.deb/.compat.deb}"
  930. execute ar rcs "$MC_DEB" "debian-binary" "control.tar.xz" "data.tar.xz"
  931. popd &>/dev/null || return
  932. execute rm -rf "$extract_dir"
  933. fi
  934. # Add older repository for libwebkit2gtk-4.0-37, etc, on newer Debian/Ubuntu
  935. if add_temp_repo; then
  936. trap 'execute sudo rm -f "$TEMP_REPO_FILE"' EXIT
  937. else
  938. err "Failed to add temporary repository"
  939. return 1
  940. fi
  941. execute "${PKG_UPDATE[@]}" || { err "Package update failed!"; return 1; }
  942. # Copy the DEB to a temporary file so _apt can read it
  943. debug "Creating temporary deb file owned by _apt"
  944. local temp_deb
  945. temp_deb=$(mktemp --suffix=.deb)
  946. execute sudo cp "$MC_DEB" "$temp_deb"
  947. id _apt &>/dev/null && execute sudo chown _apt "$temp_deb"
  948. # Use --reinstall to make sure local package is installed over repo package
  949. if ! install_package \
  950. --no-install-check \
  951. --no-gpg-check \
  952. --allow-downgrades \
  953. --reinstall \
  954. "$temp_deb"; then
  955. err "Local MC DEB installation failed"
  956. if ask_ok "Remove source DEB and retry"; then
  957. execute sudo rm -f "$MC_DEB" "$temp_deb"
  958. exec "$SCRIPT_PATH" "$@" "--no-update"
  959. fi
  960. fi
  961. # Unset the trap and remove temporary legacy repository
  962. trap - EXIT
  963. [[ -f $TEMP_REPO_FILE ]] && execute sudo rm -f "$TEMP_REPO_FILE"
  964. execute sudo rm -f "$temp_deb"
  965. return 0
  966. }
  967. # @description Installs MC via RPM package
  968. install_mc_rpm() {
  969. debug "${FUNCNAME[0]}()"
  970. install_package --no-install-check --no-gpg-check --allow-downgrades --reinstall "$MC_RPM"
  971. }
  972. # @description Installs Media Center generically for unsupported OSes
  973. install_mc_generic() {
  974. debug "${FUNCNAME[0]}()"
  975. local extract_dir
  976. local -a raw_files
  977. echo "Using generic installation method"
  978. extract_dir="$(mktemp -d)"
  979. pushd "$extract_dir" &>/dev/null || return
  980. execute ar x "$MC_DEB"
  981. execute tar xJf "control.tar.xz"
  982. echo "You must install the following dependencies manually:"
  983. grep -i "Depends:" control
  984. readarray -t raw_files < <(tar xJvf data.tar.xz)
  985. # Output to log file
  986. for f in "${raw_files[@]/#./}"; do
  987. echo "$f" >> "$SCRIPT_DIR/.uninstall"
  988. done
  989. # Manually install files
  990. for f in "${raw_files[@]}"; do
  991. execute sudo cp -a "$f" "${f/#./}"
  992. done
  993. popd &>/dev/null || return
  994. execute rm -rf "$extract_dir"
  995. return 0
  996. }
  997. # @description Installs MC via PKGBUILD
  998. install_mc_arch() {
  999. debug "${FUNCNAME[0]}()"
  1000. [[ -d $OUTPUT_DIR/PKGBUILD ]] || execute mkdir -p "$OUTPUT_DIR/PKGBUILD"
  1001. cat <<-EOF > "$OUTPUT_DIR/PKGBUILD/mediacenter.pkgbuild"
  1002. pkgname=mediacenter$MC_MVERSION
  1003. pkgver=$MC_VERSION
  1004. pkgrel=$MC_RELEASE
  1005. pkgdesc="The Most Comprehensive Media Software"
  1006. arch=("$ARCH")
  1007. url="https://www.jriver.com/"
  1008. license=('custom')
  1009. depends=('alsa-lib' 'ca-certificates' 'gtk3' 'gcc-libs' 'libx11' 'libxext' 'libxcb' 'libxau' 'libxdmcp' 'util-linux' 'mesa-libgl' 'webkit2gtk')
  1010. optdepends=(
  1011. 'mesa-libgl: nouveau video support'
  1012. 'nvidia-libgl: nvidia video support'
  1013. 'nvidia-utils: nvidia vulkan support'
  1014. 'vulkan-intel: intel vulkan support'
  1015. 'vulkan-radeon: amd vulkan support'
  1016. 'vorbis-tools: ogg vorbis support'
  1017. 'musepack-tools: musepack support'
  1018. )
  1019. source=("$MC_SOURCE")
  1020. package() {
  1021. cd "\$srcdir"
  1022. bsdtar xf data.tar.xz -C "\$pkgdir"
  1023. }
  1024. EOF
  1025. pushd "$OUTPUT_DIR/PKGBUILD" &>/dev/null || return
  1026. if ! execute makepkg \
  1027. --install \
  1028. --syncdeps \
  1029. --clean \
  1030. --cleanbuild \
  1031. --skipinteg \
  1032. --force \
  1033. --noconfirm \
  1034. -p mediacenter.pkgbuild; then
  1035. err "makepkg failed"; exit 1
  1036. fi
  1037. popd &>/dev/null || return
  1038. }
  1039. # @description Copy the RPM to createrepo-webroot and run createrepo as the createrepo-user
  1040. run_createrepo() {
  1041. debug "${FUNCNAME[0]}()"
  1042. install_package createrepo_c
  1043. # Ensure the webroot exists
  1044. if [[ ! -d $CREATEREPO_WEBROOT ]]; then
  1045. if ! execute sudo -u "$CREATEREPO_USER" mkdir -p "$CREATEREPO_WEBROOT"; then
  1046. if ! (execute sudo mkdir -p "$CREATEREPO_WEBROOT" ||
  1047. execute sudo chown -R "$CREATEREPO_USER:$CREATEREPO_USER" "$CREATEREPO_WEBROOT"); then
  1048. err "Could not create the createrepo-webroot path!"
  1049. err "Make sure that the webroot $CREATEREPO_WEBROOT is writable by user $CREATEREPO_USER"
  1050. err "Or change the repo ownership with --createrepo-user"
  1051. return 1
  1052. fi
  1053. fi
  1054. fi
  1055. # Copy built RPMs to webroot
  1056. if ! execute sudo cp -nf "$MC_RPM" "$CREATEREPO_WEBROOT" ||
  1057. ! execute sudo chown -R "$CREATEREPO_USER:$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then
  1058. err "Could not copy $MC_RPM to $CREATEREPO_WEBROOT"
  1059. return 1
  1060. fi
  1061. # Run createrepo
  1062. local -a cr_opts=(-q "$CREATEREPO_WEBROOT")
  1063. # [[ -d "$CREATEREPO_WEBROOT/repodata" ]] && cr_opts+=(--update) # TODO temporarily disabled for legacy createrepo
  1064. if ! execute sudo -u "$CREATEREPO_USER" createrepo "${cr_opts[@]}"; then
  1065. if ! (execute sudo createrepo "${cr_opts[@]}" && execute sudo chown -R "$CREATEREPO_USER:$CREATEREPO_USER" "$CREATEREPO_WEBROOT"); then
  1066. err "createrepo failed"
  1067. return 1
  1068. fi
  1069. fi
  1070. }
  1071. # @description Symlink certificates if they do not exist in default location
  1072. link_ssl_certs() {
  1073. debug "${FUNCNAME[0]}()"
  1074. local target_cert f
  1075. local mc_cert_link="$MC_ROOT/ca-certificates.crt"
  1076. local -a source_certs=(
  1077. "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
  1078. "/var/lib/ca-certificates/ca-bundle.pem"
  1079. "$MC_ROOT/local-ca-certificates.crt")
  1080. target_cert=$(readlink -f "$mc_cert_link")
  1081. [[ -f $target_cert ]] && return 0
  1082. for f in "${source_certs[@]}"; do
  1083. if [[ -f $f ]]; then
  1084. if execute sudo ln -fs "$f" "$mc_cert_link"; then
  1085. debug "Symlinked $mc_cert_link to $f"
  1086. return 0
  1087. fi
  1088. fi
  1089. done
  1090. err "Certificate symlinking failed"; return 1
  1091. }
  1092. # @description Restore the mjr license file from MJR_FILE or other common locations
  1093. restore_license() {
  1094. debug "${FUNCNAME[0]}()"
  1095. local newest f
  1096. local -a mjrfiles
  1097. # Glob mjr files from common directories
  1098. shopt -s nullglob
  1099. mjrfiles=(
  1100. "$SCRIPT_DIR"/*.mjr
  1101. "$OUTPUT_DIR"/*.mjr
  1102. "$HOME"/[dD]ownloads/*.mjr
  1103. "$HOME"/[dD]ocuments/*.mjr
  1104. )
  1105. shopt -u nullglob
  1106. if [[ ${#mjrfiles[@]} -gt 0 ]]; then
  1107. debug "mjrfiles=(${mjrfiles[*]})"
  1108. # Sort globbed files by time, newest first
  1109. newest=${mjrfiles[0]}
  1110. for f in "${mjrfiles[@]}"; do
  1111. if [[ -f $f && $f -nt $newest ]]; then
  1112. newest=$f
  1113. fi
  1114. done
  1115. debug "Latest mjrfile: $newest"
  1116. for f in "$MJR_FILE" "$newest"; do
  1117. if [[ -f $f ]]; then
  1118. if execute "mediacenter$MC_MVERSION" "/RestoreFromFile" "$f"; then
  1119. echo "Restored license from $f"
  1120. return 0
  1121. else
  1122. err "Failed to restore license from $f"
  1123. fi
  1124. fi
  1125. done
  1126. fi
  1127. }
  1128. # @description Opens ports using the system firewall tool
  1129. # @arg $1 string Service name
  1130. # @arg $2 array List of ports in firewall-cmd format
  1131. open_firewall() {
  1132. debug "${FUNCNAME[0]}()" "$@"
  1133. local service="$1"
  1134. shift
  1135. local -a f_ports=("$@") # for firewall-cmd
  1136. local u_ports="$*"
  1137. u_ports="${u_ports// /|}" # concatenate
  1138. u_ports="${u_ports//-/\:}" # for ufw
  1139. local port
  1140. if command -v firewall-cmd &>/dev/null; then
  1141. if ! sudo firewall-cmd --get-services | grep -q "$service"; then
  1142. execute sudo firewall-cmd --permanent "--new-service=$service"
  1143. execute sudo firewall-cmd --permanent "--service=$service" "--set-description=$service installed by installJRMC"
  1144. execute sudo firewall-cmd --permanent "--service=$service" "--set-short=$service"
  1145. for port in "${f_ports[@]}"; do
  1146. execute sudo firewall-cmd --permanent "--service=$service" "--add-port=$port"
  1147. done
  1148. execute sudo firewall-cmd --add-service "$service" --permanent
  1149. execute sudo firewall-cmd --reload
  1150. fi
  1151. elif command -v ufw &>/dev/null; then
  1152. sudo bash -c "cat <<-EOF > /etc/ufw/applications.d/$service
  1153. [$service]
  1154. title=$service
  1155. description=$service installed by installJRMC
  1156. ports=$u_ports
  1157. EOF"
  1158. execute sudo ufw app update "$service"
  1159. execute sudo ufw allow "$service"
  1160. else
  1161. return 1
  1162. fi
  1163. }
  1164. # @description Create the xvnc or x11vnc password file
  1165. # @arg $1 string Service type (xvnc, x11vnc)
  1166. set_vnc_pass() {
  1167. debug "${FUNCNAME[0]}()"
  1168. local vncpassfile="$HOME/.vnc/jrmc_passwd"
  1169. [[ -d ${vncpassfile%/*} ]] || execute mkdir -p "${vncpassfile%/*}"
  1170. if [[ -f $vncpassfile ]]; then
  1171. if [[ ! -v VNCPASS ]]; then
  1172. err "Refusing to overwrite existing $vncpassfile with an empty password"
  1173. err "Remove existing $vncpassfile or use --vncpass ''"
  1174. return 1
  1175. else
  1176. execute rm -f "$vncpassfile"
  1177. fi
  1178. fi
  1179. if [[ -v VNCPASS ]]; then
  1180. if [[ $1 == "xvnc" ]]; then
  1181. echo "$VNCPASS" | vncpasswd -f > "$vncpassfile"
  1182. elif [[ $1 == "x11vnc" ]]; then
  1183. execute x11vnc -storepasswd "$VNCPASS" "$vncpassfile"
  1184. fi
  1185. return
  1186. else
  1187. declare -gi NOVNCAUTH=1
  1188. fi
  1189. }
  1190. # @description Set display and port variables
  1191. set_display_vars() {
  1192. debug "${FUNCNAME[0]}()"
  1193. declare -g THIS_DISPLAY THIS_DISPLAY_NUM NEXT_DISPLAY
  1194. # Check USER_DISPLAY, else environment DISPLAY, else set to :0
  1195. THIS_DISPLAY="${USER_DISPLAY:-${DISPLAY:-:0}}"
  1196. THIS_DISPLAY_NUM="${THIS_DISPLAY#*:}" # strip prefix
  1197. THIS_DISPLAY_NUM="${THIS_DISPLAY_NUM%%.*}" # strip suffix
  1198. # Increment each time we run this
  1199. if ((NEXT_DISPLAY_NUM)); then
  1200. declare -g NEXT_DISPLAY_NUM=$((NEXT_DISPLAY_NUM + 1))
  1201. else
  1202. declare -g NEXT_DISPLAY_NUM=$((THIS_DISPLAY_NUM + 1))
  1203. fi
  1204. NEXT_DISPLAY=":$NEXT_DISPLAY_NUM"
  1205. }
  1206. # @description Create associated service variables based on service name
  1207. # @arg $1 string Service name
  1208. set_service_vars() {
  1209. debug "${FUNCNAME[0]}()" "$@"
  1210. declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME
  1211. declare -g USER_STRING GRAPHICAL_TARGET
  1212. declare -ga RELOAD ENABLE DISABLE IS_ENABLED IS_ACTIVE
  1213. local -a systemctl_prefix
  1214. local service_name="$1"
  1215. local service_type="${SERVICE_TYPE:-${2:-system}}"
  1216. local service_dir="/usr/lib/systemd/$service_type"
  1217. if [[ $USER == "root" && $service_type == "user" ]]; then
  1218. err "Trying to install user service as root"
  1219. err "Use --service-type service and/or execute installJRMC as non-root user"
  1220. return 1
  1221. fi
  1222. if [[ $service_type == "system" ]]; then
  1223. systemctl_prefix=(sudo systemctl)
  1224. GRAPHICAL_TARGET="graphical.target"
  1225. elif [[ $service_type == "user" ]]; then
  1226. systemctl_prefix=(systemctl --user)
  1227. GRAPHICAL_TARGET="default.target"
  1228. fi
  1229. # systemctl commands
  1230. RELOAD=("${systemctl_prefix[@]}" daemon-reload)
  1231. ENABLE=("${systemctl_prefix[@]}" enable --now)
  1232. DISABLE=("${systemctl_prefix[@]}" disable --now)
  1233. IS_ENABLED=("${systemctl_prefix[@]}" is-enabled --quiet)
  1234. IS_ACTIVE=("${systemctl_prefix[@]}" is-active --quiet)
  1235. [[ -d $service_dir ]] || execute sudo mkdir -p "$service_dir"
  1236. if [[ $service_type == "system" && $USER != "root" ]]; then
  1237. SERVICE_FNAME="$service_dir/$service_name@.service"
  1238. TIMER_FNAME="$service_dir/$service_name@.timer"
  1239. SERVICE_NAME="$service_name@$USER.service"
  1240. TIMER_NAME="$service_name@$USER.timer"
  1241. USER_STRING="User=%I"
  1242. else
  1243. SERVICE_NAME="$service_name.service"
  1244. TIMER_NAME="$service_name.timer"
  1245. SERVICE_FNAME="$service_dir/$SERVICE_NAME"
  1246. TIMER_FNAME="$service_dir/${TIMER_NAME}"
  1247. USER_STRING=""
  1248. fi
  1249. }
  1250. # @section Services
  1251. # @description Starts and enables (at startup) a JRiver Media Center service
  1252. # @arg $1 string Passes arguments as startup options to /usr/bin/mediacenter??
  1253. service_jriver-mediacenter() {
  1254. debug "${FUNCNAME[0]}()"
  1255. set_service_vars "${FUNCNAME[0]##*_}" "user"
  1256. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1257. [Unit]
  1258. Description=JRiver Media Center $MC_MVERSION
  1259. After=$GRAPHICAL_TARGET
  1260. [Service]
  1261. Type=simple
  1262. $USER_STRING
  1263. ExecStart=/usr/bin/mediacenter$MC_MVERSION $*
  1264. KillMode=none
  1265. ExecStop=/usr/bin/mc$MC_MVERSION /MCC 20007
  1266. Restart=always
  1267. RestartSec=10
  1268. TimeoutStopSec=30
  1269. [Install]
  1270. WantedBy=$GRAPHICAL_TARGET
  1271. EOF"
  1272. open_firewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1273. "${RELOAD[@]}" &&
  1274. "${ENABLE[@]}" "$SERVICE_NAME"
  1275. }
  1276. # @description Starts and enables (at startup) a JRiver Media Server service
  1277. service_jriver-mediaserver() {
  1278. debug "${FUNCNAME[0]}()"
  1279. set_service_vars "${FUNCNAME[0]##*_}" "user"
  1280. service_jriver-mediacenter "/MediaServer"
  1281. }
  1282. # @description Starts and enables (at startup) JRiver Media Center in a new Xvnc session
  1283. # TODO https://github.com/TigerVNC/tigervnc/blob/master/unix/vncserver/HOWTO.md
  1284. service_jriver-xvnc() {
  1285. debug "${FUNCNAME[0]}()"
  1286. local -a start_cmd
  1287. set_service_vars "${FUNCNAME[0]##*_}" "system"
  1288. set_display_vars
  1289. declare -g PORT=$((NEXT_DISPLAY_NUM + 5900))
  1290. install_package tigervnc-server
  1291. set_vnc_pass xvnc
  1292. start_cmd=(
  1293. /usr/bin/vncserver "$NEXT_DISPLAY"
  1294. -geometry 1440x900
  1295. -alwaysshared
  1296. -autokill
  1297. -xstartup "/usr/bin/mediacenter$MC_MVERSION"
  1298. )
  1299. if ((NOVNCAUTH)); then
  1300. start_cmd+=(
  1301. -name "jriver$NEXT_DISPLAY"
  1302. -SecurityTypes None)
  1303. else
  1304. start_cmd+=(
  1305. -rfbauth "$HOME/.vnc/jrmc_passwd")
  1306. fi
  1307. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1308. [Unit]
  1309. Description=Remote desktop service (VNC)
  1310. After=multi-user.target
  1311. [Service]
  1312. Type=forking
  1313. $USER_STRING
  1314. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
  1315. ExecStart=${start_cmd[*]}
  1316. ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
  1317. Restart=always
  1318. [Install]
  1319. WantedBy=multi-user.target
  1320. EOF"
  1321. "${RELOAD[@]}"
  1322. if ! "${ENABLE[@]}" "$SERVICE_NAME"; then
  1323. err "vncserver failed to start on DISPLAY $NEXT_DISPLAY"
  1324. # Allow to increment 10 times before breaking
  1325. max=$((THIS_DISPLAY_NUM + 10))
  1326. while [[ $NEXT_DISPLAY_NUM -lt $max ]]; do
  1327. echo "Incrementing DISPLAY and retrying"
  1328. service_jriver-xvnc && return
  1329. done
  1330. return 1
  1331. else
  1332. echo "Xvnc running on localhost:$PORT"
  1333. open_firewall "jriver-xvnc" "$PORT/tcp"
  1334. open_firewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1335. return 0
  1336. fi
  1337. }
  1338. # @description Starts and enables (at startup) x11vnc screen sharing for the local desktop
  1339. service_jriver-x11vnc() {
  1340. debug "${FUNCNAME[0]}()"
  1341. local -a start_cmd
  1342. set_service_vars "${FUNCNAME[0]##*_}" "user"
  1343. set_display_vars
  1344. declare -g PORT=$((THIS_DISPLAY_NUM + 5900))
  1345. install_package x11vnc
  1346. set_vnc_pass x11vnc
  1347. # If .Xauthority file is missing, generate a dummy for x11vnc -auth guess
  1348. if [[ ! -f "$HOME/.Xauthority" ]]; then
  1349. [[ $XDG_SESSION_TYPE == "wayland" ]] &&
  1350. ask_ok "Unsupported Wayland session detected for x11vnc, continue?" || return 1
  1351. debug "Generating $HOME/.Xauthority"
  1352. execute touch "$HOME/.Xauthority"
  1353. execute chmod 644 "$HOME/.Xauthority"
  1354. xauth generate "$DISPLAY" . trusted
  1355. xauth add "$HOST$DISPLAY" . "$(xxd -l 16 -p /dev/urandom)"
  1356. fi
  1357. start_cmd=(
  1358. /usr/bin/x11vnc
  1359. -display "$DISPLAY"
  1360. -noscr
  1361. -auth guess
  1362. -forever
  1363. -bg
  1364. )
  1365. if ((NOVNCAUTH)); then
  1366. start_cmd+=(-nopw)
  1367. else
  1368. start_cmd+=(-rfbauth "$HOME/.vnc/jrmc_passwd")
  1369. fi
  1370. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1371. [Unit]
  1372. Description=x11vnc
  1373. After=$GRAPHICAL_TARGET
  1374. [Service]
  1375. $USER_STRING
  1376. Type=forking
  1377. Environment=DISPLAY=$DISPLAY
  1378. ExecStart=${start_cmd[*]}
  1379. Restart=always
  1380. RestartSec=10
  1381. [Install]
  1382. WantedBy=$GRAPHICAL_TARGET
  1383. EOF"
  1384. open_firewall "jriver-x11vnc" "$PORT/tcp"
  1385. "${RELOAD[@]}" &&
  1386. "${ENABLE[@]}" "$SERVICE_NAME" &&
  1387. echo "x11vnc running on localhost:$PORT"
  1388. }
  1389. # @description Starts and enables (at startup) an hourly service to build the latest version of
  1390. # JRiver Media Center RPM from the source DEB and create/update an RPM repository
  1391. service_jriver-createrepo() {
  1392. debug "${FUNCNAME[0]}()"
  1393. if [[ $CREATEREPO_USER != "$USER" ]]; then
  1394. USER="root" set_service_vars "${FUNCNAME[0]##*_}" "system"
  1395. else
  1396. set_service_vars "${FUNCNAME[0]##*_}" "system"
  1397. fi
  1398. sudo bash -c "cat <<-EOF > $SERVICE_FNAME
  1399. [Unit]
  1400. Description=Builds JRiver Media Center RPM, moves it to the repo dir, and runs createrepo
  1401. [Service]
  1402. $USER_STRING
  1403. ExecStart=$SCRIPT_DIR/installJRMC --outputdir=$OUTPUT_DIR --createrepo=$CREATEREPO_TARGET \
  1404. --createrepo-webroot=$CREATEREPO_WEBROOT --createrepo-user=$CREATEREPO_USER --mcrepo=$MC_REPO --yes --no-update
  1405. [Install]
  1406. WantedBy=multi-user.target
  1407. EOF"
  1408. sudo bash -c "cat <<-EOF > $TIMER_FNAME
  1409. [Unit]
  1410. Description=Run JRiver MC rpmbuild hourly
  1411. [Timer]
  1412. OnCalendar=hourly
  1413. Persistent=true
  1414. [Install]
  1415. WantedBy=timers.target
  1416. EOF"
  1417. "${RELOAD[@]}" &&
  1418. "${ENABLE[@]}" "$TIMER_NAME"
  1419. }
  1420. # @description Detects if MC is installed on btrfs and disables CoW
  1421. fix_dotjriver_permissions() {
  1422. debug "${FUNCNAME[0]}()"
  1423. # Ensure the user owns their .jriver directory
  1424. if [[ -d "$HOME/.jriver" ]]; then
  1425. local owner
  1426. owner=$(stat -c '%U' "$HOME/.jriver")
  1427. if [[ "$owner" != "$USER" ]]; then
  1428. ask_ok "$USER does not currently own $HOME/.jriver, attempt fix?" &&
  1429. execute sudo chown -R "$USER:$USER" "$HOME/.jriver"
  1430. fi
  1431. fi
  1432. }
  1433. # @description Completely uninstalls MC, services, and firewall rules
  1434. uninstall() {
  1435. debug "${FUNCNAME[0]}()"
  1436. local service type unit f
  1437. if ! ask_ok "Do you really want to uninstall JRiver Media Center?"; then
  1438. echo "Uninstall cancelled"
  1439. return 1
  1440. fi
  1441. echo "Stopping and removing all Media Center services"
  1442. for service in $(compgen -A "function" "service"); do
  1443. service="${service##service_}"
  1444. for type in user system; do
  1445. set_service_vars "$service" "$type";
  1446. for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
  1447. if "${IS_ACTIVE[@]}" "$unit" ||
  1448. "${IS_ENABLED[@]}" "$unit" &>/dev/null; then
  1449. "${DISABLE[@]}" "$unit"
  1450. fi
  1451. done
  1452. for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
  1453. [[ -f $f ]] && execute sudo rm -f "$f"
  1454. done
  1455. "${RELOAD[@]}"
  1456. done
  1457. done
  1458. # Remove the repository files
  1459. for file in "/etc/yum.repos.d/jriver.repo" /etc/apt/sources.list.d/{jriver,mediacenter}*.{list,sources}; do
  1460. if [[ -e $file ]]; then
  1461. echo "Removing repository file: $file"
  1462. execute sudo rm -f "$file"
  1463. fi
  1464. done
  1465. [[ $ID == "suse" ]] && execute sudo zypper --non-interactive removerepo jriver
  1466. echo "Removing firewall rules"
  1467. for service in jriver-mediacenter jriver-xvnc jriver-x11vnc; do
  1468. if command -v firewall-cmd &>/dev/null; then
  1469. execute sudo firewall-cmd --permanent --remove-service=$service
  1470. execute sudo firewall-cmd --permanent --delete-service=$service
  1471. execute sudo firewall-cmd --reload
  1472. elif command -v ufw &>/dev/null; then
  1473. execute sudo ufw delete allow $service
  1474. [[ -f /etc/ufw/applications.d/$service ]] &&
  1475. execute sudo rm -f /etc/ufw/applications.d/$service
  1476. fi
  1477. done
  1478. echo "Uninstalling the JRiver Media Center package"
  1479. if "${PKG_REMOVE[@]}" "${MC_PKG%%=*}"; then # strip version specifier
  1480. echo "Successfully uninstalled the ${MC_PKG%%=*} package"
  1481. elif [[ $? -eq 100 ]]; then
  1482. err "JRiver Media Center package '${MC_PKG%%=*}' is not present and was not uninstalled"
  1483. else
  1484. err "Could not remove Media Center package"
  1485. fi
  1486. local keyfile="/usr/share/keyrings/jriver-com-archive-keyring.gpg"
  1487. if [[ -f $keyfile ]]; then
  1488. echo "Removing the JRiver Media Center GPG key"
  1489. execute sudo rm -f "$keyfile"
  1490. fi
  1491. if [[ -f $SCRIPT_DIR/.uninstall ]]; then
  1492. echo "Removing files from .uninstall log"
  1493. while read -r p; do
  1494. [[ -d $p ]] && execute sudo rm -rf "$p"
  1495. done < "$SCRIPT_DIR/.uninstall"
  1496. mv "$SCRIPT_DIR/.uninstall" "$SCRIPT_DIR/.uninstall.bk"
  1497. fi
  1498. if [[ -d $OUTPUT_DIR ]]; then
  1499. if ask_ok "Remove installJRMC output directory $OUTPUT_DIR?"; then
  1500. execute sudo rm -rf "$OUTPUT_DIR"
  1501. fi
  1502. fi
  1503. if [[ -d $MC_ROOT ]]; then
  1504. if ask_ok "Remove MC installation directory $MC_ROOT?"; then
  1505. execute sudo rm -rf "$MC_ROOT"
  1506. fi
  1507. fi
  1508. if [[ -d $HOME/.jriver ]]; then
  1509. if ask_ok "Backup and reset your MC library?"; then
  1510. execute mv "$HOME/.jriver" "$HOME/.jriver.bk"
  1511. echo "Your MC library has been reset and backed up to $HOME/.jriver.bk"
  1512. echo "To restore your MC library: mv $HOME/.jriver.bk $HOME/.jriver"
  1513. return
  1514. fi
  1515. echo "To reset and backup your MC library: mv $HOME/.jriver $HOME/.jriver.bk"
  1516. echo "To remove your MC library: rm -rf $HOME/.jriver"
  1517. fi
  1518. }
  1519. # @description Checks for installJRMC update and re-executes, if necessary
  1520. update() {
  1521. debug "${FUNCNAME[0]}()" "$@"
  1522. debug "Checking for installJRMC update"
  1523. # Extract and normalize version from a script
  1524. extract_version() {
  1525. local version_line
  1526. version_line=$(grep -m 1 'SCRIPT_VERSION=' "$1")
  1527. version_line=${version_line#*=}
  1528. version_line=${version_line#\"}
  1529. version_line=${version_line%-dev\"}
  1530. version_line=${version_line%\"}
  1531. echo "$version_line"
  1532. }
  1533. # Compare semantic version strings
  1534. version_greater() {
  1535. [[ "$(echo -e "$1\n$2" | sort -V | head -n 1)" != "$1" ]]
  1536. }
  1537. # Check if we're in a git directory and if it's the installJRMC repository
  1538. if git -C "$SCRIPT_DIR" rev-parse --is-inside-work-tree &>/dev/null &&
  1539. [[ "$(git -C "$SCRIPT_DIR" config --get remote.origin.url)" =~ installJRMC|installjrmc ]]; then
  1540. # Get the current commit hash
  1541. local before_pull_hash
  1542. before_pull_hash=$(git -C "$SCRIPT_DIR" rev-parse HEAD)
  1543. # Stash local changes before pull
  1544. execute git -C "$SCRIPT_DIR" stash push --quiet
  1545. # Pull latest changes
  1546. execute git -C "$SCRIPT_DIR" pull --quiet
  1547. # Restore local changes
  1548. execute git -C "$SCRIPT_DIR" stash pop --quiet
  1549. debug "Current commit hash: $before_pull_hash"
  1550. debug "New commit hash: $(git -C "$SCRIPT_DIR" rev-parse HEAD)"
  1551. # If the commit hash has changed, an update occurred
  1552. if [[ "$before_pull_hash" != $(git -C "$SCRIPT_DIR" rev-parse HEAD) ]]; then
  1553. echo "Detected installJRMC update, restarting"
  1554. exec "$SCRIPT_PATH" "$@" "--no-update"
  1555. fi
  1556. else
  1557. debug "Not in the installJRMC repository, checking for installJRMC update via webscrape."
  1558. local tmp
  1559. tmp=$(mktemp) || { err "Failed to create temporary file."; return 1; }
  1560. # Acquire the latest version of the script
  1561. if ! download "$SCRIPT_URL" "$tmp"; then
  1562. err "Failed to download the latest script."
  1563. execute rm -f "$tmp"
  1564. return 1
  1565. fi
  1566. # Extract the latest version number
  1567. local remote_version
  1568. remote_version=$(extract_version "$tmp")
  1569. if [[ -z "$remote_version" ]]; then
  1570. err "Failed to extract version from the downloaded script."
  1571. execute rm -f "$tmp"
  1572. return 1
  1573. fi
  1574. # Compare versions and update if the remote version is greater
  1575. if version_greater "$remote_version" "$SCRIPT_VERSION"; then
  1576. execute mv "$tmp" "$SCRIPT_PATH" || { err "Failed to replace the script"; execute rm -f "$tmp"; return 1; }
  1577. execute chmod +x "$SCRIPT_PATH" || { err "Failed to make the script executable"; return 1; }
  1578. execute rm -f "$tmp"
  1579. echo "Detected installJRMC update, restarting"
  1580. exec "$SCRIPT_PATH" "$@" "--no-update"
  1581. else
  1582. debug "Current installJRMC $SCRIPT_VERSION is the latest version"
  1583. execute rm -f "$tmp"
  1584. return 0
  1585. fi
  1586. fi
  1587. }
  1588. # @description installJRMC main function
  1589. main() {
  1590. debug "${FUNCNAME[0]}()" "$@" # prints function name and arguments
  1591. echo "Starting installJRMC $SCRIPT_VERSION"
  1592. if ((DEBUG)); then
  1593. echo "Debugging on"
  1594. else
  1595. echo "To enable debugging output, use --debug or -d"
  1596. fi
  1597. # Parse input, set default/host variables, and MC version
  1598. init "$@"
  1599. ((UNINSTALL_SWITCH)) && uninstall
  1600. # Exit now if only --uninstall is passed
  1601. if ! (( BUILD_SWITCH || CREATEREPO_SWITCH || REPO_INSTALL_SWITCH || LOCAL_INSTALL_SWITCH ||
  1602. CONTAINER_INSTALL_SWITCH || SNAP_INSTALL_SWITCH || APPIMAGE_INSTALL_SWITCH )) &&
  1603. [[ ${#SERVICES[@]} -eq 0 && ${#CONTAINERS[@]} -eq 0 ]]; then
  1604. exit 0
  1605. fi
  1606. install_external_repos
  1607. if ((REPO_INSTALL_SWITCH)); then
  1608. echo "Installing JRiver Media Center from remote repository"
  1609. if install_mc_repo; then
  1610. echo "JRiver Media Center installed successfully from remote repository"
  1611. install_mesa_freeworld
  1612. link_ssl_certs
  1613. restore_license
  1614. open_firewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1615. else
  1616. err "JRiver Media Center installation from remote repository failed"
  1617. return 1
  1618. fi
  1619. fi
  1620. if ((BUILD_SWITCH)); then
  1621. acquire_deb || { err "Could not download Media Center DEB package"; return 1; }
  1622. if [[ $BUILD_TARGET =~ centos|fedora|suse|mandriva || $CREATEREPO_TARGET =~ centos|fedora|suse|mandriva ]]; then
  1623. install_package dpkg rpm-build
  1624. [[ -d $OUTPUT_DIR/SPECS ]] || execute mkdir -p "$OUTPUT_DIR/SPECS"
  1625. if build_rpm; then
  1626. echo "RPM package built successfully"
  1627. else
  1628. err "Failed to build RPM package"
  1629. # On build failure, remove the source DEB in case it is corrupted
  1630. if [[ -f $MC_DEB ]]; then
  1631. echo "Removing source DEB"
  1632. if ! execute rm -f "$MC_DEB"; then
  1633. execute sudo rm -f "$MC_DEB"
  1634. fi
  1635. fi
  1636. return 1
  1637. fi
  1638. fi
  1639. fi
  1640. if ((LOCAL_INSTALL_SWITCH)); then
  1641. echo "Installing JRiver Media Center from local package"
  1642. if PKG_INSTALL_LOCAL "$@"; then
  1643. echo "JRiver Media Center installed successfully from local package"
  1644. else
  1645. err "JRiver Media Center local package installation failed"
  1646. return 1
  1647. fi
  1648. install_mesa_freeworld
  1649. link_ssl_certs
  1650. restore_license
  1651. open_firewall "jriver-mediacenter" "52100-52200/tcp" "1900/udp"
  1652. fi
  1653. if ((CREATEREPO_SWITCH)); then
  1654. if run_createrepo; then
  1655. echo "Successfully updated repo"
  1656. else
  1657. err "Repo creation failed"
  1658. fi
  1659. fi
  1660. if [[ ${#SERVICES[@]} -gt 0 ]]; then
  1661. declare service
  1662. for service in "${SERVICES[@]}"; do
  1663. if ! "service_$service"; then
  1664. if [[ $? -eq 127 ]]; then
  1665. err "Service $service does not exist, check service name"
  1666. else
  1667. err "Failed to create $service service"
  1668. fi
  1669. else
  1670. echo "Started and enabled $service service"
  1671. fi
  1672. done
  1673. unset service
  1674. fi
  1675. }
  1676. # @section Helper functions
  1677. debug() { ((DEBUG)) && echo "Debug: $*"; }
  1678. err() { echo "Error: $*" >&2; }
  1679. ask_ok() {
  1680. local response
  1681. ((YES_SWITCH)) && return 0
  1682. read -n 1 -r -p "$* [y/N]: " response
  1683. echo
  1684. [[ ${response,,} == y ]]
  1685. }
  1686. execute() {
  1687. if debug "$*"; then
  1688. "$@"
  1689. else
  1690. "$@" &>/dev/null
  1691. fi
  1692. }
  1693. fix_permissions() {
  1694. local dir="$1"
  1695. local user="$2"
  1696. local owner
  1697. [[ -d "$dir" ]] || return 1
  1698. owner=$(stat -c '%U' "$dir")
  1699. if [[ "$owner" != "$user" ]]; then
  1700. echo "Directory $dir is owned by $owner, not $user"
  1701. if ask_ok "Change ownership of $dir to $user?"; then
  1702. execute sudo chown -R "$user:$user" "$dir"
  1703. fi
  1704. fi
  1705. }
  1706. download() {
  1707. debug "${FUNCNAME[0]}()" "$@"
  1708. local url="$1"
  1709. local output="${2:-}"
  1710. local -a cmd
  1711. if command -v curl &>/dev/null || install_package --silent curl; then
  1712. cmd=(curl --silent --fail --location)
  1713. if [[ -n "$output" ]]; then
  1714. cmd+=(--output "$output")
  1715. else
  1716. cmd+=(--remote-name)
  1717. fi
  1718. elif command -v wget &>/dev/null || install_package --silent wget; then
  1719. cmd=(wget --quiet)
  1720. [[ -n "$output" ]] && cmd+=("--output-document=$output")
  1721. else
  1722. err "Unable to install wget or curl"
  1723. return 1
  1724. fi
  1725. debug "${cmd[@]}" "$url"
  1726. "${cmd[@]}" "$url"
  1727. }
  1728. create_mc_apt_container() {
  1729. debug "${FUNCNAME[0]}()" "$@"
  1730. declare -g CNT
  1731. local -a cmds=("$@")
  1732. { command -v buildah &>/dev/null || install_package buildah &>/dev/null; } &&
  1733. CNT=$(sudo buildah from --quiet alpine:edge) &&
  1734. sudo buildah run "$CNT" -- sh -c '
  1735. apk add --no-cache apt curl gnupg &>/dev/null
  1736. curl -fsSL https://dist.jriver.com/mediacenter@jriver.com.gpg.key | gpg --dearmor -o /usr/share/keyrings/jriver-com-archive-keyring.gpg &>/dev/null
  1737. cat <<-EOF > /etc/apt/sources.list.d/jriver.sources
  1738. Types: deb
  1739. URIs: https://dist.jriver.com/latest/mediacenter/
  1740. Signed-By: /usr/share/keyrings/jriver-com-archive-keyring.gpg
  1741. Suites: '"$MC_REPO"'
  1742. Components: main
  1743. Architectures: '"$MC_ARCH"'
  1744. EOF
  1745. apt-get update &>/dev/null' &&
  1746. # If user passes command strings run them in the container
  1747. for cmd in "${cmds[@]}"; do
  1748. sudo buildah run "$CNT" -- sh -c "$cmd" || { err "$cmd failed"; return 1; }
  1749. done
  1750. }
  1751. add_temp_repo() {
  1752. debug "${FUNCNAME[0]}()"
  1753. local repo_name repo_uri repo_suite repo_key
  1754. if [[ "$ID" == "ubuntu" ]]; then
  1755. local major_version="${VERSION_ID%%.*}"
  1756. local minor_version="${VERSION_ID##*.}"
  1757. minor_version="${minor_version#0}" # strip leading zero
  1758. if [[ $major_version -gt 24 || ( $major_version -eq 24 && minor_version -ge 4 ) ]]; then
  1759. echo "Temporarily adding jammy repository for libwebkit2gtk-4.0-37, etc."
  1760. repo_name="ubuntu-jammy-temp"
  1761. repo_uri="https://archive.ubuntu.com/ubuntu"
  1762. repo_suite="jammy"
  1763. repo_key="/usr/share/keyrings/ubuntu-archive-keyring.gpg"
  1764. else
  1765. return 0
  1766. fi
  1767. elif [[ "$ID" == "debian" ]]; then
  1768. local major_version="${VERSION_ID%%.*}"
  1769. if [[ $major_version -ge 13 ]]; then
  1770. echo "Temporarily adding bookworm repository for libwebkit2gtk-4.0-37, etc."
  1771. repo_name="debian-bookworm-temp"
  1772. repo_uri="https://deb.debian.org/debian"
  1773. repo_suite="bookworm"
  1774. repo_key="/usr/share/keyrings/debian-archive-keyring.gpg"
  1775. else
  1776. return 0
  1777. fi
  1778. else
  1779. # For other distributions, do nothing.
  1780. return 0
  1781. fi
  1782. declare -g TEMP_REPO_FILE="/etc/apt/sources.list.d/${repo_name}.sources"
  1783. echo "Creating temporary repository file $TEMP_REPO_FILE for $repo_suite"
  1784. sudo bash -c "cat <<-EOF > $TEMP_REPO_FILE
  1785. Types: deb
  1786. URIs: $repo_uri
  1787. Suites: $repo_suite
  1788. Components: main
  1789. Architectures: $MC_ARCH
  1790. Signed-By: $repo_key
  1791. EOF"
  1792. }
  1793. # Roughly turn debugging on for pre-init
  1794. # Reset and reparse in parse_input() with getopt
  1795. [[ " $* " =~ ( --debug | -d ) ]] && DEBUG=1
  1796. main "$@"
  1797. exit