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 97 98 99 100 101 102 103 104 105 106 107
|
# vim: filetype=sh
generate_fstab()
{
layout_dir="$1"
echo "# <file system> <mount point> <type> <options> <dump> <pass>" > etc/fstab
generate_mount_info "$layout_dir" | while read vol_dir mounttype uuid vol_mountpoint
do
echo "UUID=$uuid $vol_mountpoint $mounttype errors=remount-ro 0 1" >> etc/fstab
done
}
generate_hosts_file()
{
cat > /etc/hosts << EOF
127.0.0.1 localhost
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
}
ensure_valid_resolv_conf()
{
status="ok"
# check if resolv.conf is missing
# (we use `stat` and not [ -e [...] ] to avoid trying to
# dereference a broken symlink).
if ! stat "/etc/resolv.conf" >/dev/null 2>&1
then
status="missing"
# check if file is invalid (no 'nameserver' directive)
elif [ -f "/etc/resolv.conf" ]
then
if ! grep -q "^nameserver" /etc/resolv.conf
then
# invalid
rm -f /etc/resolv.conf
status="missing"
fi
fi
# in more complex scenarios (e.g. it is a symlink currently broken
# to /run/systemd/resolve/stub-resolv.conf), we consider the setup
# is OK and/or the user knows what he is doing.
# in any case, we must ensure we have a valid setup during package
# downloads. so we temporarily move the file and replace it with
# an appropriate conf.
if [ "$status" = "ok" ]
then
mv /etc/resolv.conf /etc/resolv.conf.chroot-orig
fi
generate_resolv_conf_file
echo "$status" # return status to caller
}
possibly_restore_resolv_conf()
{
if stat "/etc/resolv.conf.chroot-orig" >/dev/null 2>&1
then
rm -f /etc/resolv.conf
mv /etc/resolv.conf.chroot-orig /etc/resolv.conf
fi
}
generate_resolv_conf_file()
{
# note: this generated file may be overriden later in the procedure
# if debootstick has to install one missing package including a DNS
# resolver (e.g. systemd). In any case this file is needed right
# know for the package downloading to succeed.
# We copy the name servers which were used on the host and also add
# a few public ones.
# The one on the host may be '127.0.0.1' (e.g. the host may be running
# a local service, e.g., for caching) which will work when the image
# is being built but not when the target image is booted.
# On the other hand the public nameservers may be unreachable because
# of firewalling.
# That's why we indicate all of them for more robustness.
cat > /etc/resolv.conf << EOF
# the following nameservers are those which were defined
# on the machine where debootstick was run
# ------------------------------------------------------
EOF
grep nameserver /etc/resolv.conf.host >> /etc/resolv.conf
rm /etc/resolv.conf.host
cat >> /etc/resolv.conf << EOF
# the following nameservers are public ones
# ------------------------------------------------------
# cloudflare
nameserver 1.1.1.1
# google
nameserver 8.8.8.8
# opendns
nameserver 208.67.220.220
EOF
}
|