root / example / hooks / linux / interfaces @ 8d77389f
History | View | Annotate | Download (4.4 kB)
1 | 79224631 | Lance Albertson | #!/bin/bash |
---|---|---|---|
2 | 79224631 | Lance Albertson | |
3 | f1afb4b1 | Lance Albertson | # Copyright (C) 2010 Oregon State University |
4 | f1afb4b1 | Lance Albertson | # |
5 | f1afb4b1 | Lance Albertson | # This program is free software; you can redistribute it and/or modify |
6 | f1afb4b1 | Lance Albertson | # it under the terms of the GNU General Public License as published by |
7 | f1afb4b1 | Lance Albertson | # the Free Software Foundation; either version 2 of the License, or |
8 | f1afb4b1 | Lance Albertson | # (at your option) any later version. |
9 | f1afb4b1 | Lance Albertson | # |
10 | f1afb4b1 | Lance Albertson | # This program is distributed in the hope that it will be useful, but |
11 | f1afb4b1 | Lance Albertson | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | f1afb4b1 | Lance Albertson | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | f1afb4b1 | Lance Albertson | # General Public License for more details. |
14 | f1afb4b1 | Lance Albertson | # |
15 | f1afb4b1 | Lance Albertson | # You should have received a copy of the GNU General Public License |
16 | f1afb4b1 | Lance Albertson | # along with this program; if not, write to the Free Software |
17 | f1afb4b1 | Lance Albertson | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | f1afb4b1 | Lance Albertson | # 02110-1301, USA. |
19 | f1afb4b1 | Lance Albertson | # |
20 | 6fc975e1 | Lance Albertson | # This is an example script that configures your network settings after |
21 | 6fc975e1 | Lance Albertson | # installation. By default it sets it up to use dhcp. |
22 | 6fc975e1 | Lance Albertson | |
23 | c6253116 | Lance Albertson | set -e |
24 | c6253116 | Lance Albertson | |
25 | e1d2d9bd | Lance Albertson | . common.sh |
26 | e1d2d9bd | Lance Albertson | |
27 | e7a2d1ad | Lance Albertson | debug set -x |
28 | e84e87cd | Lance Albertson | |
29 | 6f258fa8 | Lance Albertson | FQDN="${INSTANCE_NAME}" |
30 | 6f258fa8 | Lance Albertson | SHORT_NAME="$(echo ${INSTANCE_NAME} | cut -d . -f 1)" |
31 | 276c74b6 | Lance Albertson | STATIC="" |
32 | 79224631 | Lance Albertson | |
33 | 6fc975e1 | Lance Albertson | if [ -z "${TARGET}" -o ! -d "${TARGET}" ] ; then |
34 | e0f1ce56 | Lance Albertson | log_error "Missing target directory" |
35 | 6fc975e1 | Lance Albertson | exit 1 |
36 | 79224631 | Lance Albertson | fi |
37 | 79224631 | Lance Albertson | |
38 | 6fc975e1 | Lance Albertson | if [ -z "${NIC_COUNT}" ] ; then |
39 | e0f1ce56 | Lance Albertson | log_error "Missing NIC_COUNT" |
40 | 6fc975e1 | Lance Albertson | exit 1 |
41 | 79224631 | Lance Albertson | fi |
42 | 79224631 | Lance Albertson | |
43 | 276c74b6 | Lance Albertson | if [ -f "${NETWORKS_DIR}/instances/${FQDN}" ] ; then |
44 | 276c74b6 | Lance Albertson | STATIC="yes" |
45 | 276c74b6 | Lance Albertson | source ${NETWORKS_DIR}/instances/${FQDN} |
46 | a04a3ce8 | Lance Albertson | if [ -f "${NETWORKS_DIR}/subnets/${SUBNET}" ] ; then |
47 | a04a3ce8 | Lance Albertson | source ${NETWORKS_DIR}/subnets/${SUBNET} |
48 | 276c74b6 | Lance Albertson | else |
49 | 276c74b6 | Lance Albertson | echo "No subnet file for subnet ${SUBNET}!" |
50 | 276c74b6 | Lance Albertson | exit 1 |
51 | 276c74b6 | Lance Albertson | fi |
52 | 276c74b6 | Lance Albertson | fi |
53 | 276c74b6 | Lance Albertson | |
54 | f6f223b8 | Lance Albertson | # Functions |
55 | 6fc975e1 | Lance Albertson | debian_setup() { |
56 | 6fc975e1 | Lance Albertson | if [ ! -d "${TARGET}/etc/network" ] ; then |
57 | e0f1ce56 | Lance Albertson | log_error "Missing target network directory" |
58 | 6fc975e1 | Lance Albertson | exit 1 |
59 | 6fc975e1 | Lance Albertson | fi |
60 | 276c74b6 | Lance Albertson | |
61 | 276c74b6 | Lance Albertson | if [ -z "${STATIC}" ] ; then |
62 | 276c74b6 | Lance Albertson | cat > ${TARGET}/etc/network/interfaces << EOF |
63 | 79224631 | Lance Albertson | # This file describes the network interfaces available on your system |
64 | 79224631 | Lance Albertson | # and how to activate them. For more information, see interfaces(5). |
65 | 79224631 | Lance Albertson | |
66 | 79224631 | Lance Albertson | auto lo |
67 | 79224631 | Lance Albertson | iface lo inet loopback |
68 | 79224631 | Lance Albertson | |
69 | 79224631 | Lance Albertson | auto eth0 |
70 | 79224631 | Lance Albertson | iface eth0 inet dhcp |
71 | 79224631 | Lance Albertson | |
72 | 79224631 | Lance Albertson | EOF |
73 | 276c74b6 | Lance Albertson | else |
74 | 276c74b6 | Lance Albertson | cat > ${TARGET}/etc/network/interfaces << EOF |
75 | 276c74b6 | Lance Albertson | # This file describes the network interfaces available on your system |
76 | 276c74b6 | Lance Albertson | # and how to activate them. For more information, see interfaces(5). |
77 | 276c74b6 | Lance Albertson | |
78 | 276c74b6 | Lance Albertson | auto lo |
79 | 276c74b6 | Lance Albertson | iface lo inet loopback |
80 | 276c74b6 | Lance Albertson | |
81 | 276c74b6 | Lance Albertson | auto eth0 |
82 | 276c74b6 | Lance Albertson | iface eth0 inet static |
83 | 276c74b6 | Lance Albertson | address ${ADDRESS} |
84 | 276c74b6 | Lance Albertson | netmask ${NETMASK} |
85 | 276c74b6 | Lance Albertson | gateway ${GATEWAY} |
86 | 276c74b6 | Lance Albertson | |
87 | 276c74b6 | Lance Albertson | EOF |
88 | 276c74b6 | Lance Albertson | fi |
89 | 79224631 | Lance Albertson | |
90 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
91 | 599b34d2 | Lance Albertson | echo "${SHORT_NAME}" > ${TARGET}/etc/hostname |
92 | 6fc975e1 | Lance Albertson | fi |
93 | 6fc975e1 | Lance Albertson | } |
94 | 6fc975e1 | Lance Albertson | |
95 | 6fc975e1 | Lance Albertson | redhat_setup() { |
96 | 6fc975e1 | Lance Albertson | if [ ! -d "${TARGET}/etc/sysconfig/network-scripts" ] ; then |
97 | e0f1ce56 | Lance Albertson | log_error "Missing target network directory" |
98 | 6fc975e1 | Lance Albertson | exit 1 |
99 | 6fc975e1 | Lance Albertson | fi |
100 | 276c74b6 | Lance Albertson | if [ -z "${STATIC}" ] ; then |
101 | 276c74b6 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network-scripts/ifcfg-eth0 << EOF |
102 | 6fc975e1 | Lance Albertson | DEVICE=eth0 |
103 | 6fc975e1 | Lance Albertson | BOOTPROTO=dhcp |
104 | 6fc975e1 | Lance Albertson | ONBOOT=yes |
105 | 6fc975e1 | Lance Albertson | EOF |
106 | 276c74b6 | Lance Albertson | else |
107 | 276c74b6 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network-scripts/ifcfg-eth0 << EOF |
108 | 276c74b6 | Lance Albertson | DEVICE=eth0 |
109 | 276c74b6 | Lance Albertson | BOOTPROTO=static |
110 | 276c74b6 | Lance Albertson | IPADDR=${ADDRESS} |
111 | 276c74b6 | Lance Albertson | NETMASK=${NETMASK} |
112 | 276c74b6 | Lance Albertson | ONBOOT=yes |
113 | 276c74b6 | Lance Albertson | EOF |
114 | a04a3ce8 | Lance Albertson | fi |
115 | 6fc975e1 | Lance Albertson | |
116 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
117 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network << EOF |
118 | 6fc975e1 | Lance Albertson | NETWORKING=yes |
119 | 6fc975e1 | Lance Albertson | HOSTNAME=${FQDN} |
120 | 276c74b6 | Lance Albertson | GATEWAY=${GATEWAY} |
121 | 6fc975e1 | Lance Albertson | EOF |
122 | 6fc975e1 | Lance Albertson | else |
123 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network << EOF |
124 | 6fc975e1 | Lance Albertson | NETWORKING=yes |
125 | 276c74b6 | Lance Albertson | GATEWAY=${GATEWAY} |
126 | 6fc975e1 | Lance Albertson | EOF |
127 | 6fc975e1 | Lance Albertson | fi |
128 | 6fc975e1 | Lance Albertson | } |
129 | 6fc975e1 | Lance Albertson | |
130 | 6fc975e1 | Lance Albertson | gentoo_setup() { |
131 | 6fc975e1 | Lance Albertson | if [ ! -f "${TARGET}/etc/conf.d/net" ] ; then |
132 | e0f1ce56 | Lance Albertson | log_error "Missing target network file" |
133 | 6fc975e1 | Lance Albertson | exit 1 |
134 | 6fc975e1 | Lance Albertson | fi |
135 | 276c74b6 | Lance Albertson | if [ -z "${STATIC}" ] ; then |
136 | 276c74b6 | Lance Albertson | cat > ${TARGET}/etc/conf.d/net << EOF |
137 | 6fc975e1 | Lance Albertson | config_eth0=( "dhcp" ) |
138 | 6fc975e1 | Lance Albertson | EOF |
139 | 276c74b6 | Lance Albertson | else |
140 | 276c74b6 | Lance Albertson | cat > ${TARGET}/etc/conf.d/net << EOF |
141 | add6b6bf | Lance Albertson | config_eth0=( "${ADDRESS} netmask ${NETMASK}" ) |
142 | 276c74b6 | Lance Albertson | routes_eth0=( "default gw ${GATEWAY}" ) |
143 | 276c74b6 | Lance Albertson | EOF |
144 | a04a3ce8 | Lance Albertson | fi |
145 | 276c74b6 | Lance Albertson | |
146 | 0747d6ac | Lance Albertson | chroot ${TARGET} ln -sf /etc/init.d/net.lo /etc/init.d/net.eth0 |
147 | cfc6ba79 | Lance Albertson | chroot ${TARGET} rc-update add net.eth0 default |
148 | 6fc975e1 | Lance Albertson | |
149 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
150 | 0747d6ac | Lance Albertson | # baselayout-2.x |
151 | 0747d6ac | Lance Albertson | if [ -d "${TARGET}/usr/share/openrc/" ] ; then |
152 | 0747d6ac | Lance Albertson | cat > ${TARGET}/etc/conf.d/hostname << EOF |
153 | 0747d6ac | Lance Albertson | hostname="${SHORT_NAME}" |
154 | 0747d6ac | Lance Albertson | EOF |
155 | 0747d6ac | Lance Albertson | else |
156 | 0747d6ac | Lance Albertson | cat > ${TARGET}/etc/conf.d/hostname << EOF |
157 | 6f258fa8 | Lance Albertson | HOSTNAME="${SHORT_NAME}" |
158 | 6fc975e1 | Lance Albertson | EOF |
159 | 0747d6ac | Lance Albertson | fi |
160 | 6fc975e1 | Lance Albertson | fi |
161 | 6fc975e1 | Lance Albertson | } |
162 | 6fc975e1 | Lance Albertson | |
163 | 6fc975e1 | Lance Albertson | suse_setup() { |
164 | 6fc975e1 | Lance Albertson | if [ ! -d ${TARGET}/etc/sysconfig/network ] ; then |
165 | e0f1ce56 | Lance Albertson | log_error "Missing target network directory" |
166 | 6fc975e1 | Lance Albertson | exit 1 |
167 | 6fc975e1 | Lance Albertson | fi |
168 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network/ifcfg-eth0 << EOF |
169 | 0cba7e2a | Lance Albertson | BOOTPROTO='dhcp4' |
170 | 0cba7e2a | Lance Albertson | STARTMODE='auto' |
171 | 0cba7e2a | Lance Albertson | NAME='Ethernet Card 0' |
172 | 6fc975e1 | Lance Albertson | EOF |
173 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
174 | 6fc975e1 | Lance Albertson | echo "${FQDN}" > ${TARGET}/etc/HOSTNAME |
175 | 6fc975e1 | Lance Albertson | fi |
176 | 6fc975e1 | Lance Albertson | } |
177 | 6fc975e1 | Lance Albertson | |
178 | 08abb89f | Lance Albertson | # Main |
179 | abade4ea | Lance Albertson | get_os_type $TARGET |
180 | 08abb89f | Lance Albertson | |
181 | 08abb89f | Lance Albertson | if [ "${NIC_COUNT}" -gt 0 -a -n "${OS_TYPE}" ] ; then |
182 | 08abb89f | Lance Albertson | ${OS_TYPE}_setup |
183 | 08abb89f | Lance Albertson | else |
184 | 08abb89f | Lance Albertson | log_error "Unsupported OS_TYPE" |
185 | 08abb89f | Lance Albertson | fi |
186 | 08abb89f | Lance Albertson | |
187 | 08abb89f | Lance Albertson | |
188 | e1d2d9bd | Lance Albertson | exit 0 |