Compare commits

...

No commits in common. "v0.2" and "master" have entirely different histories.
v0.2 ... master

63 changed files with 945 additions and 369 deletions

View file

@ -1,4 +1,5 @@
FROM debian:buster
ARG BASE_IMAGE=debian:buster
FROM ${BASE_IMAGE}
ENV DEBIAN_FRONTEND noninteractive
@ -6,8 +7,8 @@ RUN apt-get -y update && \
apt-get -y install --no-install-recommends \
git vim parted \
quilt coreutils qemu-user-static debootstrap zerofree zip dosfstools \
bsdtar libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc\
binfmt-support ca-certificates \
bsdtar libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc \
binfmt-support ca-certificates golang \
&& rm -rf /var/lib/apt/lists/*
COPY . /pi-gen/

View file

@ -1,5 +1,5 @@
Copyright (c) 2015 Raspberry Pi (Trading) Ltd.
Copyright (c) 2020 Logan Gartner
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

View file

@ -1,16 +1,16 @@
# pi-gen
_Tool used to create the raspberrypi.org Raspbian images_
Tool used to create Raspberry Pi OS images. (Previously known as Raspbian).
## Dependencies
pi-gen runs on Debian based operating systems. Currently it is only supported on
pi-gen runs on Debian-based operating systems. Currently it is only supported on
either Debian Buster or Ubuntu Xenial and is known to have issues building on
earlier releases of these systems. On other Linux distributions it may be possible
to use the Docker build described below.
To install the required dependencies for pi-gen you should run:
To install the required dependencies for `pi-gen` you should run:
```bash
apt-get install coreutils quilt parted qemu-user-static debootstrap zerofree zip \
@ -68,7 +68,7 @@ The following environment variables are supported:
system for each build stage, amounting to tens of gigabytes in the case of
Raspbian.
**CAUTION**: If your working directory is on an NTFS partition you probably won't be able to build. Make sure this is a proper Linux filesystem.
**CAUTION**: If your working directory is on an NTFS partition you probably won't be able to build: make sure this is a proper Linux filesystem.
* `DEPLOY_DIR` (Default: `"$BASE_DIR/deploy"`)
@ -124,12 +124,24 @@ The following environment variables are supported:
* `WPA_ESSID`, `WPA_PASSWORD` and `WPA_COUNTRY` (Default: unset)
If these are set, they are use to configure `wpa_supplicant.conf`, so that the Raspberry Pi can automatically connect to a wifi network on first boot. If `WPA_ESSID` is set and `WPA_PASSWORD` is unset an unprotected wifi network will be configured. If set, `WPA_PASSWORD` must be between 8 and 63 characters.
If these are set, they are use to configure `wpa_supplicant.conf`, so that the Raspberry Pi can automatically connect to a wireless network on first boot. If `WPA_ESSID` is set and `WPA_PASSWORD` is unset an unprotected wireless network will be configured. If set, `WPA_PASSWORD` must be between 8 and 63 characters.
* `ENABLE_SSH` (Default: `0`)
Setting to `1` will enable ssh server for remote log in. Note that if you are using a common password such as the defaults there is a high risk of attackers taking over you Raspberry Pi.
* `PUBKEY_SSH_FIRST_USER` (Default: unset)
Setting this to a value will make that value the contents of the FIRST_USER_NAME's ~/.ssh/authorized_keys. Obviously the value should
therefore be a valid authorized_keys file. Note that this does not
automatically enable SSH.
* `PUBKEY_ONLY_SSH` (Default: `0`)
* Setting to `1` will disable password authentication for SSH and enable
public key authentication. Note that if SSH is not enabled this will take
effect when SSH becomes enabled.
* `STAGE_LIST` (Default: `stage*`)
If set, then instead of working through the numeric stages in order, this list will be followed. For example setting to `"stage0 stage1 mystage stage2"` will run the contents of `mystage` before stage2. Note that quotes are needed around the list. An absolute or relative path can be given for stages outside the pi-gen directory.
@ -264,7 +276,7 @@ maintenance and allows for more easy customization.
- **Stage 2** - lite system. This stage produces the Raspbian-Lite image. It
installs some optimized memory functions, sets timezone and charmap
defaults, installs fake-hwclock and ntp, wifi and bluetooth support,
defaults, installs fake-hwclock and ntp, wireless LAN and bluetooth support,
dphys-swapfile, and other basics for managing the hardware. It also
creates necessary groups and gives the pi user access to sudo and the
standard console hardware permission groups.

View file

@ -1,24 +1,76 @@
# Raspberry Pi OctoPrint Kiosk
This repository contains the source for building an OctoPrint kiosk.
# TouchPrint
TouchPrint is a lightweight fork of Raspberry Pi OS whos purpose is to securely host OctoPrint and to (optionally) display it on a connected screen.
TouchPrint is very customizable. Both the GUI and/or OctoPrint can be disabled if you already have an existing setup to perform these tasks.
## Highlights
- Lightweight graphical frontend using Surf to display OctoPrint
- Easy to use TUI installer
- Built for security
# Table of Contents
- [Screenshots](#screenshots)
- [Requirements](#requirements)
- [Quick Setup Guide](#quick-setup-guide)
- [Flashing on Windows/Mac OS/Linux \(Easy\)](#flashing-on-windowsmac-oslinux-easy)
- [Flashing on Mac OS/Linux/BSD \(Recommended\)](#flashing-in-mac-oslinuxbsd-recommended)
- [First Boot](#first-boot)
- [OctoPrint Setup](#octoprint-setup)
- [Accessing OctoPrint](#accessing-octoprint)
- [Configuring TouchPrint](#configuring-touchprint)
- [Reporting Bugs](#reporting-bugs)
## Screenshots
# Screenshots
TODO
## Installation
[Download the latest image from the releases section](/releases) and flash it onto a microSD card with at least 4GB of storage.
## Requirements
# Requirements
### Minimum:
- Raspberry Pi 3
- 4GB microSD card
- Keyboard for first time setup
- 8GB microSD card
- Keyboard and video for first time setup
### Recommended:
- Raspberry Pi 4
- 8GB Class 10 microSD card
- Keyboard for first time setup
- Keyboard and video for first time setup
# Quick Setup Guide
### Flashing on Windows/Mac OS/Linux (Easy)
1. Download and install [balenaEtcher](https://www.balena.io/etcher/).
2. Download the [latest image from the releases section](/releases).
3. Follow the on screen instructions in Etcher to burn the image to your microSD or [USB drive](https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md).
### Flashing in Mac OS/Linux/BSD (Recommended)
1. Download the [latest image from the releases section](/releases).
2. Open a terminal and navigate to where you downloaded the image file.
3. Ensure that xz is installed on your computer.
| **OS** | **Command** |
|---------------|------------------------|
| Ubuntu/Debian | `apt install xz-utils` |
| Arch/Manjaro | `pacman -S xz` |
| Mac OS | `brew install xz` |
| FreeBSD | `pkg install xz-utils` |
4. Run `xz -d -c IMAGE_NAME.img.xz | sudo dd of=/dev/sdX`, replacing IMAGE\_NAME and /dev/sdX with the appropriate paths, and adding flags per your preferences.
### First Boot
1. Connect an HDMI cable and a keyboard to your Raspberry Pi.
2. Power on your Raspberry Pi and wait for it to boot.
3. Once booted, you will be put into the first time setup, where you can configure networking, choose which services you want to run, etc.
- Use the arrow keys to move the "cursor", Spacebar to toggle checkboxes, Tab to move the cursor between different sections, and Enter to continue.
4. Once the first time setup is complete, the Raspberry Pi will reboot.
### OctoPrint Setup
- If the GUI is enabled, you can setup OctoPrint on the Raspberry Pi. You can also setup OctoPrint by opening up a web browser on another computer and navigating to `https://RPI-IP`, replacing RPI-IP with the IP address of your Raspberry Pi.
- If MJPG-Streamer is enabled, you can put `/webcam` into the Stream URL box to enable it in OctoPrint.
- If you wish to enable timelapses, the path to ffmpeg is `/usr/bin/ffmpeg`.
### Accessing OctoPrint
- If OctoPrint is enabled, you can access it at `https://RPI-IP`, replacing RPI-IP with the IP address of your Raspberry Pi.
### Configuring TouchPrint
- TouchPrint can be configured either over SSH or in a TTY using the `tp-config` script. This script is provided to make management of core features easier and to consolidate TouchPrint's settings into one place.
- OctoPrint can be configured through the OctoPrint UI as normal.
# Reporting Bugs
Please report any bugs by [filing an issue](/issues). Please include as much detail as you can, including (but not limited to):
- Raspberry Pi Model
- Version of TouchPrint
- What you were doing when the bug/issue occured
- Steps to reproduce
- Logs

15
TODO.md
View file

@ -1,16 +1,21 @@
# TODO:
## First time/Octo-Config
## First time/TP-Config
- Add network configuration (replace nmtui)
- Add hostname configuration (replace nmtui)
- Timezone selection
- Add timezone configuration (replace tzdata)
- Import/export settings
- Enable/Disable HTTP redirect from port 80
## Nginx
- Update deprecated "ssl" option to "listen PORT ssl;"
## Misc
- Cleanup
- More security
- Wiki
## Things to consider
- Wayland using labwc/waybox
- Python 3
- Detect if frontend did not load correctly (probably not easy)
- HTTP/Port 80 redirect
- Onboard

View file

@ -1,4 +1,5 @@
#!/bin/bash -eu
#!/usr/bin/env bash
set -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
BUILD_OPTS="$*"
@ -73,7 +74,17 @@ fi
# Modify original build-options to allow config file to be mounted in the docker container
BUILD_OPTS="$(echo "${BUILD_OPTS:-}" | sed -E 's@\-c\s?([^ ]+)@-c /config@')"
${DOCKER} build -t pi-gen "${DIR}"
# Check the arch of the machine we're running on. If it's 64-bit, use a 32-bit base image instead
case "$(uname -m)" in
x86_64|aarch64)
BASE_IMAGE=i386/debian:buster
;;
*)
BASE_IMAGE=debian:buster
;;
esac
${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}"
if [ "${CONTAINER_EXISTS}" != "" ]; then
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
time ${DOCKER} run --rm --privileged \

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
# shellcheck disable=SC2119
run_sub_stage()
{
@ -162,7 +163,7 @@ export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
export DEPLOY_ZIP="${DEPLOY_ZIP:-2}"
export LOG_FILE="${WORK_DIR}/build.log"
export TARGET_HOSTNAME=${TARGET_HOSTNAME:-octoprintkiosk}
export TARGET_HOSTNAME=${TARGET_HOSTNAME:-touchprint}
export FIRST_USER_NAME=${FIRST_USER_NAME:-pi}
export FIRST_USER_PASS=${FIRST_USER_PASS:-raspberry}
@ -171,16 +172,19 @@ export WPA_ESSID
export WPA_PASSWORD
export WPA_COUNTRY
export ENABLE_SSH="${ENABLE_SSH:-0}"
export PUBKEY_ONLY_SSH="${PUBKEY_ONLY_SSH:-0}"
export LOCALE_DEFAULT="${LOCALE_DEFAULT:-en_US.UTF-8}"
export KEYBOARD_KEYMAP="${KEYBOARD_KEYMAP:-us}"
export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (US)}"
export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-America/New_York}"
export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-UTC}"
export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"}
export PUBKEY_SSH_FIRST_USER
export CLEAN
export IMG_NAME
export APT_PROXY
@ -226,6 +230,11 @@ if [[ -n "${WPA_PASSWORD}" && ${#WPA_PASSWORD} -lt 8 || ${#WPA_PASSWORD} -gt 63
exit 1
fi
if [[ "${PUBKEY_ONLY_SSH}" = "1" && -z "${PUBKEY_SSH_FIRST_USER}" ]]; then
echo "Must set 'PUBKEY_SSH_FIRST_USER' to a valid SSH public key if using PUBKEY_ONLY_SSH"
exit 1
fi
mkdir -p "${WORK_DIR}"
log "Begin ${BASE_DIR}"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
if [ ! -x "${ROOTFS_DIR}/usr/bin/qemu-arm-static" ]; then
cp /usr/bin/qemu-arm-static "${ROOTFS_DIR}/usr/bin/"

View file

@ -1,5 +1,8 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
rm -f "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache"
find "${ROOTFS_DIR}/var/lib/apt/lists/" -type f -delete
on_chroot << EOF
apt-get update
apt-get -y dist-upgrade

View file

@ -1,3 +1,4 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -m 644 files/resolv.conf "${ROOTFS_DIR}/etc/"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info"
@ -18,8 +19,6 @@ 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"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
@ -39,8 +40,32 @@ BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)
BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}")
ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}")
echo "Mounting BOOT_DEV..."
cnt=0
until BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}"); do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
echo "Error in losetup for BOOT_DEV. Retrying..."
sleep 5
else
echo "ERROR: losetup for BOOT_DEV failed; exiting"
exit 1
fi
done
echo "Mounting ROOT_DEV..."
cnt=0
until ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}"); do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
echo "Error in losetup for ROOT_DEV. Retrying..."
sleep 5
else
echo "ERROR: losetup for ROOT_DEV failed; exiting"
exit 1
fi
done
echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}"
@ -37,6 +38,7 @@ sed "${NOOBS_DIR}/os.json" -i -e "s|UNRELEASED|${IMG_DATE}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|NOOBS_NAME|${NOOBS_NAME}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|NOOBS_DESCRIPTION|${NOOBS_DESCRIPTION}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|RELEASE|${RELEASE}|"
sed "${NOOBS_DIR}/os.json" -i -e "s|KERNEL|$(cat "${STAGE_WORK_DIR}/kernel_version")|"
sed "${NOOBS_DIR}/release_notes.txt" -i -e "s|UNRELEASED|${IMG_DATE}|"

View file

@ -1,7 +1,7 @@
{
"description": "NOOBS_DESCRIPTION",
"feature_level": 35120124,
"kernel": "4.19",
"kernel": "KERNEL",
"name": "NOOBS_NAME",
"password": "raspberry",
"release_date": "UNRELEASED",

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
NOOBS_DIR="${STAGE_WORK_DIR}/${IMG_DATE}-${IMG_NAME}${IMG_SUFFIX}"
@ -16,8 +17,32 @@ BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)
BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}")
ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}")
echo "Mounting BOOT_DEV..."
cnt=0
until BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}"); do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
echo "Error in losetup for BOOT_DEV. Retrying..."
sleep 5
else
echo "ERROR: losetup for BOOT_DEV failed; exiting"
exit 1
fi
done
echo "Mounting ROOT_DEV..."
cnt=0
until ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}"); do
if [ $cnt -lt 5 ]; then
cnt=$((cnt + 1))
echo "Error in losetup for ROOT_DEV. Retrying..."
sleep 5
else
echo "ERROR: losetup for ROOT_DEV failed; exiting"
exit 1
fi
done
echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"
@ -29,6 +54,9 @@ mount "$BOOT_DEV" "${STAGE_WORK_DIR}/rootfs/boot"
ln -sv "/lib/systemd/system/apply_noobs_os_config.service" "$ROOTFS_DIR/etc/systemd/system/multi-user.target.wants/apply_noobs_os_config.service"
KERNEL_VER="$(zgrep -oPm 1 "Linux version \K(.*)$" "${STAGE_WORK_DIR}/rootfs/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" | cut -f-2 -d.)"
echo "$KERNEL_VER" > "${STAGE_WORK_DIR}/kernel_version"
bsdtar --numeric-owner --format gnutar -C "${STAGE_WORK_DIR}/rootfs/boot" -cpf - . | xz -T0 > "${NOOBS_DIR}/boot.tar.xz"
umount "${STAGE_WORK_DIR}/rootfs/boot"
bsdtar --numeric-owner --format gnutar -C "${STAGE_WORK_DIR}/rootfs" --one-file-system -cpf - . | xz -T0 > "${NOOBS_DIR}/root.tar.xz"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -m 644 files/sources.list "${ROOTFS_DIR}/etc/apt/"
install -m 644 files/raspi.list "${ROOTFS_DIR}/etc/apt/sources.list.d/"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
if [ ! -d "${ROOTFS_DIR}" ]; then
bootstrap ${RELEASE} "${ROOTFS_DIR}" http://deb.debian.org/debian/

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -m 644 files/cmdline.txt "${ROOTFS_DIR}/boot/"
install -m 644 files/config.txt "${ROOTFS_DIR}/boot/"

View file

@ -66,3 +66,4 @@ max_framebuffers=2
[all]
#dtoverlay=vc4-fkms-v3d
arm_64bit=1
start_x=1

View file

@ -1,14 +1,11 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -d "${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d"
install -m 644 files/noclear.conf "${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/noclear.conf"
install -v -m 644 files/fstab "${ROOTFS_DIR}/etc/fstab"
install -m 755 files/.xprofile "${ROOTFS_DIR}/etc/skel/.xprofile"
install -m 755 files/.browser.sh "${ROOTFS_DIR}/etc/skel/.browser.sh"
install -m 644 files/.dialogrc "${ROOTFS_DIR}/etc/skel/.dialogrc"
install -m 644 files/.dialogrc "${ROOTFS_DIR}/root/.dialogrc"
mkdir -p "${ROOTFS_DIR}/etc/skel/.config/openbox"
install -m 644 files/autostart "${ROOTFS_DIR}/etc/skel/.config/openbox/autostart"
on_chroot << EOF
if ! id -u ${FIRST_USER_NAME} >/dev/null 2>&1; then
@ -17,7 +14,8 @@ fi
if ! id -u octoprint >/dev/null 2>&1; then
adduser --system --shell /usr/sbin/nologin --group --disabled-password --gecos "" octoprint
fi
if ! id -u kiosk >/dev/null 2>&1; then
adduser --disabled-password --shell /usr/sbin/nologin --gecos "" kiosk
fi
echo "${FIRST_USER_NAME}:${FIRST_USER_PASS}" | chpasswd
echo "octoprint:$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c40)" | chpasswd
echo "root:$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c40)" | chpasswd
EOF

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
echo "${TARGET_HOSTNAME}" > "${ROOTFS_DIR}/etc/hostname"
echo "127.0.1.1 ${TARGET_HOSTNAME}" >> "${ROOTFS_DIR}/etc/hosts"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
if [ ! -d "${ROOTFS_DIR}" ]; then
copy_previous

View file

@ -14,11 +14,9 @@ parted
unzip
build-essential
manpages-dev
python
bash-completion
gdb
pkg-config
python-rpi.gpio
v4l-utils
avahi-daemon
hardlink

View file

@ -2,4 +2,4 @@
+++ stage2/rootfs/boot/cmdline.txt
@@ -1 +1 @@
-console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
+console=serial0,115200 console=tty1 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh
+console=serial0,115200 console=tty12 root=ROOTDEV rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet loglevel=3 init=/usr/lib/raspi-config/init_resize.sh

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/"
@ -11,6 +12,18 @@ install -m 644 files/console-setup "${ROOTFS_DIR}/etc/default/"
install -m 755 files/rc.local "${ROOTFS_DIR}/etc/"
if [ -n "${PUBKEY_SSH_FIRST_USER}" ]; then
install -v -m 0700 -o 1000 -g 1000 -d "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh
echo "${PUBKEY_SSH_FIRST_USER}" >"${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys
chown 1000:1000 "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys
chmod 0600 "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys
fi
if [ "${PUBKEY_ONLY_SSH}" = "1" ]; then
sed -i -Ee 's/^#?[[:blank:]]*PubkeyAuthentication[[:blank:]]*no[[:blank:]]*$/PubkeyAuthentication yes/
s/^#?[[:blank:]]*PasswordAuthentication[[:blank:]]*yes[[:blank:]]*$/PasswordAuthentication no/' "${ROOTFS_DIR}"/etc/ssh/sshd_config
fi
on_chroot << EOF
systemctl disable hwclock.sh
systemctl disable nfs-common
@ -46,6 +59,9 @@ done
for GRP in dialout plugdev video users; do
adduser octoprint \$GRP
done
for GRP in users; do
adduser kiosk \$GRP
done
EOF
on_chroot << EOF

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
#install -v -d "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d"
#install -v -m 644 files/wait.conf "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/"
@ -25,7 +26,12 @@ network={
EOL
fi
# Disable wifi on 5GHz models
# Disable wifi on 5GHz models if WPA_COUNTRY is not set
mkdir -p "${ROOTFS_DIR}/var/lib/systemd/rfkill/"
echo 1 > "${ROOTFS_DIR}/var/lib/systemd/rfkill/platform-3f300000.mmcnr:wlan"
echo 1 > "${ROOTFS_DIR}/var/lib/systemd/rfkill/platform-fe300000.mmcnr:wlan"
if [ -n "$WPA_COUNTRY" ]; then
echo 0 > "${ROOTFS_DIR}/var/lib/systemd/rfkill/platform-3f300000.mmcnr:wlan"
echo 0 > "${ROOTFS_DIR}/var/lib/systemd/rfkill/platform-fe300000.mmcnr:wlan"
else
echo 1 > "${ROOTFS_DIR}/var/lib/systemd/rfkill/platform-3f300000.mmcnr:wlan"
echo 1 > "${ROOTFS_DIR}/var/lib/systemd/rfkill/platform-fe300000.mmcnr:wlan"
fi

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
echo "${TIMEZONE_DEFAULT}" > "${ROOTFS_DIR}/etc/timezone"
rm "${ROOTFS_DIR}/etc/localtime"

View file

@ -1,7 +1,7 @@
python-pip
python-dev
python-setuptools
python-virtualenv
python3-pip
python3-dev
python3-setuptools
python3-venv
git
libyaml-dev
nginx

View file

@ -1,23 +1,34 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service
mkdir -p ${ROOTFS_DIR}/home/octoprint/.octoprint/
install -m 600 files/config.yaml ${ROOTFS_DIR}/home/octoprint/.octoprint/config.yaml
install -m 644 files/nginx.conf ${ROOTFS_DIR}/etc/nginx/nginx.conf
echo -e "listen 443;" > ${ROOTFS_DIR}/etc/nginx/listen.conf
touch ${ROOTFS_DIR}/etc/nginx/auth.conf
mkdir -p ${ROOTFS_DIR}/usr/local/bin
install -m 755 files/restart-octoprint ${ROOTFS_DIR}/usr/local/bin/restart-octoprint
# Yeah I could've used polkit, but this works fine so whatever
mkdir -p ${ROOTFS_DIR}/etc/sudoers.d
echo "octoprint ALL=NOPASSWD: /sbin/shutdown" > ${ROOTFS_DIR}/etc/sudoers.d/octoprint-shutdown
echo "octoprint ALL=NOPASSWD: /usr/local/bin/restart-octoprint" > ${ROOTFS_DIR}/etc/sudoers.d/octoprint-restart
on_chroot << EOF
# Package enables this when installed, won't start until first-time is run due to missing SSL certs
systemctl disable nginx
# If OctoPrint already exists, skip this (for debugging)
if [[ ! -f /srv/octoprint/bin/octoprint ]]; then
cd /srv/ || exit 1
virtualenv octoprint || exit 1
source octoprint/bin/activate || exit 1
python3 -m venv /srv/octoprint || exit 1
source /srv/octoprint/bin/activate || exit 1
pip install pip --upgrade
pip install octoprint || exit 1
# Fix permissions
chown -R octoprint:octoprint /srv/octoprint
chown -R octoprint:octoprint /home/octoprint
fi
# Enable the reverse proxy
systemctl enable nginx
EOF

View file

@ -0,0 +1,14 @@
accessControl:
autologinLocal: true
localNetworks:
- 127.0.0.0/8
webcam:
stream: /webcam/
ffmpeg: /usr/bin/ffmpeg
discovery:
publicPort: 443
server:
commands:
systemShutdownCommand: sudo shutdown now
systemRestartCommand: sudo shutdown -r now
serverRestartCommand: sudo restart-octoprint

View file

@ -1,4 +1,5 @@
worker_processes auto;
user www-data;
events {
worker_connections 1024;
@ -20,7 +21,7 @@
}
upstream "mjpg-streamer" {
server 127.0.0.1:8080;
server 127.0.0.1:9000;
}
server {
@ -29,6 +30,7 @@
ssl_certificate /etc/ssl/certs/nginx-octoprint.crt;
ssl_certificate_key /etc/ssl/private/nginx-octoprint.key;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
error_page 497 https://$host$request_uri;
server_name localhost;
location / {
@ -45,6 +47,7 @@
}
location /webcam/ {
include /etc/nginx/auth.conf;
proxy_pass http://mjpg-streamer/;
}

View file

@ -6,7 +6,7 @@ Wants=nginx.service
Type=simple
User=octoprint
Group=octoprint
ExecStart=/srv/octoprint/bin/octoprint --host localhost --port 5000
ExecStart=/srv/octoprint/bin/octoprint serve --host localhost --port 5000
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
if [ "$EUID" -ne 0 ]; then
echo "This script needs to be run as root."
exit 1
fi
systemctl restart octoprint

View file

@ -1,6 +1,2 @@
cmake
libjpeg-dev
v4l-utils
libv4l-dev
gcc
g++

View file

@ -1,25 +1,14 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
install -m 644 files/mjpg-streamer.service ${ROOTFS_DIR}/etc/systemd/system/mjpg-streamer.service
install -m 755 files/start-mjpg ${ROOTFS_DIR}/usr/local/bin/start-mjpg
mkdir -p ${ROOTFS_DIR}/usr/local/etc/mjpg-server/
install -m 755 files/config.sh ${ROOTFS_DIR}/usr/local/etc/mjpg-server/
on_chroot << EOF
# If mjpg is already installed, skip this (for debugging)
if ! which mjpg_streamer; then
cd /tmp
# Making sure that this directory doesn't exist
rm -rf /tmp/mjpg-streamer
git clone https://github.com/jacksonliam/mjpg-streamer/
cd mjpg-streamer/mjpg-streamer-experimental/
make
make install
cd /
# Cleanup
rm -rf /tmp/mjpg-streamer
# Create needed folder
mkdir -p /var/www/mjpg
# Permissions
chown octoprint:octoprint /var/www/mjpg
if [[ ! -f ${ROOTFS_DIR}/usr/local/bin/mjpeg-server ]]; then
# Do some semi janky cross compilation since Golang won't let me set GOBIN when cross compiling (gogl plz fix)
GOPATH=/tmp/go GOARCH=arm64 go get github.com/blueimp/mjpeg-server
cp /tmp/go/bin/linux_arm64/mjpeg-server ${ROOTFS_DIR}/usr/local/bin/mjpeg-server
rm -rf /tmp/go
fi
EOF

View file

@ -0,0 +1,3 @@
VIDEO_DEVICE="/dev/video0"
VIDEO_SIZE="1280x720"
FRAMERATE=15

View file

@ -1,2 +1,15 @@
#!/bin/bash
/usr/local/bin/mjpg_streamer -i input_uvc.so -o "output_http.so --port 8080 -w /var/www/mjpg"
#!/usr/bin/env bash
# Include environment variables
source /usr/local/etc/mjpg-server/config.sh
# Test if camera can just give us MJPG frames so that we can save a bunch of CPU
if ffmpeg -input_format mjpeg -video_size $VIDEO_SIZE -framerate $FRAMERATE -nostats -v quiet -i $VIDEO_DEVICE vframes 1 -f null - >/dev/null; then
/usr/local/bin/mjpeg-server -a 127.0.0.1:9000 -- ffmpeg -input_format mjpeg -video_size $VIDEO_SIZE -framerate $FRAMERATE -i $VIDEO_DEVICE -f mpjpeg -c:v copy -
# Oh, it can't :( Guess I'll just blast the CPU to maybe get 5FPS
elif ffmpeg -video_size $VIDEO_SIZE -framerate $FRAMERATE -nostats -v quiet -i $VIDEO_DEVICE -vframes 1 -f null - >/dev/null; then
/usr/local/bin/mjpeg-server -a 127.0.0.1:9000 -- ffmpeg -input_format rawvideo -video_size $VIDEO_SIZE -framerate $FRAMERATE -i /dev/video0 -f mpjpeg -
else
echo "FFmpeg could not start. Double check your configuration."
exit 1
fi

View file

@ -0,0 +1 @@
python3-pip

View file

@ -1,19 +1,23 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
mkdir -p "${ROOTFS_DIR}/usr/local/bin/"
install -m 755 files/octo-config "${ROOTFS_DIR}/usr/local/bin/octo-config"
install -m 755 files/tp-config "${ROOTFS_DIR}/usr/local/bin/tp-config"
install -m 755 files/octo-settings "${ROOTFS_DIR}/usr/local/bin/octo-settings"
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/tp-lib.sh "${ROOTFS_DIR}/usr/local/lib/tp-lib.sh"
# Autologin on first boot
mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/
cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
[Service]
ExecStart=
ExecStart=-/usr/sbin/agetty --autologin root --noclear %I $TERM
ExecStart=-/usr/sbin/agetty --skip-login --nonewline --noissue --autologin root --noclear %I $TERM
EOF
# Don't boot to a GUI
on_chroot << EOF
# Install PyYAML
pip3 install pyyaml
# Don't boot to a GUI
systemctl set-default multi-user.target
EOF

View file

@ -1,14 +1,20 @@
#!/bin/bash
#!/usr/bin/env bash
# This should never happen, no harm in checking though ;)
if [ "$EUID" -ne 0 ]; then
echo "This image has not been configured properly. Please complain to Logan"
echo "This image has not been configured properly. Please file an issue at https://github.com/logan2611/touchprint/issues"
bash
exit 1
fi
# Prevent Ctrl+C since you shouldn't be able to exit this
trap '' SIGINT
# Set the FIRST_TIME variable to disable cancel boxes
FIRST_TIME="--nocancel"
# Import common functions
source /usr/local/lib/octo-lib.sh
source /usr/local/lib/tp-lib.sh
install_package () {
echo "==========Installing $1==========" >>/home/pi/install.log
@ -21,50 +27,55 @@ error_install () {
}
recommended_menu () {
local RECOMMEND_MENU=$(dialog --nocancel --title "Plugin Manager | Recommended Plugins" --checklist "Check plugins that you wish to install" 0 0 0 \
local RECOMMEND_MENU=$(dialog --title "Plugin Manager | Recommended Plugins" --checklist "Check plugins that you wish to install." 0 0 0 \
"OctoPrint-Dashboard" "Adds a nice dashboard to OctoPrint." ON \
"ExcludeRegion" "Select regions of the bed where you don't want to print." ON \
"NavbarTemp" "Shows the temperature of the Pi, extruder(s) and bed in the navigation bar." ON \
"PrintTimeGenius" "Provides more accurate print time estimates." ON \
"HeaterTimeout" "Turns off the hotend and bed after a set amount of time." ON \
"TouchUI" "Makes the UI easier to use on touchscreens. Also adds a virtual keyboard." ON 3>&1 1>&2 2>&3)
"TouchUI" "Makes the UI easier to use on touchscreens. Also adds a virtual keyboard." ON 3>&1 1>&2 2>&3 || return 0)
RECOMMEND_MENU=($RECOMMEND_MENU)
for ((i = 0; i < ${#RECOMMEND_MENU[@]}; i++)); do
echo $(( $i * 100 / ${#RECOMMEND_MENU[@]} )) | dialog --title "Plugin Manager" --gauge "Installing ${RECOMMEND_MENU[$i]}" 10 50
case ${RECOMMEND_MENU[$i]} in
"OctoPrint-Dashboard") install_package "https://github.com/StefanCohen/OctoPrint-Dashboard/archive/master.zip" || error_install "OctoPrint-Dashboard"; install_package "https://github.com/OllisGit/OctoPrint-DisplayLayerProgress/releases/latest/download/master.zip" || error_install "OctoPrint-Dashboard";;
"ExcludeRegion") install_package "https://github.com/bradcfisher/OctoPrint-ExcludeRegionPlugin/archive/master.zip" || error_install "ExcludeRegion";;
"NavbarTemp") install_package "https://github.com/imrahil/OctoPrint-NavbarTemp/archive/master.zip" || error_install "NavbarTemp";;
"PrintTimeGenius") install_package "https://github.com/eyal0/OctoPrint-PrintTimeGenius/archive/master.zip" || error_install "PrintTimeGenius";;
"HeaterTimeout") install_package "https://github.com/google/OctoPrint-HeaterTimeout/archive/master.zip" || error_install "HeaterTimeout";;
"TouchUI") install_package "https://github.com/BillyBlaze/OctoPrint-TouchUI/archive/master.zip" || error_install "TouchUI";;
"OctoPrint-Dashboard") install_package "https://github.com/StefanCohen/OctoPrint-Dashboard/archive/master.zip" || error_install ${RECOMMEND_MENU[$i]}; install_package "https://github.com/OllisGit/OctoPrint-DisplayLayerProgress/releases/latest/download/master.zip" || error_install ${RECOMMEND_MENU[$i]};;
"ExcludeRegion") install_package "https://github.com/bradcfisher/OctoPrint-ExcludeRegionPlugin/archive/master.zip" || error_install ${RECOMMEND_MENU[$i]};;
"NavbarTemp") install_package "https://github.com/imrahil/OctoPrint-NavbarTemp/archive/master.zip" || error_install ${RECOMMEND_MENU[$i]};;
"PrintTimeGenius") install_package "https://github.com/eyal0/OctoPrint-PrintTimeGenius/archive/master.zip" || error_install ${RECOMMEND_MENU[$i]};;
"HeaterTimeout") install_package "https://github.com/google/OctoPrint-HeaterTimeout/archive/master.zip" || error_install ${RECOMMEND_MENU[$i]};;
"TouchUI") install_package "https://github.com/BillyBlaze/OctoPrint-TouchUI/archive/master.zip" || error_install ${RECOMMEND_MENU[$i]};;
esac
done
}
suggested_menu () {
local SUGGEST_MENU=$(dialog --nocancel --title "Plugin Manager | Suggested Plugins" --checklist "Check plugins that you wish to install" 0 0 0 \
local SUGGEST_MENU=$(dialog --title "Plugin Manager | Suggested Plugins" --checklist "Check plugins that you wish to install.\n\nSome of these may conflict with the recommended plugins." 0 0 0 \
"Themeify" "Adds theming supports and a few themes to OctoPrint." OFF \
"Preheat" "Adds a preheat button to preheat the bed and extruder to the temperature set in the selected gcode file." OFF \
"ConsolidatedTabs" "Allows you to combine several tabs into one larger tab with draggable and resizable panels." OFF \
"DetailedProgress" "Sends commands to your printer to display current printing progress." OFF 3>&1 1>&2 2>&3)
"DetailedProgress" "Sends commands to your printer to display current printing progress." OFF \
"Enclosure" "Adds a lot of features for enclosures such as support for external temperature sensors." OFF 3>&1 1>&2 2>&3 || return 0)
SUGGEST_MENU=($SUGGEST_MENU)
for ((i = 0; i < ${#SUGGEST_MENU[@]}; i++)); do
echo $(( $i * 100 / ${#SUGGEST_MENU[@]} )) | dialog --title "Plugin Manager" --gauge "Installing ${SUGGEST_MENU[$i]}" 10 50
case ${SUGGEST_MENU[$i]} in
"Themeify") install_package "https://github.com/birkbjo/OctoPrint-Themeify/archive/master.zip" || error_install "Themeify";;
"Preheat") install_package "https://github.com/marian42/octoprint-preheat/archive/master.zip" || error_install "Preheat";;
"ConsolidatedTabs") install_package "https://github.com/jneilliii/OctoPrint-ConsolidatedTabs/archive/master.zip" || error_install "ConsolidatedTabs";;
"DetailedProgress") install_package "https://github.com/tpmullan/OctoPrint-DetailedProgress/archive/master.zip" || error_install "DetailedProgress";;
"Themeify") install_package "https://github.com/birkbjo/OctoPrint-Themeify/archive/master.zip" || error_install ${SUGGEST_MENU[$i]};;
"Preheat") install_package "https://github.com/marian42/octoprint-preheat/archive/master.zip" || error_install ${SUGGEST_MENU[$i]};;
"ConsolidatedTabs") install_package "https://github.com/jneilliii/OctoPrint-ConsolidatedTabs/archive/master.zip" || error_install ${SUGGEST_MENU[$i]};;
"DetailedProgress") install_package "https://github.com/tpmullan/OctoPrint-DetailedProgress/archive/master.zip" || error_install ${SUGGEST_MENU[$i]};;
"Enclosure") install_package "https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/master.zip" || error_install ${SUGGEST_MENU[$i]};;
esac
done
}
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
dialog --title "NOTICE" --colors --msgbox "This collection of software is currently in beta, it may contain several bugs. This software is \Zb\Z1NOT\Zn recommended for a production environment." 10 50
# Makes a certificate and key for Nginx HTTPS
openssl req -x509 -nodes -days 36500 -newkey rsa:4096 -subj "/C=/ST=/L=/O=/OU=/CN=*/emailAddress=" -out /etc/ssl/certs/nginx-octoprint.crt -keyout /etc/ssl/private/nginx-octoprint.key
# Force the user to change the pi user's password before the RPi gets botnetted
change_password
@ -76,31 +87,44 @@ nmtui
dpkg-reconfigure tzdata
# Enable/disable OctoPrint, GUI, MJPG and SSH
service_select
service_toggle
screen_timeout
# Makes a certificate and key for Nginx HTTPS
openssl req -x509 -nodes -days 36500 -newkey rsa:4096 -subj "/C=/ST=/L=/O=/OU=/CN=*/emailAddress=" -out /etc/ssl/certs/nginx-octoprint.crt -keyout /etc/ssl/private/nginx-octoprint.key
# If a touchscreen is detected, and the GUI is enabled, ask the user if they want to calibrate it
if ( udevadm info --export-db | grep ID_INPUT_TOUCHSCREEN=1 >/dev/null ) && [[ $(readlink -f /etc/systemd/system/default.target) == "/usr/lib/systemd/system/graphical.target" ]] && dialog --title "Touchscreen Calibration" --defaultno --yesno "Do you wish to calibrate your touchscreen?\nMost touchscreens are calibrated out of the factory, so this is usually not needed." 10 60; then
startx $(which xinput_calibrator) --no-timeout --output-filename /etc/X11/xorg.conf.d/99-calibration.conf
fi
# If OctoPrint and the GUI are running locally, ask the user if they want to change the autologin user
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && [[ $(readlink -f /etc/systemd/system/default.target) == "/usr/lib/systemd/system/graphical.target" ]] && dialog --title "OctoPrint AutoLogin" --yesno "Do you wish to configure the user that the GUI auto logs in as in OctoPrint?\nThis is required if you wish to enable access control in OctoPrint." 10 60; then
octo_autologin
fi
# If OctoPrint/MJPG Streamer is running locally, ask if the user wants to change the default listening port/IP (optional)
if ( [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] || [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]] ) && dialog --title "Nginx Config" --defaultno --yesno "Do you wish to change the default Nginx listening address and/or port?" 10 60; then
nginx_config
nginx_listen
fi
# If MJPG service is enabled, ask user which video device to use
# If MJPG service is enabled, ask the user to configure Nginx basic auth and the video device
if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then
nginx_auth
video_select
video_config
fi
# If OctoPrint is running locally, ask if user wants to preinstall recommended plugins
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then
recommended_menu || return 1
suggested_menu || return 1
recommended_menu && suggested_menu
chown -R octoprint:octoprint /srv/octoprint
chown -R octoprint:octoprint /home/octoprint
fi
# Delete the autologin override and first-time setup utility
rm /etc/systemd/system/getty@tty1.service.d/override.conf
rm /etc/profile.d/first-time.sh
dialog --title "TouchPrint Config" --colors --msgbox "Congratulations! Your install of TouchPrint has been successfully configured.\n\n\Z1To change these settings later, login to your Raspberry Pi and run \"\Z1\Zbtp-config\Zn\Z1\"." 0 0
dialog --title "TouchPrint Config" --infobox "Rebooting..." 0 0
sleep 1
reboot

View file

@ -1,35 +0,0 @@
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "This script needs to be run as root."
exit 1
fi
# Import shared functions
source /usr/local/lib/octo-lib.sh
main_menu () {
local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \
"1" "Configure networking" \
"2" "Change password for pi" \
"3" "Configure services" \
"4" "Configure screen timeout" \
"5" "Configure Nginx" \
"6" "Configure MJPG" \
"7" "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") nginx_config; main_menu; return 0;;
"6") video_config; main_menu; return 0;;
"7") return 0;;
esac
}
main_menu
if dialog --title "Reboot Confirmation" --yesno "Some changes require a reboot to take effect.\nDo you want to reboot now?" 10 50; then
reboot
fi

View file

@ -1,139 +0,0 @@
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 the password field was left blank, exit
if [[ $? -ne 0 ]] || [[ $PASSWORD == "" ]]; then return 1; fi
# If the password is raspberry, tell the user he is an idiot
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 () {
# Toggle the checkboxes if the service is active or not
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" "MJPG-Streamer" $(if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "ON"; else echo "OFF"; fi) \
"3" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; then echo "ON"; else echo "OFF"; fi) \
"4" "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_MJPG=false
local ENABLE_GUI=false
local ENABLE_SSH=false
for i in "${SERVICE_MENU[@]}"; do
case $i in
"1") ENABLE_OCTO=true ;;
"2") ENABLE_MJPG=true ;;
"3") ENABLE_GUI=true ;;
"4") ENABLE_SSH=true ;;
esac
done
if [[ $ENABLE_OCTO == true ]]; then
systemctl enable octoprint
else
systemctl disable octoprint
fi
if [[ $ENABLE_MJPG == true ]]; then
systemctl enable mjpg-streamer
else
systemctl disable mjpg-streamer
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.\n\nDefault: off" 12 60 "off" 3>&1 1>&2 2>&3)
cat > /home/pi/.xtimeout << EOF
xset s ${TIMEOUT}
xset -dpms
EOF
}
nginx_config () {
local LISTEN=""
# Grab the variable from the nginx conf if it exists, otherwise use default
if [[ -f /etc/nginx/listen.conf ]]; then
LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}')
else
LISTEN="443"
fi
LISTEN=$(dialog --title "Nginx Config" --nocancel --inputbox "Configure what port and IP Nginx should listen on.\nTo listen on all IPs, just enter the port.\nDefault: 443" 11 50 "$LISTEN" 3>&1 1>&2 2>&3)
# Write new value to nginx
echo "listen $LISTEN;" > /etc/nginx/listen.conf
}
video_config () {
# In the unlikely event that there are no video devices, don't continue
if ! ls /dev/video* 2>&1 >/dev/null; then
dialog --title "Error" --msgbox "No video devices detected!" 10 50
return 1
fi
# Grab all video devices
local DEVICES=($(ls /dev/video*))
local DEVICELIST=""
# Generate a menu from said video devices
for ((i = 0; i < ${#DEVICES[@]}; i++)); do
DEVICELIST+="${DEVICES[$i]} $i OFF "
done
local DEVICE_MENU=$(dialog --title "Video Config" --nocancel --radiolist "Choose which video device you wish to use for MJPG-Streamer" 10 50 0 $DEVICELIST 3>&1 1>&2 2>&3)
[[ "$DEVICE_MENU" == "" ]] && return 0
# Write selected value to startup script
echo -e '#!/bin/bash'"\n/usr/local/bin/mjpg_streamer -i \"input_uvc.so -d $DEVICE_MENU\" -o \"output_http.so --port 8080\"" > /usr/local/bin/start-mjpg
}

View file

@ -0,0 +1,49 @@
#!/usr/bin/env python3
import yaml
import sys
def loadConfig(path):
with open(path, 'r') as f:
return yaml.full_load(f)
def writeConfig(path, config):
with open(path, 'w') as f:
return yaml.dump(config, f)
def getValue(config, args):
cur = config
for arg in args:
if arg not in cur.keys():
return
else:
cur = cur[arg]
return cur
def setValue(config, args, value):
cur = config
for arg in args[:-1]:
if arg not in cur.keys():
cur[arg] = {}
cur = cur[arg]
cur[args[-1]] = value
if __name__ == '__main__':
if len(sys.argv) > 2:
config = loadConfig(r'/home/octoprint/.octoprint/config.yaml')
if sys.argv[1] == 'read':
print(getValue(config, sys.argv[2:]))
elif sys.argv[1] == 'write':
print(sys.argv[2:-1])
print(sys.argv[-1])
setValue(config, sys.argv[2:-1], sys.argv[-1])
writeConfig(r'/home/octoprint/.octoprint/config.yaml', config)
else:
print('Octo-Settings v1 - A command line utility to change and read OctoPrint\'s settings.')
print('')
print('Usage: ', sys.argv[0], 'read [KEY1] [KEY2] ...')
print(' ', sys.argv[0], 'write [KEY1] [KEY2] ... [VALUE]')

123
stage2/06-utils/files/tp-config Executable file
View file

@ -0,0 +1,123 @@
#!/usr/bin/env bash
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo -e "TP-Config - Configures TouchPrint"
echo -e "Usage: $0"
fi
if [ "$EUID" -ne 0 ]; then
echo "This script needs to be run as root."
exit 1
fi
# Define ASK_REBOOT
ASK_REBOOT=false
# Import shared functions
source /usr/local/lib/tp-lib.sh
main_menu () {
local MAINMENU=$(dialog --nocancel --title "TouchPrint Setup" --menu "" 10 50 0 \
"1" "Configure networking" \
"2" "Change password for pi" \
"3" "Configure services" \
"4" "Configure screen timeout" \
"5" "Calibrate touchscreen" \
"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") services_menu; main_menu; return 0;;
"4") screen_timeout; main_menu; return 0;;
"5") dialog --title "Touchscreen Calibration" --infobox "Waiting for touchscreen calibrator to close..." 3 50;
DISPLAY=:0 xinput_calibrator --no-timeout --output-filename /etc/X11/xorg.conf.d/99-calibration.conf;
main_menu;
return 0;;
"6") return 0;;
esac
}
services_menu () {
local SERVICESMENU=$(dialog --nocancel --title "Services Select" --menu "" 10 50 0 \
"1" "Enable/disable services" \
"2" "Service health check" \
"3" "Configure Nginx" \
"4" "Configure MJPG" \
"5" "Configure OctoPrint" \
"6" "Go Back" 3>&1 1>&2 2>&3)
case $SERVICESMENU in
"1") service_toggle; services_menu; return 0;;
"2") service_health; services_menu; return 0;;
"3") nginx_menu; services_menu; return 0;;
"4") video_menu; services_menu; return 0;;
"5") octo_menu; services_menu; return 0;;
"6") return 0;;
esac
}
service_health () {
# Grab listening address/port from Nginx config
if [[ -f /etc/nginx/listen.conf ]]; then
LISTEN=$(awk '/listen/{gsub(";",""); print $2}' /etc/nginx/listen.conf)
else
LISTEN="443"
fi
# If Nginx config didn't contain a port, assume localhost
if ! echo $LISTEN | grep ":" 2>&1; then
ADDRESS="localhost:$LISTEN"
else
ADDRESS=$LISTEN
fi
# I hate bash, and soon you will too
dialog --colors --title "Service Health" --msgbox "\
\ZnOctoPrint: \Zb$(if curl -s -I 127.0.0.1:5000 >/dev/null; then echo '\Z2Online'; elif [[ ! -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then echo "Disabled"; else echo '\Z1Offline'; fi)
\ZnMJPG: \Zb$(if curl -s -I 127.0.0.1:9000 >/dev/null; then echo '\Z2Online'; elif [[ ! -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "Disabled"; else echo '\Z1Offline'; fi)
\ZnNginx: \Zb$(if curl -k -s -I https://$ADDRESS >/dev/null; then echo '\Z2Online'; elif [[ ! -f /etc/systemd/system/multi-user.target.wants/nginx.service ]]; then echo "Disabled"; else echo '\Z1Offline'; fi)
\ZnSSH: \Zb$(if pgrep sshd >/dev/null; then echo '\Z2Online'; elif [[ ! -f /etc/systemd/system/multi-user.target.wants/sshd.service ]]; then echo "Disabled"; else echo '\Z1Offline'; fi)" 0 0
}
nginx_menu () {
local NGINXMENU=$(dialog --title "Nginx Config" --menu "" 10 50 0 \
"1" "Listening Settings" \
"2" "MJPG Authentication" \
"3" "Go Back" 3>&1 1>&2 2>&3)
case $NGINXMENU in
"1") nginx_listen; nginx_menu; return 0;;
"2") nginx_auth; nginx_menu; return 0;;
"3") return 0;;
esac
}
video_menu () {
local VIDEOMENU=$(dialog --title "MJPG Config" --menu "" 10 50 0 \
"1" "Camera Selection" \
"2" "Video Settings" \
"3" "Go Back" 3>&1 1>&2 2>&3)
case $VIDEOMENU in
"1") video_select; video_menu; return 0;;
"2") video_config; video_menu; return 0;;
"3") return 0;;
esac
}
octo_menu () {
local OCTOMENU=$(dialog --title "OctoPrint Config" --menu "" 10 50 0 \
"1" "Autologin User" \
"2" "Go Back" 3>&1 1>&2 2>&3)
case $OCTOMENU in
"1") octo_autologin; octo_menu; return 0;;
"2") return 0;;
esac
}
main_menu
if [[ $ASK_REBOOT == true ]] && dialog --title "Reboot Confirmation" --yesno "Some changes require a reboot to take effect.\nDo you want to reboot now?" 10 50; then
reboot
fi

View file

@ -0,0 +1,296 @@
change_password () {
local PASSWORD="$(dialog --title "Change Password" $FIRST_TIME --insecure --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3 || return 0)"
# If the password field was left blank and we aren't in the first time setup, exit
[[ $PASSWORD == "" ]] && [[ $FIRST_TIME == "" ]] && return 0
# If we are in the first time setup and the password field is blank, make the user restart
[[ $PASSWORD == "" ]] && ! [[ $FIRST_TIME == "" ]] && change_password
# If the password is raspberry, tell the user he is an idiot
if [[ "$PASSWORD" == "raspberry" ]]; then
dialog --title "Change Password" --msgbox "That password sucks. Please use a different one :)" 10 50
change_password
return 0
fi
if [[ "$(dialog $FIRST_TIME --title "Change Password" --insecure --passwordbox "Confirm new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3 || return 0)" == "$PASSWORD" ]]; then
echo -e "pi:$PASSWORD" | chpasswd
else
dialog --title "Change Password" --colors --msgbox "\Z1\ZbPasswords did not match!" 5 30
change_password
return 0
fi
unset PASSWORD
}
service_toggle () {
# Toggle the checkboxes if the service is active or not
local SERVICE_MENU=$(dialog $FIRST_TIME --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" "MJPG-Streamer" $(if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then echo "ON"; else echo "OFF"; fi) \
"3" "GUI" $(if [[ $(systemctl get-default) == "graphical.target" ]]; then echo "ON"; else echo "OFF"; fi) \
"4" "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 || return 0)
SERVICE_MENU=($SERVICE_MENU)
local ENABLE_OCTO=false
local ENABLE_MJPG=false
local ENABLE_GUI=false
local ENABLE_SSH=false
for i in "${SERVICE_MENU[@]}"; do
case $i in
"1") ENABLE_OCTO=true ;;
"2") ENABLE_MJPG=true ;;
"3") ENABLE_GUI=true ;;
"4") ENABLE_SSH=true ;;
esac
done
# If FIRST_TIME is not empty, this is the first time boot so don't actually start stuff, otherwise use normal behaviour
if ! [[ "$FIRST_TIME" == "" ]]; then
if [[ $ENABLE_OCTO == true ]]; then
systemctl enable octoprint
else
systemctl disable octoprint
fi
if [[ $ENABLE_MJPG == true ]]; then
systemctl enable mjpg-streamer
raspi-config nonint do_camera 0 # Counter intuitively enables the camera
else
systemctl disable mjpg-streamer
raspi-config nonint do_camera 1 # Disables the camera
fi
if [[ $ENABLE_OCTO == true ]] && [[ $ENABLE_MJPG == true ]]; then
systemctl enable nginx
elif [[ $ENABLE_OCTO == false ]] && [[ $ENABLE_MJPG == false ]]; then
systemctl disable nginx
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
else
if [[ $ENABLE_OCTO == true ]]; then
systemctl enable --now octoprint
else
systemctl disable --now octoprint
fi
if [[ $ENABLE_MJPG == true ]]; then
systemctl enable --now mjpg-streamer
raspi-config nonint do_camera 0 # Counter intuitively enables the camera
ASK_REBOOT=true
else
systemctl disable --now mjpg-streamer
raspi-config nonint do_camera 1 # Disables the camera
ASK_REBOOT=true
fi
if [[ $ENABLE_OCTO == true ]] && [[ $ENABLE_MJPG == true ]]; then
systemctl enable --now nginx
elif [[ $ENABLE_OCTO == false ]] && [[ $ENABLE_MJPG == false ]]; then
systemctl disable --now nginx
fi
if [[ $ENABLE_GUI == true ]]; then
systemctl set-default graphical.target
ASK_REBOOT=true
else
systemctl set-default multi-user.target
ASK_REBOOT=true
fi
if [[ $ENABLE_SSH == true ]]; then
systemctl enable --now ssh
else
systemctl disable --now ssh
fi
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 $FIRST_TIME --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.\n\nDefault: off" 12 60 "off" 3>&1 1>&2 2>&3 || return 0)
# If timeout is blank, exit before we break everything
[[ "$TIMEOUT" == "" ]] && return 0
cat > /home/kiosk/.xtimeout << EOF
xset s ${TIMEOUT}
xset -dpms
xset s noblank
EOF
if [[ $(readlink -f /etc/systemd/system/default.target) == "/usr/lib/systemd/system/graphical.target" ]]; then
ASK_REBOOT=true
fi
}
octo_autologin () {
local AUTOLOGIN_MENU="$(dialog --title "OctoPrint AutoLogin" --inputbox "Enter the username of the user that you want the GUI to autologin as on startup." 10 50 $(octo-settings read accessControl autologinAs) 3>&1 1>&2 2>&3 || return 0)"
# If the text field is blank, exit before everything (probably doesn't) break
[[ "$AUTOLOGIN_MENU" == "" ]] && return 0
octo-settings write accessControl autologinAs $AUTOLOGIN_MENU
if [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]]; then
systemctl restart octoprint
ASK_REBOOT=true
fi
}
nginx_listen () {
local LISTEN=""
# Grab the variable from the nginx conf if it exists, otherwise use default
if [[ -f /etc/nginx/listen.conf ]]; then
LISTEN=$(awk '/listen/{gsub(";",""); print $2}' /etc/nginx/listen.conf)
else
LISTEN="443"
fi
LISTEN=$(dialog --title "Nginx Config" --inputbox "Configure what port and IP Nginx should listen on.\nTo listen on all IPs, just enter the port.\nDefault: 443" 11 50 "$LISTEN" 3>&1 1>&2 2>&3 || return 0)
[[ "$LISTEN" == "" ]] && return 0
# Write new value to nginx
echo "listen $LISTEN;" > /etc/nginx/listen.conf
if [[ -f /etc/systemd/system/multi-user.target.wants/nginx.service ]]; then
systemctl restart nginx
ASK_REBOOT=true
fi
}
nginx_auth () {
local NGINXAUTH_MENU=$(dialog --colors $FIRST_TIME --insecure --title "Nginx Config" --mixedform "Input desired username and password for the MJPG stream.\n\nLeave both fields blank if you do not want authentication \Zb\Z1(NOT RECOMMENDED)\Zn." 12 60 0\
"Username: " 1 1 "" 1 11 10 0 0 \
"Password: " 2 1 "" 2 11 30 0 1 3>&1 1>&2 2>&3 || return 0)
NGINXAUTH_MENU=($NGINXAUTH_MENU)
# If all the fields are blank, remove the auth stuff and exit
if [[ "${NGINXAUTH_MENU[*]}" == "" ]]; then
echo "" > /etc/nginx/auth.conf
rm /etc/nginx/.htpasswd
return 0
fi
# If only one of them is blank, make the user start over
if [[ ${NGINXAUTH_MENU[0]} == "" ]] || [[ ${NGINXAUTH_MENU[1]} == "" ]]; then
dialog --title "Nginx Config" --colors --msgbox "\Z1\ZbInvalid input!" 5 20
nginx_auth
return 0
fi
# Write the auth config and password file to Nginx
echo -e "satisfy any;\nallow 127.0.0.1;\ndeny all;\nauth_basic \"TouchPrint MJPG Stream\";\nauth_basic_user_file /etc/nginx/.htpasswd;" > /etc/nginx/auth.conf
#htpasswd -b -B -c /etc/nginx/.htpasswd ${NGINXAUTH_MENU[0]} ${NGINXAUTH_MENU[1]}
echo "${NGINXAUTH_MENU[0]}:$(openssl passwd -apr1 ${NGINXAUTH_MENU[1]})" > /etc/nginx/.htpasswd
unset NGINXAUTH_MENU
# Set perms so that no one steals our precious password hashes
chown root:www-data /etc/nginx/.htpasswd
chmod 640 /etc/nginx/.htpasswd
if [[ -f /etc/systemd/system/multi-user.target.wants/nginx.service ]]; then
systemctl restart nginx
fi
}
video_select () {
# In the unlikely event that there are no video devices, don't continue
if ! ls /dev/video* 2>&1 >/dev/null; then
dialog --title "Video Config" --colors --msgbox "\Z1\ZbNo video devices detected!" 5 30
return 1
fi
# Grab config values
source /usr/local/etc/mjpg-server/config.sh
# Grab all video devices
local DEVICES=($(ls /dev/video*))
local DEVICELIST=""
# Generate a menu from said video devices
for ((i = 0; i < ${#DEVICES[@]}; i++)); do
if [[ "$VIDEO_DEVICE" == ${DEVICES[$i]} ]]; then
DEVICELIST+="${DEVICES[$i]} $i ON "
else
DEVICELIST+="${DEVICES[$i]} $i OFF "
fi
done
local DEVICE_MENU=$(dialog --title "MJPG Config" $FIRST_TIME --radiolist "Choose which video device you wish to use for MJPG-Streamer" 10 50 0 $DEVICELIST 3>&1 1>&2 2>&3 || return 0)
[[ "$DEVICE_MENU" == "" ]] && return 0
# Write selected value to config file
echo -e "VIDEO_DEVICE=$DEVICE_MENU\nVIDEO_SIZE=$VIDEO_SIZE\nFRAMERATE=$FRAMERATE" > /usr/local/etc/mjpg-server/config.sh
if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then
systemctl restart mjpg-streamer
fi
}
video_config () {
# Include config values
source /usr/local/etc/mjpg-server/config.sh
# Set video device to a resonable default if it isn't set for some reason
if [[ "$VIDEO_DEVICE" == "" ]]; then
VIDEO_DEVICE="/dev/video0"
fi
local VIDEOCONFIG_MENU=$(dialog $FIRST_TIME --title "MJPG Config" --form "Choose desired camera resolution and framerate." 10 50 0\
"Resolution: " 1 1 "$VIDEO_SIZE" 1 13 10 0 \
"Framerate: " 2 1 "$FRAMERATE" 2 12 3 0 3>&1 1>&2 2>&3 || return 0)
VIDEOCONFIG_MENU=($VIDEOCONFIG_MENU)
# If one of the fields is empty, tell the user to start over
if [[ "${VIDEOCONFIG_MENU[0]}" == "" ]] || [[ "${VIDEOCONFIG_MENU[1]}" == "" ]]; then
dialog --title "Error" --msgbox "Invalid input!" 10 50
video_config
return 0
fi
# Write values to config file
echo -e "VIDEO_DEVICE=$VIDEO_DEVICE\nVIDEO_SIZE=${VIDEOCONFIG_MENU[0]}\nFRAMERATE=${VIDEOCONFIG_MENU[1]}" > /usr/local/etc/mjpg-server/config.sh
if [[ -f /etc/systemd/system/multi-user.target.wants/mjpg-streamer.service ]]; then
systemctl restart mjpg-streamer
fi
}

View file

@ -1,4 +1,4 @@
IMG_SUFFIX="-lite"
IMG_SUFFIX="-nogui"
if [ "${USE_QEMU}" = "1" ]; then
export IMG_SUFFIX="${IMG_SUFFIX}-qemu"
fi

View file

@ -1,2 +0,0 @@
NOOBS_NAME="Octoprint"
NOOBS_DESCRIPTION="A fork of Raspbian with Octoprint"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
if [ ! -d "${ROOTFS_DIR}" ]; then
copy_previous

View file

@ -18,3 +18,4 @@ obconf
arandr
openbox
nodm
xinput-calibrator

View file

@ -3,7 +3,6 @@ xserver-xorg-video-fbdev
xserver-xorg-video-fbturbo
xinit
menu-xdg
zenity
xdg-utils
gvfs-backends
gvfs-fuse

View file

@ -1,41 +1,8 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
#echo -n -e "NODM_USER=${FIRST_USER_NAME}\nNODM_XSESSION=/home/${FIRST_USER_NAME}/.xprofile" > ${ROOTFS_DIR}/etc/nodm.conf
cat > ${ROOTFS_DIR}/etc/default/nodm << EOF
# nodm configuration
# Set NODM_ENABLED to something different than 'false' to enable nodm
NODM_ENABLED=true
# User to autologin for
NODM_USER=${FIRST_USER_NAME}
# First vt to try when looking for free VTs
NODM_FIRST_VT=7
# X session
NODM_XSESSION=/home/${FIRST_USER_NAME}/.xprofile
# Options for nodm itself
NODM_OPTIONS=
# Options for the X server.
#
# Format: [/usr/bin/<Xserver>] [:<disp>] <Xserver-options>
#
# The Xserver executable and the display name can be omitted, but should
# be placed in front, if nodm's defaults shall be overridden.
NODM_X_OPTIONS='-nolisten tcp'
# If an X session will run for less than this time in seconds, nodm will wait an
# increasing bit of time before restarting the session.
NODM_MIN_SESSION_TIME=60
# Timeout (in seconds) to wait for X to be ready to accept connections. If X is
# not ready before this timeout, it is killed and restarted.
NODM_X_TIMEOUT=300
EOF
mkdir -p ${ROOTFS_DIR}/etc/default
install -m 644 files/nodm ${ROOTFS_DIR}/etc/default/nodm
# Probably not needed
on_chroot << EOF

View file

@ -0,0 +1,33 @@
# nodm configuration
# Set NODM_ENABLED to something different than 'false' to enable nodm
NODM_ENABLED=true
# User to autologin for
NODM_USER=kiosk
# First vt to try when looking for free VTs
NODM_FIRST_VT=7
# X session
NODM_XSESSION=/home/kiosk/.xprofile
# Options for nodm itself
NODM_OPTIONS=
# Options for the X server.
#
# Format: [/usr/bin/<Xserver>] [:<disp>] <Xserver-options>
#
# The Xserver executable and the display name can be omitted, but should
# be placed in front, if nodm's defaults shall be overridden.
NODM_X_OPTIONS='-nolisten tcp'
# If an X session will run for less than this time in seconds, nodm will wait an
# increasing bit of time before restarting the session.
NODM_MIN_SESSION_TIME=60
# Timeout (in seconds) to wait for X to be ready to accept connections. If X is
# not ready before this timeout, it is killed and restarted.
NODM_X_TIMEOUT=300

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
#rm -f "${ROOTFS_DIR}/etc/systemd/system/dhcpcd.service.d/wait.conf"

12
stage3/02-kiosk/00-run.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
mkdir -p "${ROOTFS_DIR}/home/kiosk"
install -m 755 files/.xprofile "${ROOTFS_DIR}/home/kiosk/.xprofile"
install -m 755 files/.browser.sh "${ROOTFS_DIR}/home/kiosk/.browser.sh"
install -m 755 files/.xtimeout "${ROOTFS_DIR}/home/kiosk/.xtimeout"
mkdir -p "${ROOTFS_DIR}/home/kiosk/.config/openbox"
install -m 644 files/autostart "${ROOTFS_DIR}/home/kiosk/.config/openbox/autostart"
install -m 644 files/menu.xml "${ROOTFS_DIR}/home/kiosk/.config/openbox/menu.xml"

View file

@ -1,20 +1,28 @@
#!/bin/bash
#!/usr/bin/env bash
# Deletes cookies
rm ~/.surf/cookies.txt
# Grabs the port (and IP) out of the nginx config
LISTEN=$(grep -i listen /etc/nginx/listen.conf | awk '{gsub(";",""); print $2}')
LISTEN=$(awk '/listen/{gsub(";",""); print $2}' /etc/nginx/listen.conf)
# If the value we just grabbed doesn't contain an IP, prepend localhost
if ! echo $LISTEN | grep ":" 2>&1; then
ADDRESS="localhost:$LISTEN"
ADDRESS="https://localhost:$LISTEN"
else
ADDRESS=$LISTEN
ADDRESS="https://$LISTEN"
fi
# Override the automatically detected address if the user wants to
if [[ -f ~/.overrideurl.sh ]]; then source ~/.overrideurl.sh; fi
# Wait until OctoPrint comes up
while ! curl "$ADDRESS" 2>&1 >/dev/null; do
# Wait until Nginx/override comes up
while ! curl -f -k -s -I "$ADDRESS" 2>&1 >/dev/null; do
sleep 1
done
# Wait until OctoPrint comes up if it is enabled
while [[ -f /etc/systemd/system/multi-user.target.wants/octoprint.service ]] && ! curl -f -s -I "localhost:5000"; do
sleep 1
done
@ -26,4 +34,4 @@ done
# -K | Enable kiosk mode (doesn't seem to do anything?)
# -n | Disable web inspector
# -p | Disable plugins
surf -t -F -g -K -n -p "https://$ADDRESS"
surf -t -F -g -K -n -p "$ADDRESS"

View file

@ -0,0 +1,3 @@
xset s 60
xset -dpms
xset s noblank

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<openbox_menu xmlns="http://openbox.org/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://openbox.org/
file:///usr/share/openbox/menu.xsd">
<menu id="root-menu" label="Openbox 3">
<item label="Restart Browser">
<action name="Execute"><execute>killall surf</execute></action>
<action name="Execute"><execute>bash ~/.browser.sh</execute></action>
</item>
<separator />
<item label="Restart GUI">
<action name="Exit" />
</item>
</menu>
</openbox_menu>

View file

@ -1,4 +1,4 @@
IMG_SUFFIX="-lite"
IMG_SUFFIX=""
if [ "${USE_QEMU}" = "1" ]; then
export IMG_SUFFIX="${IMG_SUFFIX}-qemu"
fi

View file

@ -1,2 +0,0 @@
NOOBS_NAME="Octoprint Kiosk"
NOOBS_DESCRIPTION="A fork of Raspbian that includes OctoPrint and a nice frontend"

View file

@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
set -e
if [ ! -d "${ROOTFS_DIR}" ]; then
copy_previous