diff --git a/TODO.md b/TODO.md index 29703b1..d8212ad 100644 --- a/TODO.md +++ b/TODO.md @@ -12,5 +12,7 @@ - Add on screen keyboard to Openbox autostart ## Misc +- Add MJPEG streamer - 64 bit builds - More security +- e diff --git a/build.sh b/build.sh index 3777193..5da3653 100755 --- a/build.sh +++ b/build.sh @@ -153,12 +153,11 @@ fi export USE_QEMU="${USE_QEMU:-0}" export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}" -export IMG_TIME="${IMG_TIME:-"$(date +%s)"}" -export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_TIME}-${IMG_NAME}"}" -export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_TIME}-${IMG_NAME}"}" +export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_NAME}"}" +export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_NAME}"}" export SCRIPT_DIR="${BASE_DIR}/scripts" -export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_TIME}-${IMG_NAME}"}" +export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}" export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"} export DEPLOY_ZIP="${DEPLOY_ZIP:-2}" export LOG_FILE="${WORK_DIR}/build.log" diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index aaa3e99..097fa67 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -3,6 +3,7 @@ IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img" INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info" +echo "Part 1" on_chroot << EOF if [ -x /etc/init.d/fake-hwclock ]; then /etc/init.d/fake-hwclock stop @@ -12,19 +13,23 @@ if hash hardlink 2>/dev/null; then fi EOF +echo "Part 2" if [ -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config" ]; then chmod 700 "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config" fi +echo "Part 3" rm -f "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache" rm -f "${ROOTFS_DIR}/usr/bin/qemu-arm-static" +echo "Part 4" if [ "${USE_QEMU}" != "1" ]; then if [ -e "${ROOTFS_DIR}/etc/ld.so.preload.disabled" ]; then mv "${ROOTFS_DIR}/etc/ld.so.preload.disabled" "${ROOTFS_DIR}/etc/ld.so.preload" fi fi +echo "Part 5" rm -f "${ROOTFS_DIR}/etc/network/interfaces.dpkg-old" rm -f "${ROOTFS_DIR}/etc/apt/sources.list~" @@ -53,12 +58,13 @@ find "${ROOTFS_DIR}/var/log/" -type f -exec cp /dev/null {} \; rm -f "${ROOTFS_DIR}/root/.vnc/private.key" rm -f "${ROOTFS_DIR}/etc/vnc/updateid" +echo "Part 6" update_issue "$(basename "${EXPORT_DIR}")" install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/issue.txt" cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" - +echo "Part 7" { if [ -f "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" ]; then firmware=$(zgrep "firmware as of" \ @@ -79,6 +85,7 @@ cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" ROOT_DEV="$(mount | grep "${ROOTFS_DIR} " | cut -f1 -d' ')" +echo "Part 8" unmount "${ROOTFS_DIR}" zerofree "${ROOT_DEV}" @@ -89,6 +96,7 @@ mkdir -p "${DEPLOY_DIR}" rm -f "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip" rm -f "${DEPLOY_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img" +echo "Part 9" if [ "${DEPLOY_ZIP}" == "1" ]; then pushd "${STAGE_WORK_DIR}" > /dev/null zip "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip" \ @@ -100,4 +108,5 @@ else cp "$IMG_FILE" "$DEPLOY_DIR" fi +echo "Part 10" cp "$INFO_FILE" "$DEPLOY_DIR" diff --git a/stage1/01-sys-tweaks/files/.browser.sh b/stage1/01-sys-tweaks/files/.browser.sh index e4ead29..1f866fc 100644 --- a/stage1/01-sys-tweaks/files/.browser.sh +++ b/stage1/01-sys-tweaks/files/.browser.sh @@ -1,8 +1,11 @@ #!/bin/bash +source /srv/octoprint/host +if [[ -f ~/.overrideurl.sh ]]; then source ./.overrideurl.sh; fi + # Wait until OctoPrint comes up -while ! curl localhost:5000 2>&1 >/dev/null; do +while ! curl "$HOST:$PORT" 2>&1 >/dev/null; do sleep 1 done -surf -d -F -g -K -n -p localhost:5000 +surf -d -F -g -K -n -p "$HOST:$PORT" diff --git a/stage1/01-sys-tweaks/files/.xprofile b/stage1/01-sys-tweaks/files/.xprofile index 6f148a0..c0a4f11 100644 --- a/stage1/01-sys-tweaks/files/.xprofile +++ b/stage1/01-sys-tweaks/files/.xprofile @@ -1,3 +1,2 @@ -xset s 0 -xset -dpms +[ -f ~/.xtimeout ] && . ~/.xtimeout exec openbox-session diff --git a/stage2/04-octoprint/01-run.sh b/stage2/04-octoprint/01-run.sh index 47df47a..0442859 100755 --- a/stage2/04-octoprint/01-run.sh +++ b/stage2/04-octoprint/01-run.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service +install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service on_chroot << EOF if ! pip list | grep -F octoprint; then diff --git a/stage2/04-octoprint/files/octoprint.service b/stage2/04-octoprint/files/octoprint.service index e60bf95..f4bfced 100644 --- a/stage2/04-octoprint/files/octoprint.service +++ b/stage2/04-octoprint/files/octoprint.service @@ -5,7 +5,7 @@ Description=OctoPrint Daemon Type=simple User=octoprint Group=octoprint -ExecStart=/srv/octoprint/venv/bin/octoprint serve +ExecStart=/usr/local/bin/start-octoprint [Install] WantedBy=multi-user.target diff --git a/stage2/05-utils/00-run.sh b/stage2/05-utils/00-run.sh index f682730..3781863 100755 --- a/stage2/05-utils/00-run.sh +++ b/stage2/05-utils/00-run.sh @@ -2,8 +2,9 @@ mkdir -p "${ROOTFS_DIR}/usr/local/bin/" install -m 755 files/octo-config "${ROOTFS_DIR}/usr/local/bin/octo-config" - -install -m 755 files/first-time.sh ${ROOTFS_DIR}/etc/profile.d/first-time.sh +install -m 755 files/first-time.sh "${ROOTFS_DIR}/etc/profile.d/first-time.sh" +install -m 755 files/octo-lib.sh "${ROOTFS_DIR}/usr/local/lib/octo-lib.sh" +install -m 755 files/start-octoprint "${ROOTFS_DIR}/usr/local/bin/start-octoprint" mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/ cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF' diff --git a/stage2/05-utils/files/first-time.sh b/stage2/05-utils/files/first-time.sh index ce87ccb..9f6501c 100755 --- a/stage2/05-utils/files/first-time.sh +++ b/stage2/05-utils/files/first-time.sh @@ -6,57 +6,7 @@ if [ "$EUID" -ne 0 ]; then exit 1 fi -change_password () { - local PASSWORD="$(dialog --title "Change Password" --nocancel --insecure --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" - if [[ $? != 0 ]]; then change_password; return 0; fi - if [[ "$PASSWORD" == "raspberry" ]]; then - dialog --title "Change Password" --nocancel --msgbox "That password sucks. Please use a different one :)" 10 50 - change_password - return 0 - fi - if [[ "$(dialog --nocancel --insecure --passwordbox "Confirm new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" == "$PASSWORD" ]]; then - if [[ $? != 0 ]]; then return 1; fi - echo -e "pi:$PASSWORD" | chpasswd - else - dialog --title "Change Password" --nocancel --msgbox "Passwords did not match!" 10 50 - change_password - return 0 - fi - local OCTOPASS="$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c20)" - echo -e "octoprint:$OCTOPASS" | chpasswd - local ROOTPASS="$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c20)" - echo -e "root:$ROOTPASS" | chpasswd - unset OCTOPASS - unset ROOTPASS - unset PASSWORD -} - -service_select () { - local SERVICE_MENU=$(dialog --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \ - "1" "OctoPrint" ON \ - "2" "GUI" ON \ - "3" "SSH" OFF 3>&1 1>&2 2>&3) - SERVICE_MENU=($SERVICE_MENU) - - for i in "${SERVICE_MENU[@]}"; do - case $i in - "1") systemctl enable octoprint ;; - "2") systemctl set-default graphical.target ;; - "3") - ssh-keygen -A - systemctl enable ssh ;; - esac - done -} - -screen_timeout() { - local TIMEOUT=$(dialog --nocancel --title "Screen Timeout" --inputbox "Input your desired screen timeout in seconds.\nEnter \"off\" to disable the screen timeout.\n\nAdding a screen timeout can reduce screen burn in." 11 60 "off" 3>&1 1>&2 2>&3) - cat > /home/pi/.xprofile << EOF - xset s ${TIMEOUT} - xset -dpms - exec openbox-session -EOF -} +source /usr/local/lib/octo-lib.sh install_package () { echo "==========Installing $1==========" >>/home/pi/install.log @@ -115,15 +65,24 @@ suggested_menu () { dialog --title "NOTICE" --nocancel --colors --msgbox "This collection of software is currently in alpha. It is lacking several critical features. \Zb\Z1DO NOT\Zn use this in a production environment. This image has been provided for testing purposes only." 10 50 change_password || return 1 + dialog --title "Network Configuration" --nocancel --msgbox "Setup will now open nmtui, a program to help configure your ethernet/wireless interfaces. Hit Quit when you are done." 10 50 nmtui + service_select || return 1 + screen_timeout || return 1 + +if dialog --title "OctoPrint Config" --yesno "Do you wish to change the default OctoPrint listening address and/or port?" 10 60; then + octo_config +fi + if dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then recommended_menu || return 1 suggested_menu || return 1 chown -R octoprint:octoprint /srv/octoprint fi + rm /etc/systemd/system/getty@tty1.service.d/override.conf rm /etc/profile.d/first-time.sh reboot diff --git a/stage2/05-utils/files/octo-config b/stage2/05-utils/files/octo-config index 8c3d80d..05592fe 100755 --- a/stage2/05-utils/files/octo-config +++ b/stage2/05-utils/files/octo-config @@ -5,94 +5,7 @@ if [ "$EUID" -ne 0 ]; then exit 1 fi - -change_password () { - local PASSWORD="$(dialog --title "Change Password" --nocancel --insecure --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" - if [[ $? -ne 0 ]] || [[ $PASSWORD == "" ]]; then return 1; fi - if [[ "$PASSWORD" == "raspberry" ]]; then - dialog --title "Change Password" --nocancel --msgbox "That password sucks. Please use a different one :)" 10 50 - change_password - return 0 - fi - if [[ "$(dialog --nocancel --insecure --passwordbox "Confirm new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" == "$PASSWORD" ]]; then - if [[ $? != 0 ]]; then return 1; fi - echo -e "pi:$PASSWORD" | chpasswd - else - dialog --title "Change Password" --nocancel --msgbox "Passwords did not match!" 10 50 - change_password - return 0 - fi - unset PASSWORD -} - -service_select () { - local SERVICE_MENU=$(dialog --separate-output --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \ - "1" "OctoPrint" $(if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "ON"; else echo "OFF"; fi) \ - "2" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; then echo "ON"; else echo "OFF"; fi) \ - "3" "SSH" $(if [[ -f /etc/systemd/system/multi-user.target.wants/ssh.service ]]; then echo "ON"; else echo "OFF"; fi) 3>&1 1>&2 2>&3) - - SERVICE_MENU=($SERVICE_MENU) #Exploderizes it into an array - - local ENABLE_OCTO=false - local ENABLE_GUI=false - local ENABLE_SSH=false - - for i in "${SERVICE_MENU[@]}"; do - case $i in - "1") ENABLE_OCTO=true ;; - "2") ENABLE_GUI=true ;; - "3") ENABLE_SSH=true ;; - esac - done - - if [[ $ENABLE_OCTO == true ]]; then - systemctl enable octoprint - else - systemctl disable octoprint - fi - - if [[ $ENABLE_GUI == true ]]; then - systemctl set-default graphical.target - else - systemctl set-default multi-user.target - fi - - if [[ $ENABLE_SSH == true ]]; then - systemctl enable ssh - else - systemctl disable ssh - fi - - -<< 'EOF' - for ((i = 0; i <= 3; i++)); do - for n in "${SERVICE_MENU[@]}"; do - if [[ $i == $n ]]; then - case $i in - "1") systemctl enable octoprint ;; - "2") systemctl set-default graphical.target ;; - "3") systemctl enable ssh ;; - esac - break - fi - done - case $i in - "1") systemctl disable octoprint ;; - "2") systemctl set-default graphical.target ;; - "3") systemctl disable ssh ;; - esac - done -EOF -} - -screen_timeout() { - local TIMEOUT=$(dialog --nocancel --title "Screen Timeout" --inputbox "Input your desired screen timeout in seconds.\nEnter \"off\" to disable the screen timeout.\n\nAdding a screen timeout can reduce screen burn in." 11 60 "0" 3>&1 1>&2 2>&3) - cat > /home/pi/.xprofile << EOF - xset s ${TIMEOUT} - xset -dpms - exec openbox-session -EOF -} +source /usr/local/lib/octo-lib.sh main_menu () { local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \ @@ -100,14 +13,16 @@ main_menu () { "2" "Change password for pi" \ "3" "Configure services" \ "4" "Configure screen timeout" \ - "5" "Exit" 3>&1 1>&2 2>&3) + "5" "Configure OctoPrint" \ + "6" "Exit" 3>&1 1>&2 2>&3) case $MAINMENU in "1") nmtui; main_menu; return 0;; "2") change_password; main_menu; return 0;; "3") service_select; main_menu; return 0;; "4") screen_timeout; main_menu; return 0;; - "5") return 0;; + "5") octo_config; main_menu; return 0;; + "6") return 0;; esac } diff --git a/stage2/05-utils/files/octo-lib.sh b/stage2/05-utils/files/octo-lib.sh new file mode 100644 index 0000000..f00ceb8 --- /dev/null +++ b/stage2/05-utils/files/octo-lib.sh @@ -0,0 +1,107 @@ +change_password () { + local PASSWORD="$(dialog --title "Change Password" --nocancel --insecure --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" + if [[ $? -ne 0 ]] || [[ $PASSWORD == "" ]]; then return 1; fi + if [[ "$PASSWORD" == "raspberry" ]]; then + dialog --title "Change Password" --nocancel --msgbox "That password sucks. Please use a different one :)" 10 50 + change_password + return 0 + fi + if [[ "$(dialog --nocancel --insecure --passwordbox "Confirm new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)" == "$PASSWORD" ]]; then + if [[ $? != 0 ]]; then return 1; fi + echo -e "pi:$PASSWORD" | chpasswd + else + dialog --title "Change Password" --nocancel --msgbox "Passwords did not match!" 10 50 + change_password + return 0 + fi + unset PASSWORD +} + +service_select () { + local SERVICE_MENU=$(dialog --separate-output --nocancel --title "Select services" --checklist "Enable/disable services" 0 0 0 \ + "1" "OctoPrint" $(if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "ON"; else echo "OFF"; fi) \ + "2" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; then echo "ON"; else echo "OFF"; fi) \ + "3" "SSH" $(if [[ -f /etc/systemd/system/multi-user.target.wants/ssh.service ]]; then echo "ON"; else echo "OFF"; fi) 3>&1 1>&2 2>&3) + + SERVICE_MENU=($SERVICE_MENU) + + local ENABLE_OCTO=false + local ENABLE_GUI=false + local ENABLE_SSH=false + + for i in "${SERVICE_MENU[@]}"; do + case $i in + "1") ENABLE_OCTO=true ;; + "2") ENABLE_GUI=true ;; + "3") ENABLE_SSH=true ;; + esac + done + + if [[ $ENABLE_OCTO == true ]]; then + systemctl enable octoprint + else + systemctl disable octoprint + fi + + if [[ $ENABLE_GUI == true ]]; then + systemctl set-default graphical.target + else + systemctl set-default multi-user.target + fi + + if [[ $ENABLE_SSH == true ]]; then + systemctl enable ssh + else + systemctl disable ssh + fi + + +<< 'EOF' + for ((i = 0; i <= 3; i++)); do + for n in "${SERVICE_MENU[@]}"; do + if [[ $i == $n ]]; then + case $i in + "1") systemctl enable octoprint ;; + "2") systemctl set-default graphical.target ;; + "3") systemctl enable ssh ;; + esac + break + fi + done + case $i in + "1") systemctl disable octoprint ;; + "2") systemctl set-default graphical.target ;; + "3") systemctl disable ssh ;; + esac + done +EOF +} + +screen_timeout() { + local TIMEOUT=$(dialog --nocancel --title "Screen Timeout" --inputbox "Input your desired screen timeout in seconds.\nEnter \"off\" to disable the screen timeout.\n\nAdding a screen timeout can reduce screen burn in." 11 60 "0" 3>&1 1>&2 2>&3) + cat > /home/pi/.xtimeout << EOF + xset s ${TIMEOUT} + xset -dpms +EOF +} + +octo_config () { + if [[ -f /srv/octoprint/host ]]; then + source /srv/octoprint/host + else + HOST="0.0.0.0" + PORT="5000" + fi + + local OCTOFORM=$(dialog --title "OctoPrint Config" --nocancel --form "Configure what port and IP OctoPrint listen on." 10 50 0 \ + "Listening IP:" 1 1 "$HOST" 1 17 20 0 \ + "Listening Port:" 2 1 "$PORT" 2 17 6 0 3>&1 1>&2 2>&3) + OCTOFORM=($OCTOFORM) + + HOST=${OCTOFORM[0]} + PORT=${OCTOFORM[1]} + + echo -e "HOST=$HOST\nPORT=$PORT" > /srv/octoprint/host +} + + diff --git a/stage2/05-utils/files/start-octoprint b/stage2/05-utils/files/start-octoprint new file mode 100644 index 0000000..d0d3b43 --- /dev/null +++ b/stage2/05-utils/files/start-octoprint @@ -0,0 +1,10 @@ +#!/bin/bash + +source /srv/octoprint/venv/bin/activate + +source /srv/octoprint/host + +[[ "$HOST" == "" ]] && HOST="0.0.0.0" +[[ "$PORT" == "" ]] && PORT="5000" + +/srv/octoprint/venv/bin/octoprint serve --host $HOST --port $PORT