summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Plaetinck <dieter@plaetinck.be>2010-12-28 17:56:00 +0100
committerDieter Plaetinck <dieter@plaetinck.be>2010-12-28 17:56:00 +0100
commit25f7a0471340e8d6c2b37e3c75aa7d0ae209d09d (patch)
tree8a5c921946125e659df4adf4b2baf733c764d482
parentfebffe7a9f6d7dd27eb7e382e11ea9fbda62bb26 (diff)
cleanup worker_auto_network() / target_configure_network() code
The only thing needed to know before calling target_configure_network() is whether $RUNTIME_DIR/aif-network-settings exists; if that exists, network setup has been run sucessfully and all values are known. It's up to target_configure_network() to source that, which means worker_auto_network() functions can become simpler. Also, variable name cleanup: s/S_DHCP/DHCP/
-rw-r--r--src/core/libs/lib-network.sh12
-rw-r--r--src/core/libs/lib-ui-interactive.sh10
-rw-r--r--src/core/procedures/base9
-rw-r--r--src/core/procedures/interactive25
4 files changed, 23 insertions, 33 deletions
diff --git a/src/core/libs/lib-network.sh b/src/core/libs/lib-network.sh
index 19d4862..aa961ce 100644
--- a/src/core/libs/lib-network.sh
+++ b/src/core/libs/lib-network.sh
@@ -1,17 +1,13 @@
#!/bin/bash
-# auto_network().
# configures network on host system according to installer settings
# if some variables are not set, we handle that transparantly
-# $1 dhcp/fixed
-# $2 http proxy (optional. defaults to '')
-# $3 ftp proxy (optional. defaults to '')
+# however, at least $DHCP must be set, so we know what do to
+# we assume that you checked whether networking has been setup before calling us
target_configure_network()
{
- [ "$1" != dhcp -a "$1" != fixed ] && die_error "target_configure_network \$1 must be 'dhcp' or 'fixed'"
- PROXY_HTTP="$2"
- PROXY_FTP="$3"
- if [ "$1" = fixed ]; then
+ source $RUNTIME_DIR/aif-network-settings 2>/dev/null || return 1
+ if [ "$DHCP" = 0 ] ; then
sed -i "s/#eth0=\"eth0/eth0=\"eth0/g" ${var_TARGET_DIR}/etc/rc.conf || return 1
sed -i "s/^eth0=\"dhcp/#eth0=\"dhcp/g" ${var_TARGET_DIR}/etc/rc.conf || return 1
sed -i "s#eth0=\"eth0#${INTERFACE:-eth0}=\"${INTERFACE:-eth0}#g" ${var_TARGET_DIR}/etc/rc.conf || return 1
diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh
index e7f114b..0b3abb4 100644
--- a/src/core/libs/lib-ui-interactive.sh
+++ b/src/core/libs/lib-ui-interactive.sh
@@ -787,7 +787,7 @@ If any previous configuration you've done until now (like fancy filesystems) req
# returns: 1 on failure
interactive_runtime_network() {
INTERFACE=""
- S_DHCP=""
+ DHCP=""
local ifaces
ifaces=$(ifconfig -a |grep "Link encap:Ethernet"|sed 's/ \+Link encap:Ethernet \+HWaddr \+/ /g')
@@ -810,9 +810,9 @@ interactive_runtime_network() {
show_warning "Dhcpcd problem" "DHCP request failed. dhcpcd returned 0 but no ip configured for $INTERFACE"
return 1
fi
- S_DHCP=1
+ DHCP=1
else
- S_DHCP=0
+ DHCP=0
NETPARAMETERS=""
while [ "$NETPARAMETERS" = "" ]; do
ask_string "Enter your IP address" "192.168.0.2" || return 1
@@ -859,14 +859,14 @@ interactive_runtime_network() {
echo "nameserver $DNS" >/etc/resolv.conf
fi
echo "INTERFACE=$INTERFACE
- S_DHCP=$S_DHCP
+ DHCP=$DHCP
IPADDR=$IPADDR
SUBNET=$SUBNET
BROADCAST=$BROADCAST
GW=$GW
DNS=$DNS
PROXY_HTTP=$PROXY_HTTP
- PROXY_FTP=$PROXY_FTP" > $RUNTIME_DIR/aif-network-settings
+ PROXY_FTP=$PROXY_FTP" > $RUNTIME_DIR/aif-network-settings || return 1
notify "The network is configured."
return 0
}
diff --git a/src/core/procedures/base b/src/core/procedures/base
index fbab6f7..dd05773 100644
--- a/src/core/procedures/base
+++ b/src/core/procedures/base
@@ -159,10 +159,11 @@ worker_install_packages ()
worker_auto_network ()
{
- [ "$S_DHCP" = 1 ] && target_configure_network dhcp "$PROXY_HTTP" "$PROXY_FTP" && return 0
- [ "$S_DHCP" = 0 ] && target_configure_network fixed "$PROXY_HTTP" "$PROXY_FTP" && return 0
- [ "$S_DHCP" != 1 -a "$S_DHCP" != 0 ] && return 0
- return 1
+ if [ -f $RUNTIME_DIR/aif-network-settings ]
+ then
+ target_configure_network || return $?
+ fi
+ return 0
}
diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive
index 5ee8cd7..03b9c1a 100644
--- a/src/core/procedures/interactive
+++ b/src/core/procedures/interactive
@@ -177,25 +177,18 @@ worker_install_bootloader ()
worker_auto_network ()
{
- ask=0
- # if the user has been through networking setup and if any of these variables is set, it may be useful to export the users' choices to the target system
- if [ "$S_DHCP" = 1 -o "$S_DHCP" = 0 ] && [ -n "$PROXY_HTTP$PROXY_FTP$DNS$INTERFACE$SUBNET$GW$BROADCAST" ]
- then
- ask=1
- # if the variables are not set but the network settings file exists, the user has probably run the runtime_network in a separate process (eg partial-configure-network)
- # in that case, lets source the file and check again
- elif [ -f $RUNTIME_DIR/aif-network-settings ] && source $RUNTIME_DIR/aif-network-settings && [ "$S_DHCP" = 1 -o "$S_DHCP" = 0 ] && [ -n "$PROXY_HTTP$PROXY_FTP$DNS$INTERFACE$SUBNET$GW$BROADCAST" ]
- then
- ask=1
- fi
- if [ "$ask" = 1 ]
+ # if the user has been through networking setup, it may be useful to export the users' choices to the target system
+ # networking setup could have happened in a separate process (eg partial-configure-network), so check if the settings file was created to be sure
+ if [ -f $RUNTIME_DIR/aif-network-settings ]
then
ask_yesno "Do you want to use the network settings from the installer in rc.conf and resolv.conf?\n\nIf you used Proxy settings, they will be written to /etc/profile.d/proxy.sh" || return 0
- [ "$S_DHCP" = 1 ] && target_configure_network dhcp "$PROXY_HTTP" "$PROXY_FTP" && return 0
- [ "$S_DHCP" = 0 ] && target_configure_network fixed "$PROXY_HTTP" "$PROXY_FTP" && return 0
- show_warning "Automatic network settings propagation failed" "Failed to import current network settings into target system"
- return 1
+ if ! target_configure_network
+ then
+ show_warning "Automatic network settings propagation failed" "Failed to import current network settings into target system"
+ return 1
+ fi
fi
+ return 0
}
worker_abort_installer ()