-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-software
executable file
·42 lines (32 loc) · 1.29 KB
/
update-software
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
#!/bin/bash
set -euo pipefail
set -x
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
set +x
# Get the directory containing this file, resolving symlinks (based on code from https://stackoverflow.com/a/51651602)
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
home_dir="$(readlink -e "$script_dir/../../..")"
user_home_dir_regex="^/home/([^/]+?)/$"
if [[ "$home_dir/" =~ $user_home_dir_regex ]]; then
username=${BASH_REMATCH[1]}
else
>&2 echo "Unable to parse username from the (presumed) home directory of the RPi's user: $home_dir"
>&2 echo " (script location: $script_dir)"
exit 1
fi
octoprint_python="$home_dir/oprint/bin/python"
echo "+ Executing commands as user '$username':"
# Switch to the RPi's user, to prevent potentially setting `root` as the owner of any files the below commands might create/modify
sudo su "$username" <<HERE
set -euo pipefail
cd "$home_dir"
echo "+ Updating pip..."
# Update pip before updating other packages below
eval "$octoprint_python -m pip install -U pip"
echo "+ Updating OctoPrint and plugins..."
# Command found at https://docs.octoprint.org/en/master/bundledplugins/softwareupdate.html#command-line-usage
eval "$octoprint_python -m octoprint plugins softwareupdate:update"
HERE
echo "+ Finished executing commands as user '$username'"