summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--initramfs-tools/scripts/samizdat11
-rw-r--r--src/dnsmasq-dhcp-script.sh64
-rwxr-xr-xsrc/keygen.sh8
4 files changed, 86 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index bcf851b..893216b 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ prefix?=/usr/local
2 2
3all: samizdat-paths.sh 3all: samizdat-paths.sh
4 4
5bin_programs=$(addprefix src/, xorriso-usb.sh btrfs-functions.sh btrfs-receive-root.sh btrfs-send-root.sh var.sh grub-efi.sh keygen.sh initrd.sh qemu.sh btarfs) samizdat-paths.sh 5bin_programs=$(addprefix src/, xorriso-usb.sh btrfs-functions.sh btrfs-receive-root.sh btrfs-send-root.sh var.sh grub-efi.sh keygen.sh initrd.sh qemu.sh btarfs dnsmasq-dhcp-script.sh) samizdat-paths.sh
6 6
7# TODO: compile these here 7# TODO: compile these here
8samizdat_execs=$(addprefix /home/d/src/samizdat/, wait_for_files samizdat-pinentry dynmenu src/samizdat-password-agent src/samizdat-gpg-agent) 8samizdat_execs=$(addprefix /home/d/src/samizdat/, wait_for_files samizdat-pinentry dynmenu src/samizdat-password-agent src/samizdat-gpg-agent)
@@ -10,6 +10,8 @@ samizdat_execs=$(addprefix /home/d/src/samizdat/, wait_for_files samizdat-pinent
10initrd_files:=$(wildcard src/initrd/*) 10initrd_files:=$(wildcard src/initrd/*)
11initramfs_conf_files:=$(wildcard initramfs-tools/*) 11initramfs_conf_files:=$(wildcard initramfs-tools/*)
12 12
13isolinux_files:=$(wildcard isolinux/*)
14
13.PHONY: samizdat-paths.sh 15.PHONY: samizdat-paths.sh
14samizdat-paths.sh: src/samizdat-paths.in 16samizdat-paths.sh: src/samizdat-paths.in
15 sed -e "s?PREFIX?$(prefix)?g" $< > $@ 17 sed -e "s?PREFIX?$(prefix)?g" $< > $@
@@ -25,3 +27,4 @@ install:
25 mkdir -p ${instdir}${samizdat_linux_dir} 27 mkdir -p ${instdir}${samizdat_linux_dir}
26 cp -r ${initrd_files} ${instdir}${samizdat_initrd_files_dir} 28 cp -r ${initrd_files} ${instdir}${samizdat_initrd_files_dir}
27 cp -r ${initramfs_conf_files} ${instdir}${samizdat_initramfs_conf_dir} 29 cp -r ${initramfs_conf_files} ${instdir}${samizdat_initramfs_conf_dir}
30 cp -r ${isolinux_files} ${instdir}${samizdat_isolinux_dir}
diff --git a/initramfs-tools/scripts/samizdat b/initramfs-tools/scripts/samizdat
index 232e3ac..374979f 100644
--- a/initramfs-tools/scripts/samizdat
+++ b/initramfs-tools/scripts/samizdat
@@ -7,11 +7,22 @@ mountroot()
7 samizdat_install_udev_rules 7 samizdat_install_udev_rules
8 mkfifo "$MENUFIFO" 8 mkfifo "$MENUFIFO"
9 sh /scripts/local-top/nbd & # I guess this isn't getting called otherwise? 9 sh /scripts/local-top/nbd & # I guess this isn't getting called otherwise?
10 wait_for_gnupghome_tar
10 bootmenu 11 bootmenu
11 bootwait root-mounted 12 bootwait root-mounted
12 chvt 1 13 chvt 1
13} 14}
14 15
16wait_for_gnupghome_tar()
17{
18 [ -e /gnupghome.tar ] && return
19 [ "${nbdroot%%,*}" ] || return
20 (while ! tftp -g -r gnupghome.tar -l /gnupghome.tar.$$ ${nbdroot%%,*}; do
21 sleep 1;
22 done
23 mv /gnupghome.tar.$$ /gnupghome.tar)
24}
25
15samizdat_install_udev_rules() 26samizdat_install_udev_rules()
16{ 27{
17 mkdir -p /etc/udev/rules.d 28 mkdir -p /etc/udev/rules.d
diff --git a/src/dnsmasq-dhcp-script.sh b/src/dnsmasq-dhcp-script.sh
new file mode 100644
index 0000000..167d229
--- /dev/null
+++ b/src/dnsmasq-dhcp-script.sh
@@ -0,0 +1,64 @@
1#!/bin/sh
2. samizdat-paths.sh
3TFTP_ROOT=${samizdat_isolinux_dir}
4[ "$1 $4" = "tftp ${TFTP_ROOT}/linux/vmlinuz" ] || exit
5# $2 is the length of the file
6CLIENT_IP=$3
7
8# dnsmasq clears the environment. kiki needs at least $HOME
9export USER=root
10export MAIL=/var/mail/root
11export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
12export LANG=en_US.UTF-8
13export HOME=/root
14export LANGUAGE=en_US:en
15export LOGNAME=root
16
17debug()
18{
19 LOGDIR=/var/log/dnsmasq-dhcp-script
20 mkdir -p "$LOGDIR"
21 exec > "$LOGDIR/$$.log" 2>&1
22 set -x
23}
24
25new_child()
26{
27 child_dir=$samizdat_child_dir/child.$$
28 if [ -d "$child_dir" ]; then
29 rmdir "$child_dir" || exit 1
30 fi
31
32 sh -x "$(which keygen.sh)" "$child_dir" || return
33 tar --exclude '*~' -zcf "$child_dir"/gnupghome.tar -C "$child_dir"/root/.gnupg . || return
34
35 tftp_dir="${TFTP_ROOT}"/"$CLIENT_IP"
36 if [ ! -d "$tftp_dir" ]; then
37 ATOMIC=y
38 dest_dir="$tftp_dir"~
39
40 # DNSMASQ DOCUMENTATION IS WRONG OMFG
41 # Otherwise this symlink farm would be unnecessary
42
43 mkdir -p "$dest_dir"
44 (cd "$dest_dir" && ln -sf ../* . && rm "$CLIENT_IP"~) || return
45 else
46 dest_dir="$tftp_dir"
47 fi
48
49 chown dnsmasq "$child_dir" "$child_dir"/gnupghome.tar
50 ln -sf "$child_dir"/gnupghome.tar "$dest_dir"/
51
52 if [ "$ATOMIC" ]; then
53 mv -T "$dest_dir" "$tftp_dir"
54 fi
55}
56
57cleanup_after_fail()
58{
59 umount "$child_dir"
60 rmdir "$child_dir"
61}
62
63debug
64(new_child || cleanup_after_fail) &
diff --git a/src/keygen.sh b/src/keygen.sh
index 4c13e67..5b48512 100755
--- a/src/keygen.sh
+++ b/src/keygen.sh
@@ -60,13 +60,19 @@ doublecheck()
60 60
61silent() 61silent()
62{ 62{
63 case "$-" in
64 *x*) return ;;
65 esac
66 SILENT=y
63 exec 3>&1 4>&2 67 exec 3>&1 4>&2
64 exec >/dev/null 2>&1 68 exec >/dev/null 2>&1
65} 69}
66 70
67noisy() 71noisy()
68{ 72{
69 exec >&3 2>&1 73 if [ "$SILENT" ]; then
74 exec >&3 2>&1
75 fi
70} 76}
71 77
72new_child() 78new_child()