59 lines
1.1 KiB
Bash
Executable file
59 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
flash_sd () {
|
|
img_file=$1
|
|
sd_card=$2
|
|
echo "Flashing $img_file to $sd_card ..."
|
|
xzcat --stdout $img_file | dd of=$sd_card status=progress
|
|
}
|
|
|
|
enlarge_partition () {
|
|
device=$1
|
|
partnr=2
|
|
echo "Resize main partition"
|
|
sfdisk --backup $device -N $partnr << EOF
|
|
,+
|
|
print
|
|
EOF
|
|
echo "Resize filesystem"
|
|
e2fsck -f "$device"p$partnr
|
|
resize2fs -p "$device"p$partnr
|
|
}
|
|
|
|
mount_temporary () {
|
|
partnr=$1
|
|
temp_mnt_point=$(mktemp -d)
|
|
mount "$SD_CARD"p"$partnr" $temp_mnt_point
|
|
echo $temp_mnt_point
|
|
}
|
|
|
|
unmount_temporary () {
|
|
handle=$1
|
|
umount $1
|
|
rmdir $1
|
|
}
|
|
|
|
provision_network () {
|
|
mnt_point=$1
|
|
|
|
echo "Provision network"
|
|
cat > $mnt_handle/network-config <<EOF
|
|
network:
|
|
version: 2
|
|
ethernets:
|
|
eth0:
|
|
addresses: [$NET_ADDR]
|
|
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
|
|
|
|
flash_sd "$IMG_FILE" "$SD_CARD"
|
|
enlarge_partition "$SD_CARD"
|
|
mnt_handle=$(mount_temporary "1")
|
|
|
|
provision_network $mnt_handle
|
|
|
|
unmount_temporary $mnt_handle
|