boilerplate
This commit is contained in:
commit
1d15d9b2d7
6 changed files with 99 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
vcpi.img.xz
|
||||||
|
|
9
README.md
Normal file
9
README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
1. Execute the `prepare-image.sh [image]` script as `root` where `[image]` is the url to raspiOS.
|
||||||
|
|
||||||
|
2. Flash the `vcpi.img.xz` with for example Balena Etcher to a SD Card
|
||||||
|
|
||||||
|
3. Boot Rpi on DHCP enabled network. The boot script should run `setup.sh` on first boot.
|
||||||
|
|
||||||
|
4. Login using user: `pi` pass: `vcpi`
|
||||||
|
|
||||||
|
5. Debug the initial setup process with `journalctl -u firstboot`. The `setup.sh` should be automatically renamed to `setup.sh.done` if setup is successful.
|
50
prepare-image.sh
Executable file
50
prepare-image.sh
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
echo "No image name provided"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
#download source
|
||||||
|
curl $1 --output src.img.xz
|
||||||
|
xz -v -T 0 -d src.img.xz
|
||||||
|
|
||||||
|
#setup
|
||||||
|
losetup -P /dev/loop8 src.img
|
||||||
|
mkdir -v /tmp/rpi-img
|
||||||
|
mount /dev/loop8p2 /tmp/rpi-img
|
||||||
|
mount /dev/loop8p1 /tmp/rpi-img/boot
|
||||||
|
|
||||||
|
#enable ssh
|
||||||
|
touch /tmp/rpi-img/boot/ssh
|
||||||
|
cp -v userconf.txt /tmp/rpi-img/boot/userconf
|
||||||
|
|
||||||
|
# pi user keys
|
||||||
|
mkdir /tmp/rpi-img/home/pi/.ssh
|
||||||
|
#echo "" > /tmp/rpi-img/home/pi/.ssh/authorized_keys
|
||||||
|
chown 1000:1000 /tmp/rpi-img/home/pi/.ssh
|
||||||
|
chown 1000:1000 /tmp/rpi-img/home/pi/.ssh/authorized_keys
|
||||||
|
|
||||||
|
#provision scripts
|
||||||
|
cp -v ./src/setup.sh /tmp/rpi-img/root/setup.sh
|
||||||
|
|
||||||
|
#setup autorun on first boot
|
||||||
|
cp -v ./src/firstboot.service /tmp/rpi-img/lib/systemd/system/firstboot.service
|
||||||
|
ln -v -s /lib/systemd/system/firstboot.service /tmp/rpi-img/etc/systemd/system/multi-user.target.wants
|
||||||
|
|
||||||
|
#enable systemd-time-wait-sync
|
||||||
|
ln -v -s /lib/systemd/system/systemd-time-wait-sync.service /tmp/rpi-img/etc/systemd/system/sysinit.target.wants/systemd-time-wait-sync.service
|
||||||
|
|
||||||
|
sync
|
||||||
|
|
||||||
|
#cleanup
|
||||||
|
losetup -d /dev/loop8
|
||||||
|
umount /tmp/rpi-img/boot
|
||||||
|
umount /tmp/rpi-img
|
||||||
|
rmdir -v /tmp/rpi-img
|
||||||
|
|
||||||
|
#write image
|
||||||
|
xz -v -T 0 -z src.img
|
||||||
|
mv -v src.img.xz vcpi.img.xz
|
14
src/firstboot.service
Normal file
14
src/firstboot.service
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
[Unit]
|
||||||
|
Description=FirstBoot
|
||||||
|
Wants=time-sync.target
|
||||||
|
Before=rc-local.service
|
||||||
|
After=network.target time-sync.target apt-daily.service apt-daily-upgrade.service
|
||||||
|
ConditionFileNotEmpty=/root/setup.sh
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/root/setup.sh
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=no
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
23
src/setup.sh
Executable file
23
src/setup.sh
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# upgrade system
|
||||||
|
apt-get update
|
||||||
|
apt-get upgrade -y
|
||||||
|
|
||||||
|
# setup apps
|
||||||
|
apt-get install htop
|
||||||
|
|
||||||
|
# setup udev
|
||||||
|
echo "SUBSYSTEM==\"usb\", ENV{DEVTYPE}==\"usb_device\", MODE=\"0666\"" > /etc/udev/rules.d/50-udev-default.rules
|
||||||
|
|
||||||
|
# setup firewall
|
||||||
|
apt-get install ufw -y
|
||||||
|
ufw allow ssh
|
||||||
|
ufw enable
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
mv /root/setup.sh /root/setup.sh.done
|
||||||
|
chmod -x /root/setup.sh.done
|
||||||
|
|
||||||
|
echo "done :)"
|
||||||
|
exit 0
|
1
userconf.txt
Normal file
1
userconf.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pi:$6$J3VR90uJ/TxGhcPf$OzVHJSqmGWsJlDFxCumcwftgv2okaHZlbrTyu5MX0YXKrDrVxMxsexbroXUt5CkSu0xedQAcfvHm5CDpkiiDu0
|
Loading…
Reference in a new issue