feat: provision user

This commit is contained in:
Laborratte 5 2026-03-26 11:12:23 +01:00
parent 8f150a20ef
commit 27ba74885f
Signed by: Laborratte5
GPG key ID: 3A30072E35202C02

View file

@ -46,14 +46,54 @@ network:
EOF
}
provision_user () {
mnt_point=$1
echo "Provision user"
if [ -f $ssh_key ]; then
# Load key from file
echo "Loading ssh key from file $ssh_key"
ssh_key=$(<$ssh_key)
fi
cat > $mnt_point/user-data <<EOF
#cloud-config
hostname: raspberry-pi
manage_etc_hosts: true
timezone: Europe/Berlin
package_update: true
package_upgrade: true
enable_ssh: true
users:
- name: $username
group: users,adm,dialout,audio,netdev,video,plugdev,cdrom,games,input,gpio,spi,i2c,render,sudo
shell: /bin/bash
lock_passwd: false
plain_text_password: $userpw
sudo: ALL=(ALL) ALL:ALL
ssh_authorized_keys:
- $ssh_key
EOF
}
read -e -p "Compressed Image file: " IMG_FILE
read -e -p "SD Card: " SD_CARD
read -e -p "IP-Address with prefix (comma separated): " NET_ADDR
read -e -p "Username: " username
read -s -p "Password: " userpw
echo
read -e -p "SSH-Key: " ssh_key
flash_sd "$IMG_FILE" "$SD_CARD"
enlarge_partition "$SD_CARD"
mnt_handle=$(mount_temporary "1")
provision_network $mnt_handle
provision_user $mnt_handle
unmount_temporary $mnt_handle