]> git.plutz.net Git - blast/blob - modules/default.mk
e8e4fd1ed3dcdfd2b9869bd55219db3361c66a9d
[blast] / modules / default.mk
1 ifdef imagesize
2   ROOT_MB := $(shell printf '%i\n' "$$(( ${imagesize} - ${BOOT_MB} - 3 ))")
3 endif
4
5 PACKAGES += btrfs-progs bzip2 ca-certificates cron deborphan firmware-linux-free gzip htop ifupdown iputils-ping irqbalance isc-dhcp-client less make net-tools nmap ntpdate openssh-client psmisc rsync sshfs sudo traceroute unzip vim wget wireless-tools wpasupplicant xz-utils zip
6
7 ifdef packages
8   PACKAGES += $(subst ${comma_},${space_},${packages})
9 endif
10
11 export DEBCONF RPICONFIG
12
13 define DEBCONF :=
14 ${DEBCONF}
15
16 keyboard-configuration  keyboard-configuration/model    select  Generic 105-key (Intl) PC
17 keyboard-configuration  keyboard-configuration/variant  select  English (US) - English (Macintosh)
18 endef
19
20 ifndef rpivmem
21   rpivmem := 128
22 endif
23
24 define RPICONFIG :=
25 ${RPICONFIG}
26
27 dtoverlay=vc4-fkms-v3d,cma-${rpivmem}
28 endef
29
30 .PHONY: _debconf_selections _raspberry_config _keyboard
31 _install: _debconf_selections
32 _debconf_selections: ${SYSROOT}
33         printf '%s\n' "$${DEBCONF}" |chroot "$${SYSROOT}" debconf-set-selections
34
35 ifdef keyboard
36   _config: _keyboard
37 endif
38 _keyboard: ${CFGROOT}
39         -sed -Ei 's;^XKBLAYOUT=.*$$;XKBLAYOUT="${keyboard}";;' "$${CFGROOT}/etc/default/keyboard"
40
41 ifdef raspi
42   _config: _raspberry_config _raspberry_initrd
43 endif
44
45 _raspberry_config: ${CFGROOT}
46         printf '%s\n' "$${RPICONFIG}" >>"$${CFGROOT}/boot/config.txt"
47
48 _raspberry_initrd: ${CFGROOT}
49         printf '${fstype}\n' >>"$${CFGROOT}/etc/initramfs-tools/modules"
50         k="$$(printf '%s\n' "$${CFGROOT}"/lib/modules/* |sed 's;^.*/;;; /-/d')"; \
51         [ "${kernel}" ] && k="${kernel}"; \
52         chroot $${CFGROOT} update-initramfs -c -k "$${k##*/}"; \
53         printf 'initramfs initrd.img-%s\n' "$${k##*/}" >>"$${CFGROOT}/boot/config.txt"
54
55 .PHONY: _timezone _locales
56
57 ifdef timezone
58   export timezone
59   PACKAGES += tzdata
60   _config: _timezone
61 endif
62
63 ifdef locales
64   PACKAGES += locales
65   _config: _locales
66 endif
67
68 _timezone: ${CFGROOT}
69         printf '%s\n' "$${timezone}" >"$${CFGROOT}/etc/timezone"
70         ln -sf /usr/share/zoneinfo/"$${timezone}" "$${CFGROOT}/etc/localtime"
71
72 _locales: ${CFGROOT}
73         for l in $(subst ${comma_},${space_},${locales}); do \
74                 printf '%s %s\n' "$${l}" "$${l#*.}"; \
75         done >"$${CFGROOT}/etc/locale.gen"
76         printf 'LANG=%s\n' "$(firstword $(subst ${comma_},${space_},${locales}))" >"$${CFGROOT}/etc/default/locale"
77         chroot "$${CFGROOT}" locale-gen
78
79 .PHONY: _rootpass _users _hostname
80
81 ifdef rootpass
82   export rootpass
83   _config: _rootpass
84 endif
85
86 ifdef rootkey
87   export rootkey
88   _config: _rootkey
89 endif
90
91 ifdef users
92   _config: _users
93 endif
94
95 ifdef hostname
96   export hostname
97   _config: _hostname
98 endif
99
100 _rootpass: ${CFGROOT}
101         chroot "$${CFGROOT}" usermod -p "$$(openssl passwd "$${rootpass}")" root
102
103 ${rootkey}.pub:
104         [ -f "$@" ] || ssh-keygen -N '' -f "$${rootkey}"
105
106 _rootkey: ${CFGROOT} ${rootkey}.pub
107         mkdir -m 700 "$${CFGROOT}/root/.ssh/"
108         cp "$${rootkey}.pub" "$${CFGROOT}/root/.ssh/authorized_keys"
109
110 _users: ${CFGROOT}
111         for u in $(subst ${comma_},${space_},${users}); do \
112                 chroot "$${CFGROOT}" useradd -s /bin/bash -p "$$(openssl passwd "")" "$$u"; \
113         done
114
115 _hostname: ${CFGROOT}
116         printf '%s\n' "$${hostname}" >"$${CFGROOT}/etc/hostname"
117         sed -Ei "s;^127\.0\.0\.1.*$$;&  $${hostname};" "$${CFGROOT}/etc/hosts"
118
119 .PHONY: _systemd_timeout
120 _config: _systemd_timeout
121 _systemd_timeout: ${CFGROOT}
122         mkdir -p "$${CFGROOT}/etc/systemd"
123         printf 'DefaultTimeout%sSec=%s\n' Start 10s Stop 10s >>"$${CFGROOT}/etc/systemd/system.conf"
124
125 ifdef wifi
126   _config: ${CFGROOT}/etc/network/interfaces.d/wifi
127   ifdef wifipass
128     export wifi wifipass
129     ${CFGROOT}/etc/network/interfaces.d/wifi: ${CFGROOT}
130         printf 'auto wlan0\nallow-hotplug wlan0\n\niface wlan0 inet dhcp\n' >$@
131         printf '  wpa-ssid "%s"\n  wpa-psk "%s"\n' "$$wifi" "$$wifipass" >>$@
132   else
133     export wifi
134     ${CFGROOT}/etc/network/interfaces.d/wifi: ${CFGROOT}
135         printf 'auto wlan0\nallow-hotplug wlan0\n\niface wlan0 inet dhcp\n' >$@
136         printf '  wireless-essid "%s"\n' "$$wifi" >>$@
137   endif
138 endif