Unattended upgrades, added octo-config

Implemented unattended upgrades
Moved default systemd target command to utils
Octo-Config is no longer a blank text file and now does stuff
This commit is contained in:
Logan G 2020-08-12 16:45:21 -06:00
parent 23c608198b
commit ce6b2a628b
Signed by: logan
GPG key ID: E328528C921E7A7A
5 changed files with 125 additions and 2 deletions

View file

@ -49,3 +49,5 @@ ntfs-3g
pciutils pciutils
rpi-eeprom rpi-eeprom
raspinfo raspinfo
unattended-upgrades
apt-listchanges

View file

@ -60,3 +60,8 @@ rm -f "${ROOTFS_DIR}/etc/ssh/"ssh_host_*_key*
rm -f "${ROOTFS_DIR}/etc/sudoers.d/010_pi-nopasswd" # Fuck you :) rm -f "${ROOTFS_DIR}/etc/sudoers.d/010_pi-nopasswd" # Fuck you :)
echo "%sudo ALL=(ALL:ALL) ALL" > ${ROOTFS_DIR}/etc/sudoers.d/group echo "%sudo ALL=(ALL:ALL) ALL" > ${ROOTFS_DIR}/etc/sudoers.d/group
on_chroot << EOF
echo unattended-upgrades unattended-upgrades/enable_auto_updates boolean true | debconf-set-selections
dpkg-reconfigure -f noninteractive unattended-upgrades
EOF

View file

@ -3,7 +3,6 @@
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 on_chroot << EOF
systemctl set-default multi-user.target
if ! pip list | grep -F octoprint; then if ! pip list | grep -F octoprint; then
if [ -d /home/octoprint ]; then if [ -d /home/octoprint ]; then
cd /home/octoprint || exit 1 cd /home/octoprint || exit 1

View file

@ -12,3 +12,6 @@ ExecStart=
ExecStart=-/usr/sbin/agetty --autologin root --noclear %I $TERM ExecStart=-/usr/sbin/agetty --autologin root --noclear %I $TERM
EOF EOF
on_chroot << EOF
systemctl set-default multi-user.target
EOF

View file

@ -1,3 +1,117 @@
#!/bin/bash #!/bin/bash
change_password () {
local PASSWORD="$(whiptail --title "Change Password" --nocancel --passwordbox "Enter new password for user \"pi\"" 10 50 3>&1 1>&2 2>&3)"
if [[ $? != 0 ]]; then return 1; fi
if [[ "$PASSWORD" == "raspberry" ]]; then
whiptail --title "Change Password" --nocancel --msgbox "That password sucks. Please use a different one :)" 10 50
change_password
return 0
fi
if [[ "$(whiptail --nocancel --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
whiptail --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=$(whiptail --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=$(whiptail --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 () {
local MAINMENU=$(whiptail --separate-output --nocancel --title "Pi Setup" --menu "" 10 50 0 \
"1" "Configure Networking" \
"2" "Change password for pi" \
"3" "Configure services" \
"4" "Configure screen timeout" \
"5" "Exit" 3>&1 1>&2 2>&3)
case $MAINMENU in
"1") nmtui; main_menu; return 0;;
"2") service_select; main_menu; return 0;;
"3") change_password; main_menu; return 0;;
"4") screen_timeout; main_menu; return 0;;
"5") return 0;;
esac
}
main_menu
if whiptail --title "Reboot Confirmation" --yesno "Some changes require a reboot to take effect.\nDo you want to reboot now?" 10 50; then
reboot
fi