|
1 | 1 | #!/bin/bash
|
2 |
| - |
3 |
| -needs_arg() { |
4 |
| - if [ -z "$OPTARG" ]; then |
5 |
| - die "Argument is required for --$OPT option" \ |
6 |
| - "See './install.sh -h' for more information." |
7 |
| - fi; |
8 |
| -} |
9 |
| - |
10 |
| -die() { |
11 |
| - for arg in "$@"; do |
12 |
| - echo "$arg" 1>&2 |
13 |
| - done |
14 |
| - exit 1 |
15 |
| -} |
16 |
| - |
17 |
| -debug() { |
18 |
| - if [ -z "$QUIET" ] ; then |
19 |
| - for arg in "$@"; do |
20 |
| - echo "$arg" |
21 |
| - done |
22 |
| - fi |
23 |
| -} |
24 |
| - |
25 |
| -package_is_installed(){ |
26 |
| - dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q "ok installed" |
27 |
| -} |
28 |
| - |
29 |
| -install_if_missing() { |
30 |
| - if package_is_installed "$1" ; then |
31 |
| - debug "Found existing $1. Skipping..." |
32 |
| - return |
33 |
| - fi |
34 |
| - |
35 |
| - debug "Installing $1..." |
36 |
| - apt-get install --yes "$1" |
37 |
| - debug "$1 installation complete." |
38 |
| -} |
39 |
| - |
40 |
| -get_photonvision_releases() { |
41 |
| - # Return cached input |
42 |
| - if [ -n "$PHOTON_VISION_RELEASES" ] ; then |
43 |
| - echo "$PHOTON_VISION_RELEASES" |
44 |
| - return |
45 |
| - fi |
46 |
| - |
47 |
| - # Use curl if available, otherwise fallback to wget |
48 |
| - if command -v curl > /dev/null 2>&1 ; then |
49 |
| - PHOTON_VISION_RELEASES="$(curl -sk https://api.github.com/repos/photonvision/photonvision/releases)" |
50 |
| - else |
51 |
| - PHOTON_VISION_RELEASES="$(wget -qO- https://api.github.com/repos/photonvision/photonvision/releases)" |
52 |
| - fi |
53 |
| - |
54 |
| - echo "$PHOTON_VISION_RELEASES" |
55 |
| -} |
56 |
| - |
57 |
| -get_versions() { |
58 |
| - if [ -z "$PHOTON_VISION_VERSIONS" ] ; then |
59 |
| - PHOTON_VISION_VERSIONS=$(get_photonvision_releases | \ |
60 |
| - sed -En 's/\"tag_name\": \"v([0-9]+\.[0-9]+\.[0-9]+)(-(beta|alpha)(-[0-9])?(\.[0-9]+)?)?\",/\1\2/p' | \ |
61 |
| - sed 's/^[[:space:]]*//') |
62 |
| - fi |
63 |
| - |
64 |
| - echo "$PHOTON_VISION_VERSIONS" |
65 |
| -} |
66 |
| - |
67 |
| -is_version_available() { |
68 |
| - local target_version="$1" |
69 |
| - |
70 |
| - # latest is a special case |
71 |
| - if [ "$target_version" = "latest" ]; then |
72 |
| - return 0 |
73 |
| - fi |
74 |
| - |
75 |
| - # Check if multiple lines are match. You can only match 1. |
76 |
| - if [ "$(get_versions | grep -cFx "$target_version")" -ne 1 ] ; then |
77 |
| - return 1 |
78 |
| - fi |
79 |
| - |
80 |
| - return 0 |
81 |
| -} |
82 |
| - |
83 |
| -help() { |
84 |
| - cat << EOF |
85 |
| -This script installs Photonvision. |
86 |
| -It must be run as root. |
87 |
| -
|
88 |
| -Syntax: sudo ./install.sh [options] |
89 |
| - options: |
90 |
| - -h, --help |
91 |
| - Display this help message. |
92 |
| - -l, --list-versions |
93 |
| - Lists all available versions of PhotonVision. |
94 |
| - -v <version>, --version=<version> |
95 |
| - Specifies which version of PhotonVision to install. |
96 |
| - If not specified, the latest stable release is installed. |
97 |
| - Ignores leading 'v's. |
98 |
| - -a <arch>, --arch=<arch> |
99 |
| - Install PhotonVision for the specified architecture. |
100 |
| - Supported values: aarch64, x86_64 |
101 |
| - -m [option], --install-nm=[option] |
102 |
| - Controls NetworkManager installation (Ubuntu only). |
103 |
| - Options: "yes", "no", "ask". |
104 |
| - Default: "ask" (unless -q or --quiet is specified, then "no"). |
105 |
| - "ask" prompts for installation. Ignored on other distros. |
106 |
| - -n, --no-networking |
107 |
| - Disable networking. This will also prevent installation of |
108 |
| - NetworkManager, overriding -m,--install-nm. |
109 |
| - -q, --quiet |
110 |
| - Silent install, automatically accepts all defaults. For |
111 |
| - non-interactive use. Makes -m,--install-nm default to "no". |
112 |
| -
|
113 |
| -EOF |
114 |
| -} |
115 |
| - |
116 |
| -INSTALL_NETWORK_MANAGER="ask" |
117 |
| -VERSION="latest" |
118 |
| - |
119 |
| -while getopts "hlv:a:mnq-:" OPT; do |
120 |
| - if [ "$OPT" = "-" ]; then |
121 |
| - OPT="${OPTARG%%=*}" # extract long option name |
122 |
| - OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty) |
123 |
| - OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` |
124 |
| - fi |
125 |
| - |
126 |
| - case "$OPT" in |
127 |
| - h | help) |
128 |
| - help |
129 |
| - exit 0 |
130 |
| - ;; |
131 |
| - l | list-versions) |
132 |
| - get_versions |
133 |
| - exit 0 |
134 |
| - ;; |
135 |
| - v | version) |
136 |
| - needs_arg |
137 |
| - VERSION=${OPTARG#v} # drop leading 'v's |
138 |
| - ;; |
139 |
| - a | arch) needs_arg; ARCH=$OPTARG |
140 |
| - ;; |
141 |
| - m | install-nm) |
142 |
| - INSTALL_NETWORK_MANAGER="$(echo "${OPTARG:-'yes'}" | tr '[:upper:]' '[:lower:]')" |
143 |
| - case "$INSTALL_NETWORK_MANAGER" in |
144 |
| - yes) |
145 |
| - ;; |
146 |
| - no) |
147 |
| - ;; |
148 |
| - ask) |
149 |
| - ;; |
150 |
| - * ) |
151 |
| - die "Valid options for -m, --install-nm are: 'yes', 'no', and 'ask'" |
152 |
| - ;; |
153 |
| - esac |
154 |
| - ;; |
155 |
| - n | no-networking) DISABLE_NETWORKING="true" |
156 |
| - ;; |
157 |
| - q | quiet) QUIET="true" |
158 |
| - ;; |
159 |
| - \?) # Handle invalid short options |
160 |
| - die "Error: Invalid option -$OPTARG" \ |
161 |
| - "See './install.sh -h' for more information." |
162 |
| - ;; |
163 |
| - * ) # Handle invalid long options |
164 |
| - die "Error: Invalid option --$OPT" \ |
165 |
| - "See './install.sh -h' for more information." |
166 |
| - ;; |
167 |
| - esac |
168 |
| -done |
169 |
| - |
170 |
| -if [ "$(id -u)" != "0" ]; then |
171 |
| - die "This script must be run as root" |
172 |
| -fi |
173 |
| - |
174 |
| -if [[ -z "$ARCH" ]]; then |
175 |
| - debug "Arch was not specified. Inferring..." |
176 |
| - ARCH=$(uname -m) |
177 |
| - debug "Arch was inferred to be $ARCH" |
178 |
| -fi |
179 |
| - |
180 |
| -ARCH_NAME="" |
181 |
| -if [ "$ARCH" = "aarch64" ]; then |
182 |
| - ARCH_NAME="linuxarm64" |
183 |
| -elif [ "$ARCH" = "armv7l" ]; then |
184 |
| - die "ARM32 is not supported by PhotonVision. Exiting." |
185 |
| -elif [ "$ARCH" = "x86_64" ]; then |
186 |
| - ARCH_NAME="linuxx64" |
187 |
| -else |
188 |
| - die "Unsupported or unknown architecture: '$ARCH'." \ |
189 |
| - "Please specify your architecture using: ./install.sh -a <arch> " \ |
190 |
| - "Run './install.sh -h' for more information." |
191 |
| -fi |
192 |
| - |
193 |
| -debug "This is the installation script for PhotonVision." |
194 |
| -debug "Installing for platform $ARCH" |
195 |
| - |
196 |
| -DISTRO=$(lsb_release -is) |
197 |
| - |
198 |
| -# Only ask if it makes sense to do so. |
199 |
| -# i.e. the distro is Ubuntu, you haven't requested disabling networking, |
200 |
| -# and you have requested a quiet install. |
201 |
| -if [[ "$INSTALL_NETWORK_MANAGER" == "ask" ]]; then |
202 |
| - if [[ "$DISTRO" != "Ubuntu" || -n "$DISABLE_NETWORKING" || -n "$QUIET" ]] ; then |
203 |
| - INSTALL_NETWORK_MANAGER="no" |
204 |
| - fi |
205 |
| -fi |
206 |
| - |
207 |
| -if [[ "$INSTALL_NETWORK_MANAGER" == "ask" ]]; then |
208 |
| - debug "" |
209 |
| - debug "Photonvision uses NetworkManager to control networking on your device." |
210 |
| - debug "This could possibly mess up the network configuration in Ubuntu." |
211 |
| - read -p "Do you want this script to install and configure NetworkManager? [y/N]: " response |
212 |
| - if [[ $response == [yY] || $response == [yY][eE][sS] ]]; then |
213 |
| - INSTALL_NETWORK_MANAGER="yes" |
214 |
| - fi |
215 |
| -fi |
216 |
| - |
217 |
| -debug "Updating package list..." |
218 |
| -apt-get update |
219 |
| -debug "Updated package list." |
220 |
| - |
221 |
| -install_if_missing curl |
222 |
| -install_if_missing avahi-daemon |
223 |
| -install_if_missing cpufrequtils |
224 |
| -install_if_missing libatomic1 |
225 |
| -install_if_missing v4l-utils |
226 |
| -install_if_missing sqlite3 |
227 |
| -install_if_missing openjdk-17-jre-headless |
228 |
| - |
229 |
| -debug "Setting cpufrequtils to performance mode" |
230 |
| -if [ -f /etc/default/cpufrequtils ]; then |
231 |
| - sed -i -e 's/^#\?GOVERNOR=.*$/GOVERNOR=performance/' /etc/default/cpufrequtils |
232 |
| -else |
233 |
| - echo 'GOVERNOR=performance' > /etc/default/cpufrequtils |
234 |
| -fi |
235 |
| - |
236 |
| -if [[ "$INSTALL_NETWORK_MANAGER" == "yes" ]]; then |
237 |
| - debug "NetworkManager installation specified. Installing components..." |
238 |
| - install_if_missing network-manager |
239 |
| - install_if_missing net-tools |
240 |
| - |
241 |
| - debug "Configuring..." |
242 |
| - systemctl disable systemd-networkd-wait-online.service |
243 |
| - cat > /etc/netplan/00-default-nm-renderer.yaml <<EOF |
244 |
| -network: |
245 |
| - renderer: NetworkManager |
246 |
| -EOF |
247 |
| - debug "network-manager installation complete." |
248 |
| -fi |
249 |
| - |
250 |
| -debug "" |
251 |
| -debug "Installing additional math packages" |
252 |
| -if [[ "$DISTRO" = "Ubuntu" && -z $(apt-cache search libcholmod3) ]]; then |
253 |
| - debug "Adding jammy to list of apt sources" |
254 |
| - add-apt-repository -y -S 'deb http://ports.ubuntu.com/ubuntu-ports jammy main universe' |
255 |
| -fi |
256 |
| - |
257 |
| -install_if_missing libcholmod3 |
258 |
| -install_if_missing liblapack3 |
259 |
| -install_if_missing libsuitesparseconfig5 |
260 |
| - |
261 |
| -debug "" |
262 |
| - |
263 |
| -if ! is_version_available "$VERSION" ; then |
264 |
| - die "PhotonVision v$VERSION is not available" \ |
265 |
| - "See ./install --list-versions for a complete list of available versions." |
266 |
| -fi |
267 |
| - |
268 |
| -if [ "$VERSION" = "latest" ] ; then |
269 |
| - RELEASE_URL="https://api.github.com/repos/photonvision/photonvision/releases/latest" |
270 |
| - debug "Downloading PhotonVision (latest)..." |
271 |
| -else |
272 |
| - RELEASE_URL="https://api.github.com/repos/photonvision/photonvision/releases/tags/v$VERSION" |
273 |
| - debug "Downloading PhotonVision (v$VERSION)..." |
274 |
| -fi |
275 |
| - |
276 |
| -mkdir -p /opt/photonvision |
277 |
| -cd /opt/photonvision || die "Tried to enter /opt/photonvision, but it was not created." |
278 |
| -curl -sk "$RELEASE_URL" | |
279 |
| - grep "browser_download_url.*$ARCH_NAME.jar" | |
280 |
| - cut -d : -f 2,3 | |
281 |
| - tr -d '"' | |
282 |
| - wget -qi - -O photonvision.jar |
283 |
| -debug "Downloaded PhotonVision." |
284 |
| - |
285 |
| -debug "Creating the PhotonVision systemd service..." |
286 |
| - |
287 |
| -# service --status-all doesn't list photonvision on OrangePi use systemctl instead: |
288 |
| -if systemctl --quiet is-active photonvision; then |
289 |
| - debug "PhotonVision is already running. Stopping service." |
290 |
| - systemctl stop photonvision |
291 |
| - systemctl disable photonvision |
292 |
| - rm /lib/systemd/system/photonvision.service |
293 |
| - rm /etc/systemd/system/photonvision.service |
294 |
| - systemctl daemon-reload |
295 |
| - systemctl reset-failed |
296 |
| -fi |
297 |
| - |
298 |
| -cat > /lib/systemd/system/photonvision.service <<EOF |
299 |
| -[Unit] |
300 |
| -Description=Service that runs PhotonVision |
301 |
| -
|
302 |
| -[Service] |
303 |
| -WorkingDirectory=/opt/photonvision |
304 |
| -# Run photonvision at "nice" -10, which is higher priority than standard |
305 |
| -Nice=-10 |
306 |
| -# for non-uniform CPUs, like big.LITTLE, you want to select the big cores |
307 |
| -# look up the right values for your CPU |
308 |
| -# AllowedCPUs=4-7 |
309 |
| -
|
310 |
| -ExecStart=/usr/bin/java -Xmx512m -jar /opt/photonvision/photonvision.jar |
311 |
| -ExecStop=/bin/systemctl kill photonvision |
312 |
| -Type=simple |
313 |
| -Restart=on-failure |
314 |
| -RestartSec=1 |
315 |
| -
|
316 |
| -[Install] |
317 |
| -WantedBy=multi-user.target |
318 |
| -EOF |
319 |
| - |
320 |
| -if [ "$DISABLE_NETWORKING" = "true" ]; then |
321 |
| - sed -i "s/photonvision.jar/photonvision.jar -n/" /lib/systemd/system/photonvision.service |
322 |
| -fi |
323 |
| - |
324 |
| -if grep -q "RK3588" /proc/cpuinfo; then |
325 |
| - debug "This has a Rockchip RK3588, enabling all cores" |
326 |
| - sed -i 's/# AllowedCPUs=4-7/AllowedCPUs=4-7/g' /lib/systemd/system/photonvision.service |
327 |
| -fi |
328 |
| - |
329 |
| -cp /lib/systemd/system/photonvision.service /etc/systemd/system/photonvision.service |
330 |
| -chmod 644 /etc/systemd/system/photonvision.service |
331 |
| -systemctl daemon-reload |
332 |
| -systemctl enable photonvision.service |
333 |
| - |
334 |
| -debug "Created PhotonVision systemd service." |
335 |
| - |
336 |
| -debug "PhotonVision installation successful." |
| 2 | +# The install script is now in photon-image-modifier |
| 3 | +# this downloads and runs that install script for people using the old short URL |
| 4 | +wget -q https://raw.githubusercontent.com/PhotonVision/photon-image-modifier/master/install.sh -O ./real_install.sh |
| 5 | +chmod +x ./real_install.sh |
| 6 | +./real_install.sh "$@" |
| 7 | +rm ./real_install.sh |
0 commit comments