-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildscript.sh
executable file
·39 lines (33 loc) · 1.02 KB
/
buildscript.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env sh
set -e
echo "Downloading the raspios zip"
filename=$(basename $(wget --no-clobber --content-disposition "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" 2>&1 | grep "Location: " | cut -d' ' -f2 ))
echo "Extracting the image"
unzip -n $filename > /dev/null
echo "Setting up loopdevice"
mkdir -p temp
imagename="$(echo $filename | cut -f1 -d'.').img"
lodevice=$(losetup -f)
losetup -fP $imagename
mount "${lodevice}p2" temp
mount "${lodevice}p1" temp/boot
echo "Patching image to enable ssh"
touch temp/boot/ssh
mkdir -p temp/home/pi/.ssh
if [ -e keys/*.pub ]; then
echo "Adding provided keys to the image"
for key in keys/*.pub; do cat $key >> temp/home/pi/.ssh/authorized_keys; done
echo "PasswordAuthentication no" >> temp/etc/ssh/sshd_config
else
echo "No keys were given"
fi
if [ -e wpa_supplicant.conf ]
then
echo "Patching image to enable wpa"
cp wpa_supplicant.conf temp/boot/wpa_supplicant.conf
fi
echo "Cleaning up"
umount temp/boot
umount temp
rmdir temp
losetup -d $lodevice