Moving towards first beta release
OctoPrint port and listening IP can now be configured First-time and Octo-Config now use a shared library reducing duplicate code Reverted output files to default format Updated TODO
This commit is contained in:
parent
5625779c12
commit
b94fcfc1c9
12 changed files with 158 additions and 154 deletions
2
TODO.md
2
TODO.md
|
@ -12,5 +12,7 @@
|
||||||
- Add on screen keyboard to Openbox autostart
|
- Add on screen keyboard to Openbox autostart
|
||||||
|
|
||||||
## Misc
|
## Misc
|
||||||
|
- Add MJPEG streamer
|
||||||
- 64 bit builds
|
- 64 bit builds
|
||||||
- More security
|
- More security
|
||||||
|
- e
|
||||||
|
|
7
build.sh
7
build.sh
|
@ -153,12 +153,11 @@ fi
|
||||||
|
|
||||||
export USE_QEMU="${USE_QEMU:-0}"
|
export USE_QEMU="${USE_QEMU:-0}"
|
||||||
export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}"
|
export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}"
|
||||||
export IMG_TIME="${IMG_TIME:-"$(date +%s)"}"
|
export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_NAME}"}"
|
||||||
export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_TIME}-${IMG_NAME}"}"
|
export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_NAME}"}"
|
||||||
export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_TIME}-${IMG_NAME}"}"
|
|
||||||
|
|
||||||
export SCRIPT_DIR="${BASE_DIR}/scripts"
|
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_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
|
||||||
export DEPLOY_ZIP="${DEPLOY_ZIP:-2}"
|
export DEPLOY_ZIP="${DEPLOY_ZIP:-2}"
|
||||||
export LOG_FILE="${WORK_DIR}/build.log"
|
export LOG_FILE="${WORK_DIR}/build.log"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
|
IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
|
||||||
INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info"
|
INFO_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.info"
|
||||||
|
|
||||||
|
echo "Part 1"
|
||||||
on_chroot << EOF
|
on_chroot << EOF
|
||||||
if [ -x /etc/init.d/fake-hwclock ]; then
|
if [ -x /etc/init.d/fake-hwclock ]; then
|
||||||
/etc/init.d/fake-hwclock stop
|
/etc/init.d/fake-hwclock stop
|
||||||
|
@ -12,19 +13,23 @@ if hash hardlink 2>/dev/null; then
|
||||||
fi
|
fi
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
echo "Part 2"
|
||||||
if [ -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config" ]; then
|
if [ -d "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config" ]; then
|
||||||
chmod 700 "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config"
|
chmod 700 "${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Part 3"
|
||||||
rm -f "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache"
|
rm -f "${ROOTFS_DIR}/etc/apt/apt.conf.d/51cache"
|
||||||
rm -f "${ROOTFS_DIR}/usr/bin/qemu-arm-static"
|
rm -f "${ROOTFS_DIR}/usr/bin/qemu-arm-static"
|
||||||
|
|
||||||
|
echo "Part 4"
|
||||||
if [ "${USE_QEMU}" != "1" ]; then
|
if [ "${USE_QEMU}" != "1" ]; then
|
||||||
if [ -e "${ROOTFS_DIR}/etc/ld.so.preload.disabled" ]; 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"
|
mv "${ROOTFS_DIR}/etc/ld.so.preload.disabled" "${ROOTFS_DIR}/etc/ld.so.preload"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Part 5"
|
||||||
rm -f "${ROOTFS_DIR}/etc/network/interfaces.dpkg-old"
|
rm -f "${ROOTFS_DIR}/etc/network/interfaces.dpkg-old"
|
||||||
|
|
||||||
rm -f "${ROOTFS_DIR}/etc/apt/sources.list~"
|
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}/root/.vnc/private.key"
|
||||||
rm -f "${ROOTFS_DIR}/etc/vnc/updateid"
|
rm -f "${ROOTFS_DIR}/etc/vnc/updateid"
|
||||||
|
|
||||||
|
echo "Part 6"
|
||||||
update_issue "$(basename "${EXPORT_DIR}")"
|
update_issue "$(basename "${EXPORT_DIR}")"
|
||||||
install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/issue.txt"
|
install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/issue.txt"
|
||||||
|
|
||||||
cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE"
|
cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE"
|
||||||
|
|
||||||
|
echo "Part 7"
|
||||||
{
|
{
|
||||||
if [ -f "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" ]; then
|
if [ -f "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" ]; then
|
||||||
firmware=$(zgrep "firmware as of" \
|
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' ')"
|
ROOT_DEV="$(mount | grep "${ROOTFS_DIR} " | cut -f1 -d' ')"
|
||||||
|
|
||||||
|
echo "Part 8"
|
||||||
unmount "${ROOTFS_DIR}"
|
unmount "${ROOTFS_DIR}"
|
||||||
zerofree "${ROOT_DEV}"
|
zerofree "${ROOT_DEV}"
|
||||||
|
|
||||||
|
@ -89,6 +96,7 @@ mkdir -p "${DEPLOY_DIR}"
|
||||||
rm -f "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip"
|
rm -f "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip"
|
||||||
rm -f "${DEPLOY_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
|
rm -f "${DEPLOY_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
|
||||||
|
|
||||||
|
echo "Part 9"
|
||||||
if [ "${DEPLOY_ZIP}" == "1" ]; then
|
if [ "${DEPLOY_ZIP}" == "1" ]; then
|
||||||
pushd "${STAGE_WORK_DIR}" > /dev/null
|
pushd "${STAGE_WORK_DIR}" > /dev/null
|
||||||
zip "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip" \
|
zip "${DEPLOY_DIR}/${ZIP_FILENAME}${IMG_SUFFIX}.zip" \
|
||||||
|
@ -100,4 +108,5 @@ else
|
||||||
cp "$IMG_FILE" "$DEPLOY_DIR"
|
cp "$IMG_FILE" "$DEPLOY_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Part 10"
|
||||||
cp "$INFO_FILE" "$DEPLOY_DIR"
|
cp "$INFO_FILE" "$DEPLOY_DIR"
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
source /srv/octoprint/host
|
||||||
|
if [[ -f ~/.overrideurl.sh ]]; then source ./.overrideurl.sh; fi
|
||||||
|
|
||||||
# Wait until OctoPrint comes up
|
# 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
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
surf -d -F -g -K -n -p localhost:5000
|
surf -d -F -g -K -n -p "$HOST:$PORT"
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
xset s 0
|
[ -f ~/.xtimeout ] && . ~/.xtimeout
|
||||||
xset -dpms
|
|
||||||
exec openbox-session
|
exec openbox-session
|
||||||
|
|
|
@ -5,7 +5,7 @@ Description=OctoPrint Daemon
|
||||||
Type=simple
|
Type=simple
|
||||||
User=octoprint
|
User=octoprint
|
||||||
Group=octoprint
|
Group=octoprint
|
||||||
ExecStart=/srv/octoprint/venv/bin/octoprint serve
|
ExecStart=/usr/local/bin/start-octoprint
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
mkdir -p "${ROOTFS_DIR}/usr/local/bin/"
|
mkdir -p "${ROOTFS_DIR}/usr/local/bin/"
|
||||||
install -m 755 files/octo-config "${ROOTFS_DIR}/usr/local/bin/octo-config"
|
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/
|
mkdir -p ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/
|
||||||
cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
|
cat > ${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
|
||||||
|
|
|
@ -6,57 +6,7 @@ if [ "$EUID" -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
change_password () {
|
source /usr/local/lib/octo-lib.sh
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
install_package () {
|
install_package () {
|
||||||
echo "==========Installing $1==========" >>/home/pi/install.log
|
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
|
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
|
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
|
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
|
nmtui
|
||||||
|
|
||||||
service_select || return 1
|
service_select || return 1
|
||||||
|
|
||||||
screen_timeout || 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
|
if dialog --title "Plugin Manager" --yesno "Do you wish to preinstall some suggested plugins?" 10 60; then
|
||||||
recommended_menu || return 1
|
recommended_menu || return 1
|
||||||
suggested_menu || return 1
|
suggested_menu || return 1
|
||||||
chown -R octoprint:octoprint /srv/octoprint
|
chown -R octoprint:octoprint /srv/octoprint
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm /etc/systemd/system/getty@tty1.service.d/override.conf
|
rm /etc/systemd/system/getty@tty1.service.d/override.conf
|
||||||
rm /etc/profile.d/first-time.sh
|
rm /etc/profile.d/first-time.sh
|
||||||
reboot
|
reboot
|
||||||
|
|
|
@ -5,94 +5,7 @@ if [ "$EUID" -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
source /usr/local/lib/octo-lib.sh
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
main_menu () {
|
main_menu () {
|
||||||
local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \
|
local MAINMENU=$(dialog --nocancel --title "Pi Setup" --menu "" 10 50 0 \
|
||||||
|
@ -100,14 +13,16 @@ main_menu () {
|
||||||
"2" "Change password for pi" \
|
"2" "Change password for pi" \
|
||||||
"3" "Configure services" \
|
"3" "Configure services" \
|
||||||
"4" "Configure screen timeout" \
|
"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
|
case $MAINMENU in
|
||||||
"1") nmtui; main_menu; return 0;;
|
"1") nmtui; main_menu; return 0;;
|
||||||
"2") change_password; main_menu; return 0;;
|
"2") change_password; main_menu; return 0;;
|
||||||
"3") service_select; main_menu; return 0;;
|
"3") service_select; main_menu; return 0;;
|
||||||
"4") screen_timeout; 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
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
107
stage2/05-utils/files/octo-lib.sh
Normal file
107
stage2/05-utils/files/octo-lib.sh
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
10
stage2/05-utils/files/start-octoprint
Normal file
10
stage2/05-utils/files/start-octoprint
Normal file
|
@ -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
|
Loading…
Reference in a new issue