#!/usr/bin/env bash # OctoPI generation script # Helper script that runs in a Raspbian chroot to create the OctoPI distro # Written by Guy Sheffer and Gina Häußge # GPL V3 ######## set -x set -e export LC_ALL=C source /common.sh if [ -n "$OCTOPI_APTMIRROR" ]; then echo "Switching apt mirror in /etc/apt/sources.list to $OCTOPI_APTMIRROR" cp /etc/apt/sources.list /etc/apt/sources.list.backup sed -i "s@http://raspbian.raspberrypi.org/raspbian/@$OCTOPI_APTMIRROR@g" /etc/apt/sources.list fi WEBCAM_USER=webcam ### Script #### unpack /filesystem/home/pi /home/pi pi unpack /filesystem/home/root /root root unpack /filesystem/boot /boot apt-get update # in case we are building from a regular raspbian image instead of the lite one... remove_extra=$(remove_if_installed scratch squeak-plugins-scratch squeak-vm wolfram-engine python-minecraftpi minecraft-pi sonic-pi oracle-java8-jdk bluej libreoffice-common libreoffice-core freepats greenfoot nodered) echo "removing:" $remove_extra apt-get remove -y --purge $remove_extra apt-get autoremove -y apt-get -y --force-yes install python3 python3-virtualenv python3-dev git screen subversion cmake avahi-daemon libavahi-compat-libdnssd1 libffi-dev libssl-dev libatlas3-base echo " - Reinstall iputils-ping" apt-get install --reinstall iputils-ping pushd /home/pi # build virtualenv sudo -u pi python3 -m virtualenv --python=python3 oprint sudo -u pi /home/pi/oprint/bin/pip install --upgrade pip # OctoPrint if [ "$OCTOPI_INCLUDE_OCTOPRINT" == "yes" ] then echo "--- Installing OctoPrint" PIP_DEFAULT_TIMEOUT=60 sudo -u pi /home/pi/oprint/bin/pip install $OCTOPI_OCTOPRINT_ARCHIVE fi #mjpg-streamer if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ] then echo "--- Installing mjpg-streamer" if [ $( is_in_apt libjpeg62-turbo-dev ) -eq 1 ]; then apt-get -y --force-yes install libjpeg62-turbo-dev elif [ $( is_in_apt libjpeg8-dev ) -eq 1 ]; then apt-get -y --force-yes install libjpeg8-dev fi apt-get -y --force-yes --no-install-recommends install imagemagick ffmpeg libv4l-dev gitclone OCTOPI_MJPGSTREAMER_REPO mjpg-streamer pushd mjpg-streamer mv mjpg-streamer-experimental/* . # As said in Makefile, it is just a wrapper around CMake. # To apply -j option, we have to unwrap it. MJPG_STREAMER_BUILD_DIR=_build [ -d ${MJPG_STREAMER_BUILD_DIR} ] || (mkdir ${MJPG_STREAMER_BUILD_DIR} && \ chown pi:pi ${MJPG_STREAMER_BUILD_DIR}) [ -f ${MJPG_STREAMER_BUILD_DIR}/Makefile ] || (cd ${MJPG_STREAMER_BUILD_DIR} && \ sudo -u pi cmake -DCMAKE${MJPG_STREAMER_BUILD_DIR}_TYPE=Release ..) sudo -u pi make -j $(nproc) -C ${MJPG_STREAMER_BUILD_DIR} sudo -u pi cp ${MJPG_STREAMER_BUILD_DIR}/mjpg_streamer . sudo -u pi find ${MJPG_STREAMER_BUILD_DIR} -name "*.so" -type f -exec cp {} . \; # create our custom web folder and add a minimal index.html to it sudo -u pi mkdir www-octopi pushd www-octopi cat <> index.html mjpg_streamer test page

Snapshot

Refresh the page to refresh the snapshot

Snapshot

Stream

Stream EOT popd popd fi # FFMPEG HLS if [ "$OCTOPI_INCLUDE_FFMPEG_HLS" == "yes" ] then apt-get install -y --force-yes --no-install-recommends ffmpeg nginx useradd ${WEBCAM_USER} usermod -aG video ${WEBCAM_USER} 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.9 g++-4.9 sudo -u pi wget -O$zipfile $OCTOPI_CURAENGINE_ARCHIVE sudo -u pi unzip $zipfile pushd $folder sudo -u pi make -j$(nproc) CXX=g++-4.9 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" apt-get -y --force-yes install ssl-cert haproxy rm /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/certs/ssl-cert-snakeoil.pem fi if [ "$OCTOPI_INCLUDE_WIRINGPI" == "yes" ] then echo "--- Installing WiringPi" apt-get -y install wiringpi fi # fetch current yq build and install to /usr/local/bin wget -O yq $OCTOPI_YQ_DOWNLOAD && chmod +x yq && mv yq /usr/local/bin 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 # Keep legacy compatibility ln -s /etc/custompios_buildbase /etc/octopi_buildbase # allow pi user to run shutdown and service commands echo "pi ALL=NOPASSWD: /sbin/shutdown" > /etc/sudoers.d/octoprint-shutdown echo "pi ALL=NOPASSWD: /usr/sbin/service" > /etc/sudoers.d/octoprint-service #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 # add some "How To" info to boot output # Note, this code is also in /filesystem/home/pi/scripts/ sed -i 's@exit 0@@' /etc/rc.local cat <<'EOT' >> /etc/rc.local echo echo "------------------------------------------------------------" echo echo "You may now open a web browser on your local network and " echo "navigate to any of the following addresses to access " echo "OctoPrint:" echo for name in $_NAME; do echo " http://$name.local" done for ip in $(hostname -I); do echo " http://$ip" done echo echo "https is also available, with a self-signed certificate." echo echo "------------------------------------------------------------" echo EOT echo 'exit 0' >> /etc/rc.local # add a longer welcome text to ~pi/.bashrc echo "source /home/pi/scripts/welcome" >> /home/pi/.bashrc #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 ### Disable GUI at start systemctl_if_exists disable lightdm.service || true update-rc.d change_password defaults update-rc.d change_hostname defaults ### OctoPrint if [ "$OCTOPI_INCLUDE_OCTOPRINT" == "yes" ] then systemctl_if_exists enable octoprint.service else # let's remove the configs for system services we don't need rm /etc/systemd/system/octoprint.service fi ### haproxy if [ "$OCTOPI_INCLUDE_HAPROXY" == "yes" ] then systemctl_if_exists enable gencert.service else # let's remove the configs for system services we don't need rm /etc/systemd/system/gencert.service # also we need to make OctoPrint bind to all interfaces because otherwise # it will be unaccessible... [ -f /etc/systemd/system/octoprint.service ] && sed -i "s@HOST=127.0.0.1@HOST=0.0.0.0@" /etc/systemd/system/octoprint.service 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 ### Streamer select service. systemctl_if_exists enable streamer_select.service ### mjpg_streamer if [ "$OCTOPI_INCLUDE_MJPGSTREAMER" == "yes" ] then systemctl_if_exists enable webcamd.service else rm /etc/logrotate.d/webcamd rm /etc/systemd/system/webcamd.service rm /root/bin/webcamd fi ### HLS streamer systemctl_if_exists enable ffmpeg_hls.service #cleanup apt-get clean apt-get autoremove -y if [ -n "$OCTOPI_APTMIRROR" ]; then echo "Reverting /etc/apt/sources.list" mv /etc/apt/sources.list.backup /etc/apt/sources.list fi