#!/usr/bin/env sh # SPDX-License-Identifier: GPL-3.0 # Denis Kanuf die() { >&2 printf '\e[1;31mdied: %s\e[0m\n' "$*" exit 1 } l() { >&2 printf '\e[1m%s\e[0m\n' "$*" } d() { >&2 printf '\e[1;34m# %s\e[0m\n' "$*" "$@" || die "$*" } MNAME=octoprint MDIR=/var/lib/machines/$MNAME TDIR=/var/lib/machines/$MNAME-template DEVPTN='/dev/ttyUSB*' LICENSE="$(cat < EOF )" alias OP='d systemd-nspawn --machine=$MNAME --hostname=$MNAME --directory="$MDIR" --tmpfs=/run --tmpfs=/run/lock' t_mkdir() { for d do d install -d "$TDIR/$d" done } ############################################################################### ho_install() { d apt install -y systemd-container debootstrap cron-apt dnsmasq d dd of=/etc/cron-apt/action.d/6-upgrade <&2 echo "not a container for running octoprint - no device" exit 0 elif [ -e "/dev/$device" ] then > /local/env echo OCTOPRINT_HOST=0.0.0.0 >>/local/env echo OCTOPRINT_PORT=$((2000+${device#*USB})) install -o octoprint -g octoprint -m 700 -d /var/lib/octoprint /usr/bin/systemctl enable --no-block --now octoprint.service /usr/bin/systemctl disable octoprint-init.service else >&2 echo "Device not found: $device" exit 1 fi } ############################################################################### case "$1" in install) ho_install ;; list) ho_list ;; install_env) ho_environment ;; *) >&2 echo "Usage: $0 install" exit 1 ;; esac