]> git.plutz.net Git - rpi_small/blob - Makefile
include teesock, update test program
[rpi_small] / Makefile
1 #  Generator for Oktopus boot media
2 #  Copyright (C) 2018 Hochschule für Technik und Wirtschaft Berlin
3 #                written by Paul Hänsch <oktopus@plutz.net>
4 #
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU Affero General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU Affero General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Affero General Public License
16 #  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
18 .FORCE:
19
20 BOOTSTRAP = http://raspbian.raspberrypi.org/raspbian
21
22 define SOURCES = 
23 deb     http://raspbian.raspberrypi.org/raspbian stretch main non-free firmware rpi\n\
24 deb     http://archive.raspberrypi.org/debian stretch main\n
25 endef
26
27 PACKAGES := apt bluez bluez-firmware bluez-tools bridge-utils btrfs-tools busybox-static bzip2 ca-certificates cron deborphan dnsmasq firmware-brcm80211 firmware-linux-free firmware-misc-nonfree gzip htop ifupdown init iptables iputils-ping irqbalance isc-dhcp-client less libraspberrypi-bin libraspberrypi0 make net-tools nmap ntpdate openbsd-inetd openssh-client openssh-server pi-bluetooth rpi-update rsync ssh sshfs sudo systemd traceroute unzip vim wget wireless-tools wpasupplicant xz-utils zip
28
29 # Do not change, only override in config.mk
30 WIFI-SSID = 
31 WIFI-PASS = 
32
33 include config.mk
34
35 config.mk: config.example
36         cp -n "$<" "$@"
37
38 raspi_root:
39         btrfs subvolume create "$@" || mkdir "$@"
40         mkdir -p "$@/usr/bin"
41         chmod 755 -R "$@/"
42         cp -p "/usr/bin/qemu-arm-static" "$@/usr/bin/"
43         debootstrap --keyring=./raspbian-archive-keyring.gpg \
44                 --arch=armhf --variant=minbase \
45                 stretch "$@/" "${BOOTSTRAP}"
46
47 raspi_root/: raspi_root .FORCE
48         printf '${SOURCES}' >$@/etc/apt/sources.list
49         -chroot "$@" apt-key add - <./raspberrypi-archive-keyring.gpg
50         -cp /etc/resolv.conf "$@etc/"
51         -chroot "$@" sh -c 'apt-mark showmanual |xargs apt-mark auto'
52         -chroot "$@" apt-get update
53         chroot "$@" ln -sf /bin/true /usr/local/sbin/invoke-rc.d
54         chroot "$@" apt-get --yes install ${PACKAGES}
55         chroot "$@" apt-get --yes --auto-remove purge
56         chroot "$@" apt-get --yes --auto-remove upgrade
57         chroot "$@" rpi-update || [ -f "$@/boot/bootcode.bin" ]
58         -[ -d "$@/boot.bak/" ] && rm -r "$@/boot.bak/"
59         sync
60         chroot "$@" apt-get clean
61         chroot "$@" rm /usr/local/sbin/invoke-rc.d
62         touch "$@"
63
64 id_rsa.pub:
65         ssh-keygen -b 2048 -t rsa -N '' -f id_rsa
66
67 files/etc/network/interfaces.d/wifi: wifi.tmpl
68         sed 's;#WIFI-SSID#;${WIFI-SSID};; s;#WIFI-PASS#;${WIFI-PASS};;' <'$<' >'$@'
69         chmod 644 '$@'
70
71 files/root/.ssh/authorized_keys: id_rsa.pub
72         mkdir -p files/root/.ssh/
73         cat '$<' >>'$@'
74         chmod 700 files/root/ files/root/.ssh/
75         chmod 600 '$@'
76
77 include gummikraken.mk
78 include teesock.mk
79
80 raspi.img: raspi_root/ files/ partitions files/root/.ssh/authorized_keys files/etc/network/interfaces.d/wifi files/srv/gummikraken/ files/usr/local/bin/teesock
81         -rmdir "$@.mnt"
82         mkdir "$@.mnt"  # fail receipe if dir is nonempty
83         dd bs=1M count=0 seek=1792 of="$@"  # set up sparse file
84         sfdisk "$@" <partitions
85         lo=$$(losetup -f); image='$@'; \
86         start=$$(sfdisk --dump "$$image" |sed -rn 's;^.*start= *([0-9]+),.*type=83;\1;p'); \
87         size=$$(sfdisk --dump "$$image" |sed -rn 's;^.*size= *([0-9]+),.*type=83;\1;p'); \
88         losetup -o $$((start * 512)) --sizelimit $$((size * 512)) "$${lo}" "$$image" && \
89         mkfs.ext4 -F "$$lo" && mount -t ext4 "$$lo" "$@.mnt/";
90         mkdir "$@.mnt/boot"
91         lo=$$(losetup -f); image='$@'; \
92         start=$$(sfdisk --dump "$$image" |sed -rn 's;^.*start= *([0-9]+),.*type=c;\1;p'); \
93         size=$$(sfdisk --dump "$$image" |sed -rn 's;^.*size= *([0-9]+),.*type=c;\1;p'); \
94         losetup -o $$((start * 512)) --sizelimit $$((size * 512)) "$${lo}" "$$image" && \
95         mkfs.fat -F 32 -n boot "$$lo" && mount -t vfat "$$lo" "$@.mnt/boot";
96         cp -a "raspi_root/." "files/." "$@.mnt/"
97         umount "$@.mnt/boot/" "$@.mnt/"
98         losetup -a |sed -rn '/$@/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d
99         losetup -a |sed -rn '/$@/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d
100         rmdir "$@.mnt/"