summaryrefslogtreecommitdiffstats
path: root/src/initramfs/stage3-stuff/bin/dhcpmkconfig
blob: fa01db75b85f1c34cf03c514f22c2ca6b771ceb3 (plain) (blame)
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
#!/bin/sh
# Copyright (c) 2003..2006 - RZ Uni Freiburg
# Copyright (c) 2006..2010 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found under http://openslx.org
#
# Universal (distro independent) IP configuration writer for busybox udhcpc 
# applet used within OpenSLX initramfs. The result is written to the 
# /etc/initramfs-setup file

# script started twice by udhcpc, quit fast if no ip configuration present
[ -z "$ip" ] && exit 0

# heavy debugging output in level 3 and above ... and on 13
#FIXME: DEBUGLEVEL is not propagated to this file (at least for Ubuntu)
[ -z "$DEBUGLEVEL" ] && DEBUGLEVEL=0
[ $DEBUGLEVEL -gt 3 -a $DEBUGLEVEL -lt 8 -o $DEBUGLEVEL -eq 13 ] && \
  set -x

echo -e "# network configuration written by $0:" >/tmp/confviadhcp
unset HOME IFS KCMDLINE DEBUGLEVEL MODPRV TERM BOOTIF BOOT_IMAGE \
       infomsg mask lease interface cfgmsg cfgfile boot_file no_bootsplash
# set the broadcast address if not delivered by dhcp
[ -z "$broadcast" ] && \
  broadcast=$(ipcalc -b $ip/$subnet|sed s/.*=//)
set | sed \
  -e "s,^P.*,,;s,ntpsrv,ntp_servers,;s,ip,clientip," \
  -e "s,serverid,serverip,;s,subnet,subnet_mask," \
  -e "s,router,gateway,;s,hostname,host_name," \
  -e "s,domain,domain_name,;s,dns,domain_name_servers," \
  -e "s,broadcast,broadcast_address,;s,dhc.*,,;/^$/d" \
  -e "s,nissrv,nis_servers,;s,nisdomain_name,nis_domain," \
  -e "s,wins,netbios_name_servers,;/OPTIND.*/d" >>/tmp/confviadhcp

# generate a local /etc/resolv.conf (might overwrite the version from preboot)
[ -n "$domain" ] && echo -e "search $domain\n" >/etc/resolv.conf
test -n "$dns" && {
  for name in $dns; do
    echo nameserver $name >>/etc/resolv.conf;
  done; }