This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_instance.sh
78 lines (59 loc) · 2.34 KB
/
add_instance.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
#!/bin/bash
echo "$(date -u) - add_instance.sh" >>"$(pwd)"/logs/scripts.log
. sp.config
sep="# ----------------------------------- #"
printf "\n\nHow many SimplyPrint instances do you wish to set up? (write a number and press Enter)\n"
read -r addTotal
# shellcheck disable=SC2154
newTotal=$((total + addTotal))
printf "\n\nSetting up %s instances" "$addTotal"
. functions.sh
# Get ports now that all are removed;
get_ports
# shellcheck disable=SC2154
last_total_ports=$total_ports
for ((i = total; i < newTotal; i++)); do
printf "\n\n\n\n"
echo "$sep"
echo "- Printer $((i + 1)) setup"
if [ "$i" -gt "1" ]; then
echo " !! Do NOT remove any USB cables !! "
fi
echo "Insert the USB cable into the pi (cable must be connected to the printer, and printer must be turned on)"
printf "\n"
read -n 1 -s -r -p "Press any key when cable is inserted... "
# shellcheck disable=SC2154
last_ports=$return_ports # save last ports
get_ports # get ports now
if [ "$total_ports" -lt "$last_total_ports" ] || [ "$total_ports" -eq "$last_total_ports" ]; then
printf "\n\n\n # !!! Failed; has same amount of ports as before. Either previous USB was plugged out, or new one wasn't inserted / registered\n\n"
exit
fi
last_total_ports=$total_ports # set new 'last'
this_port=""
for x in $return_ports; do
if [[ ! " $last_ports " =~ $x ]]; then
# This (new) value doesn't exist in old array; is the new device
this_port=$x
fi
done
if [ "$this_port" == "" ]; then
# Could not find a new port...
printf "\n\n\n # !!! Failed; New device not detected, try again - maybe with a different cable? Make sure the printer's power supply is turned on.\n\n"
exit
else
# Found port! Let's continue
printf "\n\nDevice %s detected!\n" "$this_port"
dev_id=$(bash get_device_id.sh $this_port)
echo "spDevices[$i]=$dev_id,$this_port" >>sp.config
printf "Added to config: spDevices[$i]=%s\n\n" "$dev_id,$this_port"
fi
done
printf "\nHere are the links for octoprint, they will be offline until Docker is ready\n"
ip=$(ifconfig wlan0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
echo "ip: $ip"
for ((i = total; i < newTotal; i++)); do
echo "http://$ip:80$i/"
done
sed -i "s/total=[0-99]/total=${newTotal}/gI" sp.config
bash generate_yaml.sh