#!/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 # 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