summaryrefslogtreecommitdiff
path: root/initramfs-tools/scripts/samizdat
blob: ddcb64c0fff355f03e6b81d63bb70a69e032226e (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
#!/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
}

mountroot()
{
  openvt -c 13 sh

  mkfifo "$MENUFIFO"

  if [ "$nbdroot" ]; then
      my_configure_networking

      (debug_log samizdat.nbd
       . /scripts/local-top/nbd
      bootdone nbd-script)

      wait_for_gnupghome_tar
  fi

  bootmenu
  samizdat_install_udev_rules
  bootwait samizdat-gpg
  bootwait root-mounted

  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
  chvt 1
}

cdrom_has_keys()
{
    [ ! "$BOOTIF" ] || return
    bootwait samizdat-cdrom
    [ -d /cdrom/gnupghome ]
}

wait_for_gnupghome_tar()
{
  [ -e /gnupghome.tar ] && return
  echo -n Waiting to receive GPG keys through the network... > /dev/tty1
  my_configure_networking
  (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
  (sleep 5; echo ) &
  (. common.sh && . btrfs-create.sh && init_gpg)
}

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
}