From 63f5365f3c59d3a757a3184e254fecc936a1fd56 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 31 Oct 2018 15:14:38 +0100 Subject: [PATCH] introduce config file tree --- .gitignore | 4 ++++ Makefile | 21 ++++++++++++++++++--- config.example | 3 +++ cmdline.txt => files/boot/cmdline.txt | 0 config.txt => files/boot/config.txt | 0 files/etc/hostname | 1 + files/etc/network/interfaces.d/wired | 3 +++ wifi.tmpl | 7 +++++++ 8 files changed, 36 insertions(+), 3 deletions(-) rename cmdline.txt => files/boot/cmdline.txt (100%) rename config.txt => files/boot/config.txt (100%) create mode 100644 files/etc/hostname create mode 100644 files/etc/network/interfaces.d/wired create mode 100644 wifi.tmpl diff --git a/.gitignore b/.gitignore index 28f18a8..d5b546a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ raspi_root/ raspi.img config.mk +files/root/.ssh/authorized_keys +files/etc/network/interfaces/wifi +id_rsa +id_rsa.pub diff --git a/Makefile b/Makefile index 4338e25..74ef722 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,10 @@ endef PACKAGES := apt apt-transport-https bluez bluez-firmware btrfs-tools busybox-static bzip2 ca-certificates cron deborphan firmware-atheros firmware-brcm80211 firmware-libertas firmware-linux-free firmware-misc-nonfree firmware-realtek gzip htop ifupdown init iptables iputils-ping irqbalance isc-dhcp-client less libraspberrypi-bin libraspberrypi0 make net-tools nmap ntpdate openssh-client openssh-server p7zip-full raspberrypi-bootloader raspberrypi-kernel rsync ssh sshfs sudo systemd traceroute unace unrar-free unzip vim wget wireless-tools wpasupplicant xz-utils zip +# Do not change, only override in config.mk +WIFI-SSID = +WIFI-PASS = + include config.mk config.mk: config.example @@ -27,7 +31,6 @@ raspi_root/: raspi_root .FORCE printf '${SOURCES}' >$@/etc/apt/sources.list -chroot "$@" apt-key add - <./raspberrypi-archive-keyring.gpg -cp /etc/resolv.conf "$@etc/" - cp -u cmdline.txt config.txt "$@boot/" -chroot "$@" sh -c 'apt-mark showmanual |xargs apt-mark auto' -chroot "$@" apt-get update chroot "$@" ln -sf /bin/true /usr/local/sbin/invoke-rc.d @@ -38,7 +41,19 @@ raspi_root/: raspi_root .FORCE chroot "$@" apt-get clean touch "$@" -raspi.img: raspi_root/ partitions +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};;' <'$<' >'$@' + +files/root/.ssh/authorized_keys: id_rsa.pub + mkdir -p files/root/.ssh/ + cat '$<' >>'$@' + chmod 700 files/root/ files/root/.ssh/ + chmod 600 '$@' + +raspi.img: raspi_root/ files/ partitions files/root/.ssh/authorized_keys files/etc/network/interfaces.d/wifi -rmdir "$@.mnt" mkdir "$@.mnt" # fail receipe if dir is nonempty dd bs=1M count=0 seek=1024 of="$@" # set up sparse file @@ -54,7 +69,7 @@ raspi.img: raspi_root/ partitions size=$$(sfdisk --dump "$$image" |sed -rn 's;^.*size= *([0-9]+),.*type=c;\1;p'); \ losetup -o $$((start * 512)) --sizelimit $$((size * 512)) "$${lo}" "$$image" && \ mkfs.fat -F 32 -n boot "$$lo" && mount -t vfat "$$lo" "$@.mnt/boot"; - cp -a "$<." "$@.mnt/" + cp -a "raspi_root/." "files/." "$@.mnt/" umount "$@.mnt/boot/" "$@.mnt/" losetup -a |sed -rn '/$@/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d losetup -a |sed -rn '/$@/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d diff --git a/config.example b/config.example index b38bde1..345d2f4 100644 --- a/config.example +++ b/config.example @@ -8,3 +8,6 @@ endef BOOTSTRAP := http://raspbian.raspberrypi.org/raspbian # PACKAGES := ${PACKAGES} foo bar ... additional packages + +# WIFI-SSID = +# WIFI-PASS = diff --git a/cmdline.txt b/files/boot/cmdline.txt similarity index 100% rename from cmdline.txt rename to files/boot/cmdline.txt diff --git a/config.txt b/files/boot/config.txt similarity index 100% rename from config.txt rename to files/boot/config.txt diff --git a/files/etc/hostname b/files/etc/hostname new file mode 100644 index 0000000..09277c9 --- /dev/null +++ b/files/etc/hostname @@ -0,0 +1 @@ +Oktopus diff --git a/files/etc/network/interfaces.d/wired b/files/etc/network/interfaces.d/wired new file mode 100644 index 0000000..768218b --- /dev/null +++ b/files/etc/network/interfaces.d/wired @@ -0,0 +1,3 @@ +auto eth0 +allow-hotplug eth0 +iface eth0 inet dhcp diff --git a/wifi.tmpl b/wifi.tmpl new file mode 100644 index 0000000..ec196f3 --- /dev/null +++ b/wifi.tmpl @@ -0,0 +1,7 @@ +auto wlan0 +allow-hotplug wlan0 + +iface wlan0 inet dhcp + wpa-ssid "#WIFI-SSID#" + wpa-psk "#WIFI-PASS#" + hostname "Oktopus" -- 2.39.2