-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·125 lines (105 loc) · 3.41 KB
/
update.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
#!/bin/bash
###### Configuration variables - please edit #########
KLIPPER_PATH=/home/pi/klipper
PICO_CONF=.config.pico
SPIDER_CONF=.config.spider
PICOTOOL_BIN_PATH=/home/pi/repos/picotool/build/picotool
###### Configuration end - DO NOT EDIT BELOW #########
#colors
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
function checkSudo() {
if [ "$EUID" -ne 0 ]
then echo -e "${RED}This script needs to be run with sudo to work properly, terminating...${ENDCOLOR}"
exit 1
fi
}
function pause(){
read -p "$*"
}
function checkPicotool() {
#check if picotool is installed, if it's correct binary, so you don't accidentaly reboot your machine
if [ -f "$PICOTOOL_BIN_PATH" ]; then
if ! objdump -s "$PICOTOOL_BIN_PATH" | grep -q picotool; then
echo -e "${RED}Invalid path or picotool binary, install it from https://github.com/raspberrypi/picotool, exiting...${ENDCOLOR}"
exit 1
else
echo -e "${GREEN}Picotool found${ENDCOLOR}"
fi
else
echo -e "${RED}Picotool not found, exiting...${ENDCOLOR}"
exit 1
fi
}
function findPico() {
#find pico
if pico=$(find /dev/serial/by-id/ -name "*rp2040*" 2>/dev/null); then
echo -e "${GREEN}Pico path: $pico ${ENDCOLOR}"
elif pico_bootsel=$(udevadm info /dev/pico 2>/dev/null); then
pico=$(echo "$pico_bootsel" | grep ACM)
echo -e "${RED}Pico found in BOOTSEL mode, rebooting pico...${ENDCOLOR}"
$PICOTOOL_BIN_PATH reboot
sleep 5
exec bash "$0"
else
echo -e "${RED}Pico not found, re-plug needed, exiting...${ENDCOLOR}"
kill -INT $$
fi
}
function check_udev_rule() {
if [ ! -s /etc/udev/rules.d/99-pico.rules ]; then
cat << EOF > /etc/udev/rules.d/99-pico.rules
SUBSYSTEM=="tty", ATTRS{product}=="rp2040",SYMLINK+="pico"
EOF
udevadm control --reload
echo -e "${GREEN}udev rule for pico added and reloaded, continuing...${ENDCOLOR}"
fi
}
function checkKlipper() {
if [ ! -d $KLIPPER_PATH ]; then
echo -e "${RED}Klipper directory ${KLIPPER_PATH} doesn't exists, exiting${ENDCOLOR}"
exit 1
elif [ ! -f $KLIPPER_PATH/$PICO_CONF ]; then
echo -e "${RED}Pico config $KLIPPER_PATH/$PICO_CONF doesn't exists, exiting${ENDCOLOR}"
exit 1
elif [ ! -f $KLIPPER_PATH/$SPIDER_CONF ]; then
echo -e "${RED}Spider config $KLIPPER_PATH/$SPIDER_CONF doesn't exists, exiting${ENDCOLOR}"
exit 1
else
echo -e "${GREEN}All Klipper configs are present, Klipper directory valid${ENDCOLOR}"
fi
}
function updateSpider() {
# Update Spider
echo "*** Updating Spider ***"
cp .config.spider .config
make clean
make
make flash FLASH_DEVICE=/dev/serial/by-id/usb-Klipper_stm32f446xx_4B0032000250563046353420-if00
pause "Spider updated, press ENTER to continue with Pico"
}
pause "Press ENTER to start the update"
checkSudo
checkKlipper
checkPicotool
findPico
check_udev_rule
cd $KLIPPER_PATH
#Stop Klipper
echo "*** Stopping Klipper ***"
sudo service klipper stop
# Update Spide
updateSpider
#Update Pico
#echo "*** Updating Pico ***"
#cp .config.pico .config
#make clean
#make
#make flash FLASH_DEVICE=/dev/serial/by-id/usb-Klipper_rp2040_E6609CB2D3243128-if00
#echo "waiting for Pico to come up"
#while [ ! -e "/dev/serial/by-id/usb-Klipper_rp2040_E6609CB2D3243128-if00" ]; do sleep 0.1; done
echo "*** Starting Klipper again ***"
sudo service klipper start
echo "*** Update Complete ***"