summaryrefslogtreecommitdiff
path: root/initramfs-tools/scripts/samizdat
blob: 89e39ef2eb89fb3c869bfa6e286b987c5b3fcb26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
klogd -c1 # TODO: This should be even earlier.  Can it go on the kernel command line?

. common.sh
debug_log samizdat.init

my_configure_networking()
{
    configure_networking > /dev/tty1
    if [ -e /run/net-"$DEVICE".conf ]
    then
        . /run/net-"$DEVICE".conf
        printf 'Note: configure_networking: ROOTSERVER=%s\n', "$ROOTSERVER" >&2
    else
        false
    fi
}

read_nbd_variables()
{
    NBDCLIENT=:
    . /scripts/local-top/nbd
    unset NBDCLIENT
}

run_nbd_client()
{
    (debug_log samizdat.nbd
     read_nbd_variables
     for DEVNAME in /dev/nbd0 /dev/nbd1
     do
         case "$DEVNAME" in
             /dev/nbd0) nbdpath=samizdat.btrfs ;;
             /dev/nbd1) nbdpath=samizdat.patch.btrfs ;;
         esac
         nbd-client $nbdsrv -N $nbdpath $nbdport $DEVNAME -swap -persist -systemd-mark
     done
     bootdone nbd-script)
}

write_resolv_dot_conf()
{

    if [ "$IPV4DNS0" != '0.0.0.0' ]; then
        printf '%s\n' "$IPV4DNS0" "$IPV4DNS1" |
            sed -e '/^0.0.0.0$/d; s/^/nameserver /' > /root/etc/resolv.conf
    fi
}

mountroot()
{
  openvt -c 13 sh

  mkfifo "$MENUFIFO"

  if [ "$nbdroot" ]; then
      my_configure_networking
      run_nbd_client

      wait_for_gnupghome_tar
      (sleep 5; echo ) &
      (. common.sh && . btrfs-create.sh && init_gpg)
  fi

  bootmenu
  samizdat_install_udev_rules
  bootwait samizdat-gpg
  bootwait root-mounted
  write_resolv_dot_conf
  chvt 1
}

wait_for_gnupghome_tar()
{
  [ -e /gnupghome.tar ] && return
  echo -n Waiting to receive GPG keys through the network... > /dev/tty1
  (while ! tftp -g -r gnupghome.tar -l /gnupghome.tar.$$ "$ROOTSERVER" 2>/run/initramfs/samizdat/log/tftp.$$.log; do
    sleep 1;
    echo -n . > /dev/tty1
  done
  mv /gnupghome.tar.$$ /gnupghome.tar)
  echo '  done.' > /dev/tty1
  bootdone gnupg-tar
}

samizdat_restart_udev()
{
  local LOG_DIR=/run/initramfs/samizdat/log
  mkdir -p "$LOG_DIR"
  killall systemd-udevd 2>/dev/null
  /lib/systemd/systemd-udevd --resolve-names=never --debug >$LOG_DIR/udevd-systemd.log 2>&1 &
  udevadm hwdb --update  # rule is not executed by 'udevadm trigger' otherwise.  not sure why
}