-
Notifications
You must be signed in to change notification settings - Fork 859
/
Copy pathinstall_prerequisites.sh
executable file
·197 lines (182 loc) · 6.06 KB
/
install_prerequisites.sh
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
#!/bin/bash
# exit when any command fails
set -e
MANAGERS=(dnf apt port vcpkg brew pacman)
MANAGER=""
LIST=0
VERBOSE=0
DRYRUN=0
UPDATE=0
REQUIRED_RECOMMENDED_ALL=1
SUDO=""
PKGS_UPDATE=""
PKGS_REQUIRED=()
PKGS_RECOMMENDED=()
PKGS_ALL=()
PKGS_OPTIONS=()
# Parse Command line
PARAMS=""
while (( "$#" )); do
case "$1" in
-v|--verbose)
VERBOSE=1
shift
;;
-d|--dry-run)
DRYRUN=1
shift
;;
-l|--list)
LIST=1
shift
;;
-u|--update-package-list)
UPDATE=1
shift
;;
-m|--package-manager)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
MANAGER=($2)
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
-h|--help)
echo "$0 [-vh] [-m package-manager-list] [required|recommended|all]"
echo " -m, --package-manager: preferred package manager order (default: \"${MANAGERS[*]}\")"
echo " -v, --verbose: verbose output"
echo " -d, --dry-run: print actions, but do not execute"
echo " -l, --list: just list the packages to install"
echo " -u, --update-package-list: update package manager package list"
echo " -h, --help: this help message"
echo " (required|recommended|all) the set of dependencies to select."
exit 0
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
PARAMS="$1"
shift
;;
esac
done
# Make lower case
PARAMS=$(echo "$PARAMS" | tr '[:upper:]' '[:lower:]' | tr -s "[:blank:]")
# Work out which set of dependencies we're installing
case "$PARAMS" in
required)
REQUIRED_RECOMMENDED_ALL=0
if ((VERBOSE > 0)); then echo "Selecting required dependencies only."; fi
;;
""|recommended)
REQUIRED_RECOMMENDED_ALL=1
if ((VERBOSE > 0)); then echo "Selecting required+recommended dependencies."; fi
;;
all)
REQUIRED_RECOMMENDED_ALL=2
if ((VERBOSE > 0)); then echo "Selecting all available dependencies."; fi
;;
*)
echo "Unrecognized positional argument \"$PARAMS\". Expecting one of (required,recommended [default],all)"
exit 1
;;
esac
# Find an available package manager from the preferred list
# if one has not already been selected manually.
if [ -z "$MANAGER" ]
then
for m in ${MANAGERS[@]}
do
if [ -x "$(command -v $m)" ]; then
MANAGER="$m"
break
fi
done
fi
# If no package manager is found, exit
if [ -z "$MANAGER" ]
then
echo "Error: No preferred package managers from list [${MANAGERS[*]}] found. Use -m to select manually." >&2
exit 1
fi
if ((VERBOSE > 0)); then echo "Using \"$MANAGER\" package manager (select another using -m)"; fi
# Setup prereq commands and packages.
if [[ "$MANAGER" == "apt" ]]; then
SUDO="sudo"
PKGS_UPDATE="apt update"
PKGS_OPTIONS+=(install --no-install-suggests --no-install-recommends)
if ((DRYRUN > 0)); then PKGS_OPTIONS+=(--dry-run); SUDO=""; fi
PKGS_REQUIRED+=(libgl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols libegl1-mesa-dev)
PKGS_REQUIRED+=(libc++-dev libepoxy-dev libglew-dev libeigen3-dev cmake g++ ninja-build)
PKGS_RECOMMENDED+=(libjpeg-dev libpng-dev catch2)
PKGS_RECOMMENDED+=(libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev)
PKGS_ALL+=(libdc1394-dev libraw1394-dev libopenni-dev python3-dev)
elif [[ "$MANAGER" == "dnf" ]]; then
SUDO="sudo"
PKGS_UPDATE="dnf check-update"
PKGS_OPTIONS+=(install)
PKGS_REQUIRED+=(wayland-devel libxkbcommon-devel g++ ninja-build)
PKGS_REQUIRED+=(epoxy-devel eigen3 cmake)
PKGS_RECOMMENDED+=(libjpeg-devel libpng-devel OpenEXR-devel catch2)
PKGS_ALL+=(libdc1394-devel libraw1394-devel librealsense-devel openni-devel)
if ((DRYRUN > 0)); then
MANAGER="echo $MANAGER"
SUDO=""
fi
elif [[ "$MANAGER" == "pacman" ]]; then
SUDO="sudo"
PKGS_UPDATE="" # databases and packages are updated in -Syu install options
PKGS_OPTIONS+=(-Syu --needed)
PKGS_REQUIRED+=(mesa wayland libxkbcommon wayland-protocols libc++ glew eigen cmake gcc ninja)
PKGS_RECOMMENDED+=(libjpeg-turbo libpng ffmpeg)
PKGS_ALL+=(libdc1394 libraw1394 openni python3)
if ((DRYRUN > 0)); then
MANAGER="echo $MANAGER"
SUDO=""
fi
elif [[ "$MANAGER" == "port" ]]; then
SUDO="sudo"
PKGS_UPDATE="port sync -q"
if ((DRYRUN > 0)); then PKGS_OPTIONS+=(-y); SUDO=""; fi
PKGS_OPTIONS+=(-N install -q)
PKGS_REQUIRED+=(glew eigen3-devel cmake +gui ninja)
PKGS_RECOMMENDED+=(libjpeg-turbo libpng openexr tiff ffmpeg-devel lz4 zstd py37-pybind11 catch2)
PKGS_ALL+=(libdc1394 openni)
elif [[ "$MANAGER" == "brew" ]]; then
PKGS_OPTIONS+=(install)
if ((VERBOSE > 0)); then PKGS_OPTIONS+=(--verbose); fi
PKGS_REQUIRED+=(glew eigen cmake ninja)
PKGS_RECOMMENDED+=(libjpeg-turbo libpng openexr libtiff ffmpeg lz4 zstd catch2 python-setuptools)
# Brew doesn't have a dryrun option
if ((DRYRUN > 0)); then
MANAGER="echo $MANAGER"
fi
elif [[ "$MANAGER" == "vcpkg" ]]; then
# TODO: this should be a config option somehow...
PKGS_OPTIONS+=(install --triplet=x64-windows )
if ((DRYRUN > 0)); then PKGS_OPTIONS+=(--dry-run); fi
PKGS_REQUIRED+=(glew eigen3 vcpkg-tool-ninja)
PKGS_RECOMMENDED+=(libjpeg-turbo libpng openexr tiff ffmpeg lz4 zstd python3 Catch2)
PKGS_ALL+=(openni2 realsense2)
else
echo "Error: Don't know how to use \"$MANAGER\", please fix the script." >&2
exit 1
fi
if ((REQUIRED_RECOMMENDED_ALL < 2)); then PKGS_ALL=(); fi
if ((REQUIRED_RECOMMENDED_ALL < 1)); then PKGS_RECOMMENDED=(); fi
PACKAGES=( "${PKGS_REQUIRED[*]}" "${PKGS_RECOMMENDED[*]}" "${PKGS_ALL[*]}" )
if ((LIST > 0)); then
echo "${PACKAGES[*]}"
exit 0
fi
if ((UPDATE > 0)); then
if ((VERBOSE > 0)); then echo "Requesting \"$MANAGER\" package update."; fi
$SUDO $PKGS_UPDATE
fi
if ((VERBOSE > 0)); then echo "Requesting install of: ${PACKAGES[*]}"; fi
# Install
$SUDO $MANAGER ${PKGS_OPTIONS[*]} ${PACKAGES[*]}