summaryrefslogtreecommitdiffstats
path: root/remote/rootfs/rootfs-stage32/data/opt/openslx/bin
diff options
context:
space:
mode:
authorSimon Rettberg2013-07-02 15:19:21 +0200
committerSimon Rettberg2013-07-02 15:19:21 +0200
commit9deed9551d99a6fbd2ab672286df7777b681d6cc (patch)
treead07ccb65355f81281f123ab80d80ed8fd2462e4 /remote/rootfs/rootfs-stage32/data/opt/openslx/bin
parentAdd executable rights to all scripts. (diff)
downloadtm-scripts-9deed9551d99a6fbd2ab672286df7777b681d6cc.tar.gz
tm-scripts-9deed9551d99a6fbd2ab672286df7777b681d6cc.tar.xz
tm-scripts-9deed9551d99a6fbd2ab672286df7777b681d6cc.zip
[rootfs-stage32] Add /etc/hosts file, make udhcpc script update it
Diffstat (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/bin')
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script36
1 files changed, 35 insertions, 1 deletions
diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script
index 08d59eba..1bbf6e80 100755
--- a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script
+++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/udhcpc.openslx.script
@@ -29,6 +29,14 @@ rebuild_resolv_conf () {
sort -u /run/udhcpc/*.resolv > "$RESOLV_CONF"
}
+escape_search() {
+ echo "$@" | sed -e 's/[]\/()$*.^|[]/\\&/g'
+}
+
+escape_replace() {
+ echo "$@" | sed -e 's/[\/&]/\\&/g'
+}
+
case "$1" in
bound|renew)
ip addr add "$ip/$(ipcalc -s -p $ip $subnet|sed s/.*=//)" dev "$interface"
@@ -39,7 +47,7 @@ case "$1" in
# Update resolver configuration file
CONF=""
if [ -n "$domain" ]; then
- printf -v CONF "domain $domain\n"
+ printf -v CONF "domain $domain\nsearch $domain\n"
elif [ -n "$SLX_NET_DOMAIN" ]; then
printf -v CONF "domain $SLX_NET_DOMAIN\nsearch $SLX_NET_DOMAIN\n"
fi
@@ -81,6 +89,32 @@ case "$1" in
fi
fi
+ # Hostname in /etc/hosts
+ touch /etc/hosts
+ if [ -n "$dns_host" ]; then
+ short="${dns_host%%.*}"
+ [ "x$short" = "x$dns_host" ] && short=""
+ sed -i -r "s/\s$(escape_search "$dns_host")(\s|$)/ /g" /etc/hosts
+ [ -n "$short" ] && sed -i -r "s/\s$(escape_search "$short")(\s|$)/ /g" /etc/hosts
+ if grep -q -E "^$ip\s" /etc/hosts; then
+ sed -i "s/^$(escape_search "$ip")\s/$(escape_replace "$ip $dns_host $short ")/g" /etc/hosts
+ else
+ echo "$ip $dns_host $short" >> /etc/hosts
+ fi
+ fi
+ if [ -n "$hostname" -a "x$hostname" != "x$dns_host" ]; then
+ short="${hostname%%.*}"
+ [ "x$short" = "x$hostname" ] && short=""
+ sed -i -r "s/\s$(escape_search "$hostname")(\s|$)/ /g" /etc/hosts
+ [ -n "$short" ] && sed -i -r "s/\s$(escape_search "$short")(\s|$)/ /g" /etc/hosts
+ if grep -q -E "^$ip\s" /etc/hosts; then
+ sed -i "s/^$(escape_search "$ip")\s/$(escape_replace "$ip $hostname $short ")/g" /etc/hosts
+ else
+ echo "$ip $hostname $short" >> /etc/hosts
+ fi
+ fi
+ sed -i -r '/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\s*$/d' /etc/hosts
+
# We consider the network setup to be complete if an interface is being configured that
# has a default route and some dns servers set.
if [ -n "$router" ] && [ -n "$dns" ] && [ ! -e "/run/udhcpc/network-ready" ]; then