PACKAGES := apt bluez bluez-firmware bluez-tools btrfs-tools busybox-static bzip2 ca-certificates cron debian-archive-keyring deborphan firmware-brcm80211 firmware-linux-free firmware-misc-nonfree gzip htop ifupdown init iputils-ping irqbalance isc-dhcp-client less libraspberrypi-bin libraspberrypi0 make net-tools nmap ntpdate openssh-client openssh-server pi-bluetooth psmisc raspberrypi-bootloader raspberrypi-kernel rsync ssh sshfs sudo systemd traceroute unzip vim wget wireless-tools wpasupplicant xz-utils zip
-# Do not change, only override in config.mk
-WIFI-SSID =
-WIFI-PASS =
-
IMGFILE = raspi.img
config.mk: config.example
cp -n "$<" "$@"
include config.mk
-.PHONY: imgfile imgmount root_copy norecommends apt_keys
+.PHONY: imgfile imgmount root_copy norecommends apt_keys wifi_cfg ssh_key
+
export SOURCES
+export WIFI_CFG
raspi_root:
btrfs subvolume create "$@" || mkdir "$@"
chroot "$@" rm /usr/local/sbin/invoke-rc.d
touch "$@"
-id_rsa.pub:
- ssh-keygen -b 2048 -t rsa -N '' -f id_rsa
-
-files/etc/network/interfaces.d/wifi: wifi.tmpl
- sed 's;#WIFI-SSID#;${WIFI-SSID};; s;#WIFI-PASS#;${WIFI-PASS};;' <'$<' >'$@'
- chmod 644 '$@'
-
-files/root/.ssh/authorized_keys: id_rsa.pub
- mkdir -p files/root/.ssh/
- cat '$<' >>'$@'
- chmod 700 files/root/ files/root/.ssh/
- chmod 600 '$@'
-
imgfile: raspi_root/ # do not set up image file before chroot
imgfile: partitions
dd bs=1M count=0 seek=1280 of="${IMGFILE}" # set up sparse file
losetup -o $$((start * 512)) --sizelimit $$((size * 512)) "$${lo}" "$$image" && \
mkfs.fat -F 32 -n boot "$$lo" && mount -t vfat "$$lo" "$@/boot";
-root_copy: files/root/.ssh/authorized_keys files/etc/network/interfaces.d/wifi
root_copy: imgmount raspi_root/ files/
cp -a "raspi_root/." "files/." "$</"
-${IMGFILE}: imgmount root_copy
+id_rsa.pub:
+ ssh-keygen -b 2048 -t rsa -N '' -f id_rsa
+
+ssh_key: imgmount id_rsa.pub
+ mkdir -p "$</root/.ssh/"
+ cat id_rsa.pub >>"$</root/.ssh/authorized_keys"
+ chmod 700 "$</root" "$</root/.ssh"
+ chmod 600 "$</root/.ssh/authorized_keys"
+
+wifi_cfg: imgmount
+ printf '%s\n' "$$WIFI_CFG" >"$</etc/network/interfaces.d/wifi"
+ chmod 644 "$</etc/network/interfaces.d/wifi"
+ chroot "$<" systemctl disable systemd-networkd-wait-online.service
+
+${IMGFILE}: imgmount root_copy wifi_cfg ssh_key
umount "$</boot/" "$</"
losetup -a |sed -En '/${IMGFILE}/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d
losetup -a |sed -En '/${IMGFILE}/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d