-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_zero_overshoot.sh
executable file
·67 lines (58 loc) · 1.69 KB
/
install_zero_overshoot.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
#!/bin/bash
# Force script to exit if an error occurs
set -e
KLIPPER_PATH="${HOME}/klipper"
SYSTEMDDIR="/etc/systemd/system"
EXTENSION_LIST="zero_overshoot.py"
#SRCDIR = /home/pi/Zero_Overshoot
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/ && pwd )"
# Step 1: Verify Klipper has been installed
function check_klipper() {
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
echo "Klipper service found!"
else
echo "Klipper service not found, please install Klipper first"
exit -1
fi
}
# Step 2: Check if the extensions are already present.
# This is a way to check if this is the initial installation.
function check_existing() {
local -i existing=0
for extension in ${EXTENSION_LIST}; do
[ -e "${KLIPPER_PATH}/klippy/extras/${extension}" ] && existing=1 || existing=0
[ ${existing} -eq 0 ] && break
done
echo ${existing}
}
# Step 3: Link extension to Klipper
function link_extension() {
echo "Linking extensions to Klipper..."
for extension in ${EXTENSION_LIST}; do
ln -sf "${SRCDIR}/${extension}" "${KLIPPER_PATH}/klippy/extras/${extension}"
done
}
# Step 4: Optionally, restarting Klipper
function restart_klipper() {
echo "Restarting Klipper..."
sudo systemctl restart klipper
}
function verify_ready() {
if [ "$(id -u)" -eq 0 ]; then
echo "This script must not run as root"
exit -1
fi
check_klipper
}
while getopts "k:" arg; do
case ${arg} in
k) KLIPPER_PATH=${OPTARG} ;;
esac
done
verify_ready
existing_install=$(check_existing)
link_extension
if [ ${existing_install} -eq 0 ]; then
restart_klipper
fi
exit 0