-
Notifications
You must be signed in to change notification settings - Fork 372
/
Copy pathchroot_script
executable file
·227 lines (189 loc) · 6.99 KB
/
chroot_script
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env bash
set -x
set -e
# OctoPI generation script
# Helper script that runs in a Raspbian chroot to create the OctoPI distro
# Written by Guy Sheffer <guysoft at gmail dot com>
# GPL V3
source /common.sh
unpack /filesystem/home/pi /home/pi pi
unpack /filesystem/home/root /root root
unpack /filesystem/boot /boot
apt-get update
apt-get remove -y --purge scratch squeak-plugins-scratch squeak-vm wolfram-engine python-minecraftpi minecraft-pi sonic-pi oracle-java8-jdk
#apt-get octoprint virtualenv
apt-get -y --force-yes install python2.7 python-virtualenv python-dev git screen libts-bin subversion cmake checkinstall avahi-daemon libavahi-compat-libdnssd1
pushd /home/pi
#build virtualenv
sudo -u pi virtualenv --system-site-packages oprint
# OctoPrint & pyserial
if [ "$OCTOPI_INCLUDE_OCTOPRINT" == "yes" ]
then
echo "--- Installing OctoPrint"
apt-get install -y --force-yes python-numpy python-netifaces
apt-get remove -y python-serial
#pyserial that can handle non-standard baud rates
sudo -u pi svn co http://pyserial.svn.sourceforge.net/svnroot/pyserial/trunk pyserial
pushd pyserial/pyserial
sudo -u pi /home/pi/oprint/bin/python setup.py install
popd
#pybonjour (for mdns discovery)
sudo -u pi /home/pi/oprint/bin/pip install pybonjour
#OctoPrint
gitclone OCTOPI_OCTOPRINT_REPO OctoPrint
pushd OctoPrint
PIP_DEFAULT_TIMEOUT=60 sudo -u pi /home/pi/oprint/bin/python setup.py install
popd
fi
#OctoPiPanel
if [ "$OCTOPI_INCLUDE_OCTOPIPANEL" == "yes" ]
then
echo "--- Installing OctoPiPanel"
gitclone OCTOPI_OCTOPIPANEL_REPO OctoPiPanel
pushd OctoPiPanel
sudo -u pi /home/pi/oprint/bin/pip install -r requirements.txt
popd
#Add fbcp for TFT screens
gitclone OCTOPI_FBCP_REPO rpi-fbcp
pushd rpi-fbcp
sudo -u pi mkdir build
pushd build
sudo -u pi cmake ..
sudo -u pi make
install fbcp /usr/local/bin/fbcp
sudo -u pi make clean
popd
popd
fi
#mjpg-streamer
if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ]
then
echo "--- Installing mjpg-streamer"
apt-get -y --force-yes install libjpeg8-dev imagemagick libav-tools libv4l-dev
gitclone OCTOPI_MJPGSTREAMER_REPO mjpg-streamer
pushd mjpg-streamer
mv mjpg-streamer-experimental/* .
sudo -u pi make
popd
fi
#CuraEngine
if [ "$OCTOPI_INCLUDE_CURAENGINE" == "yes" ]
then
echo "--- Installing CuraEngine"
folder=CuraEngine-$OCTOPI_CURAENGINE_VERSION
zipfile=$folder.zip
apt-get -y install gcc-4.7 g++-4.7
sudo -u pi wget -O$zipfile $OCTOPI_CURAENGINE_ARCHIVE
sudo -u pi unzip $zipfile
pushd $folder
sudo -u pi wget https://gist.githubusercontent.com/foosel/f86d6a729c0187ff8a82/raw/3d4f152b924080f502d887d11269f27a2389d64d/CuraEngine.patch
sudo -u pi patch < CuraEngine.patch
sudo -u pi make CXX=g++-4.7 VERSION=$OCTOPI_CURAENGINE_VERSION
cp build/CuraEngine /usr/local/bin/cura_engine
popd
sudo -u pi rm -r $folder $zipfile
fi
#setup haproxy for http and https, and webcam
if [ "$OCTOPI_INCLUDE_HAPROXY" == "yes" ]
then
echo "--- Installing haproxy"
export HAPROXY_VERSION=OCTOPI_HAPROXY_VERSION
sudo apt-get -y --force-yes install ssl-cert libssl-dev libpcre3-dev
rm /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/certs/ssl-cert-snakeoil.pem
sudo -u pi wget $OCTOPI_HAPROXY_ARCHIVE
sudo -u pi tar xzvf haproxy-$OCTOPI_HAPROXY_VERSION.tar.gz
rm haproxy-$OCTOPI_HAPROXY_VERSION.tar.gz
sudo -u pi mv `ls | grep haproxy | head -n 1` haproxy-ss
pushd haproxy-ss
sudo -u pi make TARGET=linux2628 USE_LINUX_SPLICE=1 USE_LINUX_TPROXY=1 USE_PCRE=1 USE_OPENSSL=1
mkdir -p /usr/local/share/man/man1 /usr/local/doc /usr/local/doc/haproxy
sudo checkinstall --default --pkgname haproxy --pkgversion 1.5
popd
rm -rf haproxy-ss
adduser --system --disabled-password --disabled-login --home /var/lib/haproxy \
--no-create-home --quiet --force-badname --group haproxy
fi
popd
#Make sure user pi has access to serial ports
usermod -a -G tty pi
usermod -a -G dialout pi
# store octopi commit used to build this image
echo "$OCTOPI_COMMIT" > /etc/octopi_commit
# allow pi user to run shutdown and service commands
echo "pi ALL=NOPASSWD: /sbin/shutdown" > /etc/sudoers.d/octoprint-shutdown
echo "pi ALL=NOPASSWD: /sbin/service" > /etc/sudoers.d/octoprint-service
#reach printer by name
echo "$OCTOPI_OVERRIDE_HOSTNAME" > /etc/hostname
sed -i -e "s@raspberrypi@$OCTOPI_OVERRIDE_HOSTNAME@g" /etc/hosts
#make sure users don't run git with sudo, thus breaking permissions, by adding /root/bin to the
#default sudo path and placing a git wrapper script there that checks if it's run as root
sed -i "s@secure_path=\"@secure_path=\"/root/bin:@g" /etc/sudoers
chmod +x /root/bin/git
# enable raspicam
echo "# enable raspicam" >> /boot/config.txt
echo "start_x=1" >> /boot/config.txt
echo "gpu_mem=128" >> /boot/config.txt
# allow network configuration via /boot/octopi-network.txt
sed -i "s@wpa-conf@# wpa-conf@g" /etc/network/interfaces
sed -i "s@iface wlan@# iface wlan@g" /etc/network/interfaces
echo "source /boot/octopi-network.txt" >> /etc/network/interfaces
#unpack root in the end, so etc file are not overwritten, might need to add two roots int he future
unpack /filesystem/root /
#####################################################################
### setup services
### OctoPrint
if [ "$OCTOPI_INCLUDE_OCTOPRINT" == "yes" ]
then
update-rc.d octoprint defaults 95
else
# let's remove the configs for system services we don't need
rm /etc/init.d/octoprint
rm /etc/default/octoprint
fi
### haproxy
if [ "$OCTOPI_INCLUDE_HAPROXY" == "yes" ]
then
update-rc.d gencert defaults
update-rc.d haproxy defaults 99
else
# let's remove the configs for system services we don't need
rm /etc/init.d/gencert
rm /etc/init.d/haproxy
rm /etc/default/haproxy
rm /etc/logrotate.d/haproxy
rm /etc/rsyslog.d/49-haproxy.conf
# also we need to make OctoPrint bind to all interfaces because otherwise
# it will be unaccessible...
[ -f /etc/default/octoprint ] && sed -i "s@HOST=127.0.0.1@HOST=0.0.0.0@" /etc/default/octoprint
fi
### CuraEngine
if [ ! "$OCTOPI_INCLUDE_CURAENGINE" == "yes" ]
then
# unconfigure the cura engine path in octoprint's config.yaml
sudo -u pi sed -i -e "s@cura_engine: /usr/local/bin/cura_engine@cura_engine:@g" /home/pi/.octoprint/config.yaml
fi
### mjpg_streamer
if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ]
then
# make webcamd autostart
update-rc.d webcamd defaults
else
rm /etc/logrotate.d/webcamd
rm /etc/init.d/webcamd
rm /etc/default/webcamd
rm /root/bin/webcamd
fi
### OctoPiPanel
if [ ! "$OCTOPI_INCLUDE_OCTOPIPANEL" == "yes" ]
then
# we don't need the tft setup stuff
rm /home/pi/scripts/OctoPiPanel
rm /home/pi/scripts/calibrate-rpi-display
rm /home/pi/scripts/enable-adafruit-pitft
rm /home/pi/scripts/enable-rpi-display
rm /boot/cmdline-pi-tft.txt
rm /etc/udev/rules.d/95-ads7846.rules
fi
#cleanup
apt-get clean
apt-get autoremove -y