Added first time setup

This commit is contained in:
Logan G 2020-08-11 18:25:59 -06:00
parent 76200d1b89
commit 201707be75
Signed by: logan
GPG key ID: E328528C921E7A7A
4 changed files with 67 additions and 1 deletions

View file

@ -13,7 +13,7 @@ if ! id -u ${FIRST_USER_NAME} >/dev/null 2>&1; then
adduser --disabled-password --gecos "" ${FIRST_USER_NAME} adduser --disabled-password --gecos "" ${FIRST_USER_NAME}
fi fi
if ! id -u octoprint >/dev/null 2>&1; then if ! id -u octoprint >/dev/null 2>&1; then
adduser --disabled-password --gecos "" octoprint adduser --system --shell /usr/sbin/nologin --disabled-password --gecos "" octoprint
fi fi
echo "${FIRST_USER_NAME}:${FIRST_USER_PASS}" | chpasswd echo "${FIRST_USER_NAME}:${FIRST_USER_PASS}" | chpasswd
echo "octoprint:$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c20)" | chpasswd echo "octoprint:$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c20)" | chpasswd

View file

@ -1,8 +1,12 @@
#!/bin/bash -e #!/bin/bash -e
install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service install -m 644 files/octoprint.service ${ROOTFS_DIR}/etc/systemd/system/octoprint.service
install -m 644 files/first-time.service ${ROOTFS_DIR}/etc/systemd/system/first-time.service
install -m 755 files/first-time.sh ${ROOTFS_DIR}/usr/local/bin/first-time.sh
on_chroot << EOF on_chroot << EOF
systemctl set-default multi-user.target
systemctl enable first-time
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

@ -0,0 +1,10 @@
[Unit]
Description=Raspberry Pi first time setup
[Service]
Type=simple
ExecStart=/usr/local/bin/first-time.sh
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,52 @@
#!/bin/bash
change_password () {
local PASSWORD="$(whiptail --title "Change Password" --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" --msgbox "That password sucks. Please use a different one :)" 10 50
change_password
return 0
fi
if [[ "$(whiptail --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 "$PASSWORD\n$PASSWORD" | passwd pi
else
whiptail --title "Change Password" --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 "$OCTOPASS\n$OCTOPASS" | passwd octoprint
local ROOTPASS="$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c20)"
echo -e "$ROOTPASS\n$ROOTPASS" | passwd root
unset OCTOPASS
unset ROOTPASS
unset PASSWORD
}
service_select () {
local SERVICE_MENU=$(whiptail --title "Select services" --checklist "Enable/disable services" 0 0 0 \
"OctoPrint" "" ON \
"GUI" "" ON \
"SSH" "" OFF 3>&1 1>&2 2>&3)
SERVICE_MENU=($SERVICE_MENU)
for i in "${SERVICE_MENU[@]}"; do
case $i in
"OctoPrint") systemctl enable octoprint ;;
"GUI") systemctl set-default graphical.target ;;
"SSH")
ssh-keygen -A
systemctl enable sshd ;;
esac
done
}
nmtui
configure_password || exit 1
service_select || exit 1
systemctl disable first-time || exit 1
rm /etc/systemd/system/first-time.service
reboot