forked from rudetrooper/Octoprint-Chituboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChituboard.sh
127 lines (105 loc) · 3.34 KB
/
Chituboard.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
126
127
#!/usr/bin/env bash
# filename: Chituboard.sh
# modified version of Kenzillla's Mariner+Samba Auto-Installer
function info { echo -e "\e[32m[info] $*\e[39m"; }
function warn { echo -e "\e[33m[warn] $*\e[39m"; }
function error { echo -e "\e[31m[error] $*\e[39m"; exit 1; }
if ! [ "$(id -u)" = 0 ]; then
warn "This script needs to be run as root." >&2
exit 1
fi
# check if the reboot flag file exists.
# We created this file before rebooting.
if [ ! -f ./resume-Chituboard ]; then
warn "running script for the first time.."
# run your scripts here
info
info "Welcome to Octoprint+Samba Auto-Installer!"
sleep .1
info "..."
sleep 1
# remove this part, octoprint install is already expanded filesystem
warn "It is a good idea to change your password from the default"
while true
do
read -r -p "Change now? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
info
echo "$(passwd pi)"
break
;;
[nN][oO]|[nN])
break
;;
*)
warn "Invalid input..."
esac
done
# create a flag file to check if we are resuming from reboot.
sudo touch ./resume-Chituboard
info "rebooting.."
# reboot here
sudo reboot
sleep 5
else
warn "resuming script after reboot.."
# remove the temporary file that we created to check for reboot
sudo rm -f ./resume-Chituboard
# continue with rest of the script
info
info "Setting up Chituboard prerequisites"
echo "dtoverlay=dwc2,dr_mode=peripheral" >> /boot/config.txt
echo "enable_uart=1" >> /boot/config.txt
sudo sed -i 's/console=serial0,115200 //g' /boot/cmdline.txt
echo -n " modules-load=dwc2" >> /boot/cmdline.txt
# setup 4 GB container file to for storing uploaded files
info
info "Setting up Pi-USB; this could take several minutes"
sudo dd bs=1M if=/dev/zero of=/piusb.bin count=4096
sudo mkdosfs /piusb.bin -F 32 -I
# Create the mount point for the container file
sudo mkdir /home/pi/.octoprint/uploads/resin
echo "/piusb.bin /home/pi/.octoprint/uploads/resin vfat users,uid=pi,gid=pi,umask=000 0 2 " >> /etc/fstab
sudo mount -a
sudo sed -i 's/exit 0//g' /etc/rc.local
echo '/bin/sleep 5
modprobe g_mass_storage file=/piusb.bin removable=1 ro=0 stall=0
exit 0' >> /etc/rc.local
sudo systemctl stop serial-getty@ttyS0
sudo systemctl disable serial-getty@ttyS0
info ""
info "Setting up Sambashare; this could take a long time"
sudo apt-get -y install samba winbind -y
read -r -p "Enter a short description of your printer, like the model: " model
echo "[USB_Share]
comment = $model
path = /home/pi/.octoprint/uploads/resin/
browseable = Yes
writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
public = yes
read only = no
force user = root
force group = root" >> /etc/samba/smb.conf
info ""
while true
do
read -r -p "Reboot now? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
warn "Rebooting in 5 seconds"
sleep 5
echo "$(sudo reboot)"
break
;;
[nN][oO]|[nN])
break
;;
*)
warn "Invalid input..."
esac
done
fi