blob: 17a572f3bafd07df24192b5b129a0ac0ccca015f (
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
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
|
#!/bin/bash
DATUM=$(date +%Y%m%d_%H%M%S)
INTERFACES="/etc/network/interfaces"
RESOLV="/etc/resolv.conf"
ERR=0
ask_config() {
echo
echo "This script configures a static IP adress."
echo "If you are unsure you can execute it later; you will find this script"
echo "at /usr/local/sbin/${0}."
echo "Please keep in mind you will have to reinitialize the network by hand then"
echo "(or simply reboot)."
echo
echo -n "If you want to configure a static IP adress, press y, any other key to abort: "
read -n 1 config_me
ech
echo
[ "$config_me" != "y" ] && exit 0
}
backup_configs() {
if [ -f /etc/network/interfaces ]; then
cp -p "$INTERFACES" "$INTERFACES.${DATUM}" || \
{ echo "Could not $INTERFACES to backup location $INTERFACES.$DATUM - aborting."; \
exit 1 ; }
cp -p "$RESOLV" "$RESOLV.${DATUM}" || \
{ echo "Could not $RESOLV to backup location $RESOLV.$DATUM - aborting."; \
exit 1 ; }
fi
}
restore_configs() {
cp -p "$INTERFACES.$DATUM" "$INTERFACES"
cp -p "$RESOLV.{DATUM}" "$RESOLV"
}
enter_values() {
while [ "$entry" != "y" ] && [ "$entry" != "Y" ]; do
echo
echo -n "IP-Adress: "
read ipadress
echo -n "Gateway: "
read gateway
echo -n "Net mask - leave empty for 255.255.255.0: "
read netmask
[ "$netmask" == "" ] && netmask=255.255.255.0
echo -n "Domain - leave empty if not wanted: "
read domain
echo -n "Search domain - leave empty if not wanted: "
read search
echo -n "Primary nameserver: "
read primarydns
echo -n "Secondary nameserver - leave empty if no secondary DNS: "
read secondarydns
echo
echo "# IP Adress : $ipadress"
echo "# Gateway : $gateway"
echo "# Net mask : $netmask"
echo "# Domain : $domain"
echo "# Search domain : $search"
echo "# Primary nameserver : $primarydns"
echo "# Secondary nameserver : $secondarydns"
echo
echo -n "Are those correct values? Press y or Y für yes, any other key for no: "
read -n 1 entry
echo
done
}
write_configs() {
echo "# This file was written by the satellite auto installer." > "$INTERFACES"
echo "# If any problems arise, copy $INTERFACES.${DATUM}." >> "$INTERFACES"
echo "# The loopback network interface" >> "$INTERFACES"
echo "auto lo" >> "$INTERFACES"
echo "iface lo inet loopback" >> "$INTERFACES"
echo "" >> "$INTERFACES"
echo "# Primary network interface" >> "$INTERFACES"
echo "auto eth0" >> "$INTERFACES"
echo "iface eth0 inet static" >> "$INTERFACES"
echo "address $ipadress" >> "$INTERFACES"
echo "gateway $gateway" >> "$INTERFACES"
echo "netmask $netmask" >> "$INTERFACES"
echo "# This file was written by the satellite server install script." > "$RESOLV"
echo "# If any problems arise, copy $RESOLV.${DATUM}." >> "$RESOLV"
[ -n "$domain" ] && echo "domain $domain" >> "$RESOLV"
[ -n "$search" ] && echo "search $search" >> "$RESOLV"
echo "nameserver $primarydns" >> "$RESOLV"
[ -n "$secondarydns" ] && echo "nameserver $secondarydns" >> "$RESOLV"
}
ask_config
enter_values
backup_configs
write_configs
|