]> git.plutz.net Git - rpi_small/blob - Makefile
typo for boot partition
[rpi_small] / Makefile
1 .FORCE:
2
3 BOOTSTRAP = http://raspbian.raspberrypi.org/raspbian
4
5 define SOURCES = 
6 deb     http://raspbian.raspberrypi.org/raspbian stretch main non-free firmware rpi\n\
7 deb     http://archive.raspberrypi.org/debian stretch main\n
8 endef
9
10 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 rpi-update rsync ssh sshfs sudo systemd traceroute unace unrar-free unzip vim wget wireless-tools wpasupplicant xz-utils zip
11
12 # Do not change, only override in config.mk
13 WIFI-SSID = 
14 WIFI-PASS = 
15
16 include config.mk
17
18 config.mk: config.example
19         cp -n "$<" "$@"
20
21 raspi_root:
22         btrfs subvolume create "$@" || mkdir "$@"
23         mkdir -p "$@/usr/bin"
24         chmod 755 -R "$@/"
25         cp -p "/usr/bin/qemu-arm-static" "$@/usr/bin/"
26         debootstrap --keyring=./raspbian-archive-keyring.gpg \
27                 --arch=armhf --variant=minbase \
28                 stretch "$@/" "${BOOTSTRAP}"
29
30 raspi_root/: raspi_root .FORCE
31         printf '${SOURCES}' >$@/etc/apt/sources.list
32         -chroot "$@" apt-key add - <./raspberrypi-archive-keyring.gpg
33         -cp /etc/resolv.conf "$@etc/"
34         -chroot "$@" sh -c 'apt-mark showmanual |xargs apt-mark auto'
35         -chroot "$@" apt-get update
36         chroot "$@" ln -sf /bin/true /usr/local/sbin/invoke-rc.d
37         chroot "$@" apt-get --yes install ${PACKAGES}
38         chroot "$@" apt-get --yes --auto-remove purge
39         chroot "$@" apt-get --yes --auto-remove upgrade
40         chroot "$@" rpi-update
41         chroot "$@" rm /usr/local/sbin/invoke-rc.d
42         chroot "$@" apt-get clean
43         touch "$@"
44
45 id_rsa.pub:
46         ssh-keygen -b 2048 -t rsa -N '' -f id_rsa
47
48 files/etc/network/interfaces.d/wifi: wifi.tmpl
49         sed 's;#WIFI-SSID#;${WIFI-SSID};; s;#WIFI-PASS#;${WIFI-PASS};;' <'$<' >'$@'
50         chmod 644 '$@'
51
52 files/root/.ssh/authorized_keys: id_rsa.pub
53         mkdir -p files/root/.ssh/
54         cat '$<' >>'$@'
55         chmod 700 files/root/ files/root/.ssh/
56         chmod 600 '$@'
57
58 raspi.img: raspi_root/ files/ partitions files/root/.ssh/authorized_keys files/etc/network/interfaces.d/wifi
59         -rmdir "$@.mnt"
60         mkdir "$@.mnt"  # fail receipe if dir is nonempty
61         dd bs=1M count=0 seek=1024 of="$@"  # set up sparse file
62         sfdisk "$@" <partitions
63         lo=$$(losetup -f); image='$@'; \
64         start=$$(sfdisk --dump "$$image" |sed -rn 's;^.*start= *([0-9]+),.*type=83;\1;p'); \
65         size=$$(sfdisk --dump "$$image" |sed -rn 's;^.*size= *([0-9]+),.*type=83;\1;p'); \
66         losetup -o $$((start * 512)) --sizelimit $$((size * 512)) "$${lo}" "$$image" && \
67         mkfs.ext4 -F "$$lo" && mount -t ext4 "$$lo" "$@.mnt/";
68         mkdir "$@.mnt/boot"
69         lo=$$(losetup -f); image='$@'; \
70         start=$$(sfdisk --dump "$$image" |sed -rn 's;^.*start= *([0-9]+),.*type=c;\1;p'); \
71         size=$$(sfdisk --dump "$$image" |sed -rn 's;^.*size= *([0-9]+),.*type=c;\1;p'); \
72         losetup -o $$((start * 512)) --sizelimit $$((size * 512)) "$${lo}" "$$image" && \
73         mkfs.fat -F 32 -n boot "$$lo" && mount -t vfat "$$lo" "$@.mnt/boot";
74         cp -a "raspi_root/." "files/." "$@.mnt/"
75         umount "$@.mnt/boot/" "$@.mnt/"
76         losetup -a |sed -rn '/$@/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d
77         losetup -a |sed -rn '/$@/{s;^([^:]+):.*$$;\1;p;q}' |xargs losetup -d
78         rmdir "$@.mnt/"