-
Notifications
You must be signed in to change notification settings - Fork 0
/
installJRMC
executable file
·1808 lines (1600 loc) · 57.9 KB
/
installJRMC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC2317
# @file installJRMC
# @brief Install JRiver Media Center and associated services
# @description See installJRMC --help or print_help() below for usage
# Copyright (c) 2021-2024 Bryan C. Roessler
# This software is released under the Apache License.
# https://www.apache.org/licenses/LICENSE-2.0
#
# TODO (v2)
# * Interactive mode
# * Additional containerization (createrepo and rpmbuild)
#
# BUGS
# * No createrepo on Mint
#
# NOTES
# * Be careful with tabs in heredocs
shopt -s extglob
declare -g SCRIPT_VERSION="1.4.6"
declare -g MC_REPO="bullseye" # should match the MC_VERSION
declare -g MC_VERSION="33.0.49" # Do find all replace
declare -g BOARD_URL="https://yabb.jriver.com/interact/index.php/board,86.0.html" # MC33
declare -gi UPDATE_SWITCH=1 # set to 0 to disable automatic self-update
declare -g SCRIPT_URL="https://git.bryanroessler.com/bryan/installJRMC/raw/master/installJRMC"
declare -gi DEBUG=${DEBUG:-0} # det default debug and allow DEBUG env override (default: disabled)
# @description Print help text
print_help() {
debug "Running: ${FUNCNAME[0]}"
cat <<-EOF
USAGE:
installJRMC [[OPTION] [VALUE]]...
If no options (excluding -d or --debug) are provided installJRMC defaults to '--install repo'.
OPTIONS
--install, -i repo|local
repo: Install MC from repository, updates are handled by the system package manager
local: Build and install MC package locally from official source release
--build[=suse|fedora|centos]
Build RPM from source DEB but do not install
Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
--compat
Build/install MC locally without minimum dependency version requirements
--mcversion VERSION
Specify the MC version, ex. "$MC_VERSION" or "${MC_VERSION%%.*}" (default: latest)
--arch VERSION
Specify the MC architecture, ex. "amd64", "arm64", etc (default: host architecture)
--mcrepo REPO
Specify the MC repository, ex. "bullseye", "bookworm", "noble", etc (default: latest official)
--outputdir PATH
Generate rpmbuild output in this directory (default: ./output)
--restorefile MJR_FILE
Restore file location for automatic license registration
--betapass PASSWORD
Enter beta team password for access to beta builds
--service, -s SERVICE
See SERVICES section below for a list of possible services to install
--service-type user|system
Starts services at boot (system) or at user login (user) (default: per service, see SERVICES)
--container, -c CONTAINER (TODO: Under construction)
See CONTAINERS section below for a list of possible services to install
--createrepo[=suse|fedora|centos]
Build rpm, copy to webroot, and run createrepo.
Use in conjunction with --build=TARGET for crossbuilding repos
Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
--createrepo-webroot PATH
Specify the webroot directory to install the repo (default: /var/www/jriver)
--createrepo-user USER
Specify the web server user if it differs from \$USER
--no-update
Disable automatic installJRMCself-update
--uninstall, -u
Uninstall JRiver MC, remove services, containers, and firewall rules (does not remove library files)
--yes, -y, --auto
Assume yes response to questions
--version, -v
Print this script version and exit
--debug, -d
Print debug output
--help, -h
Print help dialog and exit
SERVICES
jriver-mediaserver (default --service-type=user)
Enable and start a mediaserver systemd service (requires an existing X server)
jriver-mediacenter (user)
Enable and start a mediacenter systemd service (requires an existing X server)
jriver-x11vnc (user)
Enable and start x11vnc for the local desktop (requires an existing X server)
Usually combined with jriver-mediaserver or jriver-mediacenter services
--vncpass and --display are optional (see below)
jriver-xvnc (system)
Enable and start a new Xvnc session running JRiver Media Center
--vncpass PASSWORD
Set the vnc password for x11vnc/Xvnc access. If no password is set, installJRMC
will either use existing password stored in \$HOME/.vnc/jrmc_passwd or use no password
--display DISPLAY
Display to use for x11vnc/Xvnc (default: The current display (x11vnc) or the
current display incremented by 1 (Xvnc))
jriver-createrepo (system)
Install hourly service to build latest MC RPM and run createrepo
CONTAINERS (TODO: Under construction)
mediacenter-xvnc
createrepo
EOF
}
# @description Parses user input and sets sensible defaults
# @arg $@ User input
parse_input() {
debug "Running: ${FUNCNAME[0]} $*"
declare -gi BUILD_SWITCH=0 REPO_INSTALL_SWITCH=0 LOCAL_INSTALL_SWITCH=0 \
CONTAINER_INSTALL_SWITCH=0 COMPAT_SWITCH=0 CREATEREPO_SWITCH=0 UNINSTALL_SWITCH=0 \
YES_SWITCH=0 DEBUG=0
declare -g USER_MC_VERSION USER_MC_REPO MJR_FILE \
BETAPASS SERVICE_TYPE VNCPASS USER_DISPLAY BUILD_TARGET CREATEREPO_TARGET
local long_opts short_opts input
long_opts="install:,build::,outputdir:,mcversion:,arch:,mcrepo:,compat,"
long_opts+="restorefile:,betapass:,"
long_opts+="service-type:,service:,services:,"
long_opts+="version,debug,verbose,help,uninstall,yes,auto,no-update,"
long_opts+="createrepo::,createrepo-webroot:,createrepo-user:,"
long_opts+="vncpass:,display:,container:"
short_opts="+i:b::s:c:uyvdh"
if input=$(getopt -o $short_opts -l $long_opts -- "$@"); then
eval set -- "$input"
while true; do
case $1 in
--install|-i)
shift
case $1 in
local|rpm|deb) BUILD_SWITCH=1; LOCAL_INSTALL_SWITCH=1 ;;
repo|remote) REPO_INSTALL_SWITCH=1 ;;
container) CONTAINER_INSTALL_SWITCH=1 ;;
*) err "Invalid --install option passed"; exit 1 ;;
esac
;;
--build|-b) BUILD_SWITCH=1; shift; BUILD_TARGET="$1" ;;
--outputdir) shift; OUTPUT_DIR="$1" ;;
--mcversion)
shift
if [[ $1 =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
USER_MC_VERSION="$1"
elif [[ $1 =~ ([0-9][0-9]) ]]; then
case $1 in
33) ;; # use update check to determine latest version
32) USER_MC_VERSION="32.0.58" ;;
31) USER_MC_VERSION="31.0.83" ;;
30) USER_MC_VERSION="30.0.96" ;;
29) USER_MC_VERSION="29.0.91" ;;
28) USER_MC_VERSION="28.0.110" ;;
27) USER_MC_VERSION="27.0.88" ;;
26) USER_MC_VERSION="26.0.107" ;;
25) USER_MC_VERSION="25.0.114" ;;
24) USER_MC_VERSION="24.0.78" ;;
23) USER_MC_VERSION="23.0.104" ;;
22) USER_MC_VERSION="22.0.102" ;;
21) USER_MC_VERSION="21.0.90" ;;
20) USER_MC_VERSION="20.0.131" ;;
*) err "Bad --mcversion"; print_help; exit 1 ;;
esac
else
err "Bad --mcversion"; print_help; exit 1
fi
;;
--arch) shift; echo "Switching arch from $ARCH to $1"; ARCH="$1" ;;
--mcrepo) shift; USER_MC_REPO="$1" ;;
--restorefile) shift; MJR_FILE="$1" ;;
--betapass) shift; BETAPASS="$1" ;;
--service-type) shift; SERVICE_TYPE="$1" ;;
--service|-s|--services) shift; SERVICES+=("$1") ;;
--createrepo) shift; CREATEREPO_TARGET="$1"; BUILD_TARGET="$1"
BUILD_SWITCH=1; CREATEREPO_SWITCH=1 ;;
--createrepo-webroot) shift; CREATEREPO_WEBROOT="$1" ;;
--createrepo-user) shift; CREATEREPO_USER="$1" ;;
--vncpass) shift; VNCPASS="$1" ;;
--display) shift; USER_DISPLAY="$1" ;;
--compat) COMPAT_SWITCH=1; BUILD_SWITCH=1 ;;
--no-update) UPDATE_SWITCH=0 ;;
--container|-c) shift; CONTAINERS+=("$1") ;;
--yes|-y|--auto) YES_SWITCH=1 ;;
--version|-v) echo "Version: $SCRIPT_VERSION"; exit 0 ;;
--debug|-d|--verbose) DEBUG=1 ;;
--help|-h) print_help; exit 0 ;;
--uninstall|-u) UNINSTALL_SWITCH=1 ;;
--) shift; break ;;
esac
shift
done
else
err "Incorrect option provided, see installJRMC --help"; exit 1
fi
# Print some warnings for unsupported argument combinations
if [[ -n $USER_MC_REPO ]] && ((LOCAL_INSTALL_SWITCH)); then
err "--install=local is not compatible with --mcrepo as only the default ($MC_REPO) DEB is available"
fi
if [[ -n $BETA_PASS ]] && ((REPO_INSTALL_SWITCH)); then
echo "Warning: not all repositories have beta channels"
echo "If the MC package is unavailable, try using --mcrepo to select another repository"
fi
if [[ -n $CONTAINER_INSTALL_SWITCH ]] && ((LOCAL_INSTALL_SWITCH || REPO_INSTALL_SWITCH)); then
err "Some --install methods are incompatible"
fi
}
# @description Perform OS detection and generate OS-specific functions
# @see parse_input
init() {
debug "Running: ${FUNCNAME[0]}"
declare -g USER
declare -g SCRIPT_PATH; SCRIPT_PATH=$(readlink -f "${BASH_SOURCE[0]}")
declare -g SCRIPT_DIR; SCRIPT_DIR=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
declare -g OUTPUT_DIR="$SCRIPT_DIR/output"
declare -g CREATEREPO_WEBROOT="/var/www/jriver"
declare -g CREATEREPO_USER="$USER" # can be root
declare -g ID VERSION_ID ARCH NAME
declare -g MC_MVERSION MC_PKG MC_RPM MC_ROOT
declare -ga PKG_INSTALL PKG_REMOVE PKG_UPDATE PKG_QUERY
declare -ga SERVICES CONTAINERS
# Try to save users from themselves
if ((EUID == 0)); then
err "Running as root but attempting to continue"
ask_ok "Continue as root user?" || exit 1
fi
if [[ -n $SUDO_USER ]]; then
err "Sudo detected, installJRMC should not be run with sudo but attempting to continue"
ask_ok "Continue as user $SUDO_USER (unsupported and may result in permission issues)?" || exit 1
USER="${SUDO_USER:-$USER}"
fi
# Set default command arguments and/or parse user input
if [[ $# -eq 0 || ! "$*" =~ (--install|--service|--container|--createrepo) ]]; then
debug "Automatically using --install=repo"
REPO_INSTALL_SWITCH=1
fi
# Parse input commands with getopt
[[ $# -gt 0 ]] && parse_input "$@"
# Run the self-updater if enabled
((UPDATE_SWITCH)) && update "$@"
# Get host information
[[ -f /etc/os-release ]] && source /etc/os-release
# Detect architecture and translate to MC convention
if ARCH=$(uname -m); then
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
esac
else
ARCH="amd64"
err "Failed to detect host arch, using default: $ARCH"
fi
debug "Detected host platform: $ID $VERSION_ID $ARCH"
# Normalize ID and set host-specific vars
case $ID in
debian|arch|fedora|centos) ;;
rhel|almalinux) ID="centos" ;;
linuxmint|neon|zorin|*ubuntu*) ID="ubuntu" ;;
raspbian) ID="debian" ;;
*suse*)
ID="suse"
# Currently there is no remote repository for SUSE
# installJRMC can easily create one but I'd rather a SUSEian provide it
# So use local rpmbuild method by default for SUSE
if ((REPO_INSTALL_SWITCH)); then
debug "Automatically using --install=local for SUSE"
REPO_INSTALL_SWITCH=0
BUILD_SWITCH=1
LOCAL_INSTALL_SWITCH=1
fi
;;
*)
err "Auto-detecting distro, this is unreliable and --compat may be required"
for cmd in dnf yum apt-get pacman; do
if command -v "$cmd" &>/dev/null; then
case "$cmd" in
dnf) ID="fedora" ;;
yum) ID="centos"; COMPAT_SWITCH=1 ;;
apt-get) ID="ubuntu" ;;
pacman) ID="arch" ;;
esac
break
fi
done
if [[ -z $ID ]]; then
err "OS detection failed!"
if ask_ok "Continue with manual installation?"; then
debug "Automatically using --install=local for unknown distro"
ID="unknown"
REPO_INSTALL_SWITCH=0
BUILD_SWITCH=1
LOCAL_INSTALL_SWITCH=1
else
exit 1
fi
fi
;;
esac
# Set default targets
BUILD_TARGET="${BUILD_TARGET:-$ID}"
CREATEREPO_TARGET="${CREATEREPO_TARGET:-$ID}"
# Match the MC repo to the system codename
if [[ -z $USER_MC_REPO && ($ID == debian || $ID == ubuntu) ]]; then
MC_REPO=${UBUNTU_CODENAME:-${VERSION_CODENAME:-$MC_REPO}}
fi
# Use the correct repo for legacy MC versions
if [[ -n $USER_MC_VERSION ]]; then
case ${USER_MC_VERSION%%.*} in # get MVERSION from user input
2[0-6]) USER_MC_REPO="jessie" ;;
2[7-9]|30) USER_MC_REPO="buster" ;;
31) USER_MC_REPO="bullseye" ;;
# After this point, things get messy with multiple repos for the same MC version
# Just use the default repo
esac
fi
# Set distro-specific package manager commands for normalized IDs
case $ID in
fedora|centos)
local rpm_mgr
rpm_mgr=$(command -v dnf &>/dev/null && echo "dnf" || echo "yum")
PKG_INSTALL=(execute sudo "$rpm_mgr" install -y)
PKG_REMOVE=(execute sudo "$rpm_mgr" remove -y)
PKG_UPDATE=(execute sudo "$rpm_mgr" makecache)
PKG_QUERY=(rpm -q)
PKG_INSTALL_LOCAL() { install_mc_rhel; }
;;
debian|ubuntu)
PKG_INSTALL=(execute sudo apt-get -f install -y -q0)
PKG_REMOVE=(execute sudo apt-get remove --auto-remove -y -q0)
PKG_UPDATE=(execute sudo apt-get update -y -q0)
PKG_QUERY=(dpkg -s)
PKG_INSTALL_LOCAL() { install_mc_deb "$@"; }
;;
suse)
PKG_INSTALL=(execute sudo zypper --gpg-auto-import-keys --non-interactive --quiet install --force --no-confirm)
PKG_REMOVE=(execute sudo zypper --non-interactive --quiet remove --clean-deps)
PKG_UPDATE=(execute sudo zypper --non-interactive --quiet refresh jriver)
PKG_QUERY=(rpm -q)
PKG_INSTALL_LOCAL() { install_mc_suse; }
;;
arch)
PKG_INSTALL=(execute sudo pacman -Sy --noconfirm)
PKG_REMOVE=(execute sudo pacman -Rs --noconfirm)
PKG_UPDATE=(execute sudo pacman -Syy)
PKG_QUERY=(sudo pacman -Qs)
PKG_INSTALL_LOCAL() { install_mc_arch; }
;;
unknown)
PKG_INSTALL=(:)
PKG_REMOVE=(:)
PKG_UPDATE=(:)
PKG_QUERY=(:)
PKG_INSTALL_LOCAL() { install_mc_generic; }
;;
esac
# Don't check for latest MC version if set by user or using --install=repo only
if [[ -z $USER_MC_VERSION ]] \
&& ((BUILD_SWITCH || LOCAL_INSTALL_SWITCH || CREATEREPO_SWITCH)); then
# Retrieves the latest MC version number from the specified MC_REPO
get_latest_mc_version "${USER_MC_REPO:-$MC_REPO}"
fi
# Set MC version variables
MC_REPO="${USER_MC_REPO:-$MC_REPO}"
MC_VERSION="${USER_MC_VERSION:-$MC_VERSION}"
MC_MVERSION="${MC_VERSION%%.*}"
MC_PKG="mediacenter$MC_MVERSION"
MC_RPM="$OUTPUT_DIR/RPMS/x86_64/mediacenter$MC_MVERSION-$MC_VERSION.x86_64.rpm"
MC_ROOT="/usr/lib/jriver/Media Center $MC_MVERSION"
if [[ -n $USER_MC_VERSION ]]; then
# Append explicit package version when user provides --mcversion
case $ID in
fedora|centos|suse) MC_PKG+="-$MC_VERSION" ;;
debian|ubuntu) MC_PKG+="=$MC_VERSION" ;;
esac
fi
debug "Host platform: $ID $VERSION_ID"
debug "MC repository: $MC_REPO"
}
# @description Determines the latest JRiver MC version using several methods
# @arg $1 string MC repository name
get_latest_mc_version() {
debug "Running: ${FUNCNAME[0]}" "$*"
local cnt mc_version_source
# Use generalized containerized package manager to determine latest MC version
if install_package --silent buildah \
&& cnt=$(buildah from --quiet alpine:edge 2>/dev/null) \
&& buildah run "$cnt" -- sh -c \
"apk add apt" &>/dev/null \
&& buildah run "$cnt" -- sh -c \
"echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $1 main' > /etc/apt/sources.list 2>&1" &>/dev/null \
&& buildah run "$cnt" -- sh -c \
"apt update --allow-insecure-repositories &>/dev/null" &>/dev/null \
&& MC_VERSION=$(buildah run "$cnt" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) &>/dev/null \
&& [[ $MC_VERSION =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
mc_version_source="containerized package manager"
execute buildah rm "$cnt"
# Fallback to webscrape
elif MC_VERSION=$(download "$BOARD_URL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1) \
&& [[ $MC_VERSION =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
mc_version_source="webscrape"
# Fallback to hardcoded value
else
mc_version_source="hardcoded"
err "Warning! Using hardcoded version number"
fi
echo "Using latest MC version $MC_VERSION from the $MC_REPO repo (determined by $mc_version_source)"
}
# @description Installs a package using the system package manager
# @arg $1 array One or more package names
# @option --no-install-check Do not check if package is already installed
# @option --no-gpg-check Disable GPG checks for RPM based distros
# @option --allow-downgrades Useful for installing specific MC versions
# @option --silent | -s Do not print errors (useful for optional packages)
install_package() {
debug "Running: ${FUNCNAME[0]}" "$@"
local -a pkg_array install_flags
local -A pkg_aliases
local input pkg _pkg
local -i no_install_check=0 allow_downgrades=0 silent=0 refresh=0 no_gpg_check=0 reinstall=0
local long_opts="no-install-check,allow-downgrades,no-gpg-check,refresh,reinstall,silent"
input=$(getopt -o +s -l "$long_opts" -- "$@") || { err "Incorrect options provided"; exit 1; }
eval set -- "$input"
while true; do
case $1 in
--no-install-check) no_install_check=1 ;;
--allow-downgrades) allow_downgrades=1 ;;
--no-gpg-check) no_gpg_check=1 ;;
--refresh) refresh=1 ;;
--reinstall) reinstall=1 ;;
--silent|-s) silent=1 ;;
--) shift; break ;;
esac
shift
done
# Define package aliases based on the distribution
case $ID in
debian|ubuntu)
pkg_aliases=(
[rpm-build]="rpm"
[createrepo_c]="createrepo"
[tigervnc-server]="tigervnc-standalone-server"
) ;;
suse)
pkg_aliases=(
[buildah]="buildah fuse-overlayfs"
) ;;
esac
# Filter out already installed packages to create pkg_array
for pkg in "$@"; do
if [[ -v pkg_aliases[$pkg] ]]; then
debug "Aliasing $pkg to ${pkg_aliases[$pkg]}"
IFS=' ' read -ra pkgs <<< "${pkg_aliases[$pkg]}"
for _pkg in "${pkgs[@]}"; do
if ((no_install_check)) \
|| ! { command -v "$_pkg" &>/dev/null \
|| "${PKG_QUERY[@]}" "$_pkg" &>/dev/null; }; then
pkg_array+=("$_pkg")
else
debug "$_pkg is already installed, skipping installation"
fi
done
else
if ((no_install_check)) \
|| ! { command -v "$pkg" &>/dev/null \
|| "${PKG_QUERY[@]}" "$pkg" &>/dev/null; }; then
pkg_array+=("$pkg")
else
debug "$pkg is already installed, skipping installation"
fi
fi
done
# Generate installation flags based on the distribution
case $ID in
debian|ubuntu)
((allow_downgrades)) && install_flags+=(--allow-downgrades)
((reinstall)) && install_flags+=(--reinstall) ;;
fedora|centos)
((allow_downgrades)) && install_flags+=(--allowerasing)
((no_gpg_check)) && install_flags+=(--nogpgcheck)
((refresh)) && install_flags+=(--refresh)
;;
suse)
((no_gpg_check)) && install_flags+=(--allow-unsigned-rpm) ;;
esac
# Install packages if any need installation
if [[ ${#pkg_array[@]} -gt 0 ]]; then
if ! "${PKG_INSTALL[@]}" "${install_flags[@]}" "${pkg_array[@]}"; then
((silent)) || err "Failed to install ${pkg_array[*]}"
return 1
fi
fi
return 0
}
# @description install host-specific external repos
install_external_repos() {
debug "Running: ${FUNCNAME[0]}"
case $ID in
ubuntu)
if ! grep ^deb /etc/apt/sources.list.d/* | grep -q universe; then
echo "Adding universe repository"
if ! execute sudo add-apt-repository -y universe; then
err "Adding universe repository failed"
fi
fi
;;
centos)
if ! command -v dpkg &>/dev/null; then
echo "Adding EPEL repository"
install_package epel-release
fi
if ! "${PKG_QUERY[@]}" rpmfusion-free-release &>/dev/null; then
echo "Installing the RPMFusion repository"
install_package --no-install-check \
"https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
fi
# Install mesa-va-drivers-freeworld separately from the RPM using dnf swap
install_mesa_freeworld
;;
fedora)
if ! "${PKG_QUERY[@]}" rpmfusion-free-release &>/dev/null; then
echo "Installing the RPMFusion repository"
install_package --no-install-check \
"https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
fi
# Install mesa-va-drivers-freeworld separately from the RPM using dnf swap
install_mesa_freeworld
;;
suse) : # TODO may eventually be needed if X11_XOrg is not available by default
# if ! zypper repos | grep -q "X11_XOrg"; then
# echo "Installing the X11 repository"
# execute sudo zypper --non-interactive --quiet addrepo \
# "https://download.opensuse.org/repositories/X11:/XOrg/${NAME// /_}/X11:XOrg.repo"
# execute sudo zypper --non-interactive --quiet refresh
# fi
;;
esac
}
# @description Installs mesa-va-drivers-freeworld
install_mesa_freeworld() {
debug "Running: ${FUNCNAME[0]}"
swap_or_install_freeworld_package() {
local pkg=$1
local freeworld_pkg="${pkg}-freeworld"
if ! "${PKG_QUERY[@]}" "$freeworld_pkg" &>/dev/null; then
if "${PKG_QUERY[@]}" "$pkg" &>/dev/null; then
if ! execute sudo dnf swap -y "$pkg" "$freeworld_pkg"; then
err "Package swap failed for $pkg!"
fi
else
"${PKG_INSTALL[@]}" "$freeworld_pkg"
fi
fi
}
swap_or_install_freeworld_package "mesa-va-drivers"
swap_or_install_freeworld_package "mesa-vdpau-drivers"
}
# @description Installs JRiver Media Center from a remote repository
install_mc_repo() {
debug "Running: ${FUNCNAME[0]}"
local repo_file repo_text channel
case $ID in
fedora|centos)
repo_file="/etc/yum.repos.d/jriver.repo"
read -r -d '' repo_text <<-EOF
[jriver]
name=JRiver Media Center by BryanC
baseurl=https://repos.bryanroessler.com/jriver
gpgcheck=0
EOF
;;
debian|ubuntu)
[[ -n $BETAPASS ]] && channel="beta" || channel="latest"
local major_version="${VERSION_ID%%.*}"
local minor_version="${VERSION_ID##*.}"
local keyfile="/usr/share/keyrings/jriver-com-archive-keyring.gpg"
if [[ $ID == "ubuntu" ]] \
&& [[ $major_version -gt 24 || ($major_version -eq 24 && $minor_version -ge 10) ]]; then
if [[ $channel == "beta" ]]; then
repo_file="/etc/apt/sources.list.d/jriver-beta.sources"
else
repo_file="/etc/apt/sources.list.d/jriver.sources"
fi
old_repo_files=(
"/etc/apt/sources.list.d/jriver.list"
"/etc/apt/sources.list.d/jriver-beta.list"
"/etc/apt/sources.list.d/jriver_beta.list"
)
for f in "${old_repo_files[@]}"; do
[[ -f $f ]] && execute sudo rm -f "$f"
done
read -r -d '' repo_text <<-EOF
Types: deb
URIs: http://dist.jriver.com/$channel/mediacenter/
Signed-By: $keyfile
Suites: $MC_REPO
Components: main
EOF
else
if [[ $channel == "beta" ]]; then
execute sudo rm -f "/etc/apt/sources.list.d/jriver_beta.list"
repo_file="/etc/apt/sources.list.d/jriver-beta.list"
else
repo_file="/etc/apt/sources.list.d/jriver.list"
fi
repo_text="deb [signed-by=$keyfile arch=amd64,i386,armhf,arm64] http://dist.jriver.com/$channel/mediacenter/ $MC_REPO main"
fi
echo "Installing JRiver Media Center RPM key"
download "http://dist.jriver.com/[email protected]" |
gpg --dearmor | sudo tee "$keyfile" &>/dev/null
;;
*)
err "An MC repository for $ID is not yet available"
err "Use --install local to install MC on $ID"
return 1
;;
esac
echo "Adding MC repository file: $repo_file"
debug "repo_text: $repo_text"
sudo tee "$repo_file" &>/dev/null <<< "$repo_text"
if ! "${PKG_UPDATE[@]}"; then
err "Package update failed!"
return 1
fi
if ! install_package \
--no-install-check \
--allow-downgrades \
--no-gpg-check \
"$MC_PKG"; then
err "Package install failed!"
return 1
fi
}
# @description Acquires the source DEB package from JRiver
acquire_deb() {
debug "Running: ${FUNCNAME[0]}"
local fname="MediaCenter-$MC_VERSION-$ARCH.deb"
declare -g MC_DEB="$OUTPUT_DIR/SOURCES/$fname"
# If deb file already exists, skip download
if [[ -f $MC_DEB ]]; then
if [[ $(stat -c%s "$MC_DEB") -lt 10000000 ]]; then
echo "Removing existing DEB under 10MB: $MC_DEB"
execute rm "$MC_DEB"
else
echo "Using existing DEB: $MC_DEB"
return 0
fi
fi
# Define the repositories to check
local repos=(
"https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/$fname"
"https://files.jriver-cdn.com/mediacenter/test/$fname")
if [[ -n $BETAPASS ]]; then
repos=("https://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/beta/$BETAPASS/$fname" "${repos[@]}")
fi
# Loop through the repositories and attempt to download
for repo in "${repos[@]}"; do
echo "Checking $repo for DEB package"
if download "$repo" "$MC_DEB"; then
echo "Found"
break
fi
err "DEB file not found/downloaded"
return 1
done
[[ -f $MC_DEB ]]
}
# @description Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
build_rpm() {
debug "Running: ${FUNCNAME[0]}"
local i rpmbuild_cmd stub
local -a requires recommends
# skip rebuilding the rpm if it already exists
if [[ -f $MC_RPM ]]; then
echo "$MC_RPM already exists. Skipping build step"
return 0
fi
# Load deb dependencies into array
IFS=',' read -ra requires <<< "$(dpkg-deb -f "$MC_DEB" Depends)"
IFS=',' read -ra recommends <<< "$(dpkg-deb -f "$MC_DEB" Recommends)"
# Clean up formatting
requires=("${requires[@]%%|*}")
requires=("${requires[@]/?:/}")
requires=("${requires[@]# }")
requires=("${requires[@]% }")
requires=("${requires[@]//\(/}")
requires=("${requires[@]//)/}")
recommends=("${recommends[@]%%|*}")
recommends=("${recommends[@]/?:/}")
recommends=("${recommends[@]# }")
recommends=("${recommends[@]% }")
recommends=("${recommends[@]//\(/}")
recommends=("${recommends[@]//)/}")
# Translate package names
case $BUILD_TARGET in
fedora|centos)
requires=("${requires[@]/libc6/glibc}")
requires=("${requires[@]/libasound2/alsa-lib}")
requires=("${requires[@]/libuuid1/libuuid}")
requires=("${requires[@]/libx11-6/libX11}")
requires=("${requires[@]/libxext6/libXext}")
requires=("${requires[@]/libxcb1*/libxcb}") # TODO Remove minimum version for MC31 (*)
requires=("${requires[@]/libxdmcp6/libXdmcp}")
requires=("${requires[@]/libstdc++6/libstdc++}")
requires=("${requires[@]/libgtk-3-0/gtk3}")
requires=("${requires[@]/libgl1/mesa-libGL}")
requires=("${requires[@]/libpango-1.0-0/pango}")
requires=("${requires[@]/libpangoft2-1.0-0/pango}")
requires=("${requires[@]/libpangox-1.0-0/pango}")
requires=("${requires[@]/libpangoxft-1.0-0/pango}")
requires=("${requires[@]/libnss3/nss}")
requires=("${requires[@]/libnspr4/nspr}")
requires=("${requires[@]/libgomp1/libgomp}")
requires=("${requires[@]/libfribidi0/fribidi}")
requires=("${requires[@]/libfontconfig1/fontconfig}")
requires=("${requires[@]/libfreetype6/freetype}")
requires=("${requires[@]/libharfbuzz0b/harfbuzz}")
requires=("${requires[@]/libgbm1/mesa-libgbm}")
requires=("${requires[@]/libva2/libva}")
requires=("${requires[@]/libva-drm2/libva}")
requires=("${requires[@]/libepoxy0/libepoxy}")
requires=("${requires[@]/liblcms2-2/lcms2}")
requires=("${requires[@]/libvulkan1/vulkan-loader}")
requires=("${requires[@]/libepoxy0/libepoxy}")
requires=("${requires[@]/python/python3}")
requires=("${requires[@]/libwebkit2gtk*/webkit2gtk4.0}")
recommends+=(mesa-va-drivers-freeworld)
;;
suse)
requires=("${requires[@]/libc6/glibc}")
requires=("${requires[@]/libasound2/alsa-lib}")
requires=("${requires[@]/libx11-6/libX11-6}")
requires=("${requires[@]/libxext6/libXext6}")
requires=("${requires[@]/libxdmcp6/libXdmcp6}")
requires=("${requires[@]/libgtk-3-0/gtk3}")
requires=("${requires[@]/libgl1/Mesa-libGL1}")
requires=("${requires[@]/libpango-1.0-0/pango}")
requires=("${requires[@]/libpangoft2-1.0-0/pango}")
requires=("${requires[@]/libpangox-1.0-0/pango}")
requires=("${requires[@]/libpangoxft-1.0-0/pango}")
requires=("${requires[@]/libnss3/mozilla-nss}")
requires=("${requires[@]/libnspr4/mozilla-nspr}")
requires=("${requires[@]/libfribidi0/fribidi}")
requires=("${requires[@]/libfontconfig1/fontconfig}")
requires=("${requires[@]/libharfbuzz0b/libharfbuzz0}")
requires=("${requires[@]/libwebkit2gtk*/libwebkit2gtk-4_0-37}")
for i in "${!requires[@]}"; do
[[ ${requires[$i]} == "mesa-vulkan-drivers" ]] && unset -v 'requires[i]'
done
recommends+=(libvulkan_intel)
recommends+=(libvulkan_radeon)
;;
esac
# Convert array to newline delim'd string (for heredoc)
printf -v requires "Requires: %s\n" "${requires[@]}"
printf -v recommends "Recommends: %s\n" "${recommends[@]}"
# Strip last newline
requires="${requires%?}"
recommends="${recommends%?}"
if ((COMPAT_SWITCH)); then
# Strip minimum versions
requires=$(echo "$requires" | awk -F" " 'NF == 4 {print $1 " " $2} NF != 4 {print $0}')
fi
# Exclude MC stub executable <= MC31
if [[ $MC_MVERSION -le 31 ]]; then
stub=""
else
stub="%{_bindir}/mc$MC_MVERSION"
fi
# Create spec file
cat <<-EOF > "$OUTPUT_DIR/SPECS/mediacenter.spec"
Name: mediacenter$MC_MVERSION
Version: $MC_VERSION
Release: 1
Summary: JRiver Media Center
Group: Applications/Media
Source0: http://files.jriver-cdn.com/mediacenter/channels/v$MC_MVERSION/latest/MediaCenter-$MC_VERSION-$ARCH.deb
BuildArch: x86_64
%define _rpmfilename %%{ARCH}/%%{NAME}-%%{version}.%%{ARCH}.rpm
AutoReq: 0
$requires
$recommends
Conflicts: MediaCenter
Provides: mediacenter$MC_MVERSION
License: Copyright 1998-$(date +%Y), JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
URL: http://www.jriver.com/
%define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
%description
Media Center is more than a world class player.
%global __os_install_post %{nil}
%prep
%build
%install
dpkg -x %{S:0} %{buildroot}
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%{_bindir}/mediacenter$MC_MVERSION
$stub
%{_libdir}/jriver
%{_datadir}
%exclude %{_datadir}/applications/media_center_packageinstaller_$MC_MVERSION.desktop
/etc/security/limits.d/*
EOF
# Run rpmbuild
echo "Building MC $MC_VERSION RPM, this may take some time"
rpmbuild_cmd=(
rpmbuild
--define="%_topdir $OUTPUT_DIR"
--define="%_libdir /usr/lib"
-bb
"$OUTPUT_DIR/SPECS/mediacenter.spec"
)
if execute "${rpmbuild_cmd[@]}" && [[ -f $MC_RPM ]] ; then
echo "Build successful. The RPM file is located at: $MC_RPM"
else
err "Build failed"
# After failire, remove the source DEB and reaquire it on next run
[[ -f $MC_DEB ]] && echo "Removing source DEB" && execute rm -f "$MC_DEB"
exit 1
fi
}
# @description Installs Media Center DEB package and optional compatability fixes
install_mc_deb() {
debug "Running: ${FUNCNAME[0]}"
if ((COMPAT_SWITCH)); then
local extract_dir; extract_dir="$(mktemp -d)"
pushd "$extract_dir" &>/dev/null || return
command -v ar &>/dev/null || { install_package binutils || return 1; }
execute ar x "$MC_DEB"
execute tar xJf "control.tar.xz"
# Remove minimum version specifiers from control file
sed -i 's/ ([^)]*)//g' "control"
# Remove libwebkit2gtk and their fantastic package versioning strategy
sed -i 's/,\s*libwebkit2gtk[^,]*,\?|libwebkit2gtk[^,]*,\?//g' "control"
# TODO workaround for ZorinOS
[[ $ID == "ubuntu" && ${VERSION_ID%.*} -le 16 ]] \
&& grep -q zorin /etc/os-release \
&& sed -i 's/libva2/libva1/g' "control"
execute tar -cJf "control.tar.xz" "control" "postinst"
declare -g MC_DEB="${MC_DEB/.deb/.compat.deb}"
execute ar rcs "$MC_DEB" "debian-binary" "control.tar.xz" "data.tar.xz"
popd &>/dev/null || return
execute rm -rf "$extract_dir"
fi
# Use --reinstall to make sure local package is installed over repo package
if ! install_package \
--no-install-check \
--no-gpg-check \
--allow-downgrades \
--reinstall \
"$MC_DEB"; then
err "Local MC DEB installation failed"
err "Only the default MC repo can be used for --install=local"
if ask_ok "Remove source DEB and retry"; then
execute rm -f "$MC_DEB"
exec "$SCRIPT_PATH" "$@" "--no-update"
else
return 1
fi
fi
}
# @description Installs Media Center RPM package on RHEL distros
install_mc_rhel() {
debug "Running: ${FUNCNAME[0]}"
# Swap in freeworld hardware acceleration separately from the RPM
install_mesa_freeworld
install_package --no-install-check --no-gpg-check --allow-downgrades "$MC_RPM"
}
# @description Installs Media Center RPM package on SUSE
install_mc_suse() {
debug "Running: ${FUNCNAME[0]}"
install_package --no-install-check --no-gpg-check --allow-downgrades "$MC_RPM"
}
# @description Installs Media Center generically for unsupported OSes
install_mc_generic() {
debug "Running: ${FUNCNAME[0]}"
local extract_dir
local -a raw_files
echo "Using generic installation method"
extract_dir="$(mktemp -d)"
pushd "$extract_dir" &>/dev/null || return
execute ar x "$MC_DEB"
execute tar xJf "control.tar.xz"
echo "You must install the following dependencies manually:"
grep -i "Depends:" control
readarray -t raw_files < <(tar xJvf data.tar.xz)
# Output to log file
for f in "${raw_files[@]/#./}"; do
echo "$f" >> "$SCRIPT_DIR/.uninstall"
done
# Manually install files
for f in "${raw_files[@]}"; do
execute sudo cp -a "$f" "${f/#./}"
done
popd &>/dev/null || return
execute rm -rf "$extract_dir"
return 0
}
# @description Installs Media Center Arch PKGBUILD
install_mc_arch() {
debug "Running: ${FUNCNAME[0]}"
[[ -d $OUTPUT_DIR/PKGBUILD ]] || execute mkdir -p "$OUTPUT_DIR/PKGBUILD"
cat <<-EOF > "$OUTPUT_DIR/PKGBUILD/mediacenter.pkgbuild"
pkgname=mediacenter$MC_MVERSION
pkgver=$MC_VERSION
pkgrel=1
pkgdesc="The Most Comprehensive Media Software"
arch=('x86_64')
url="http://www.jriver.com/"
license=('custom')