root / example / instance-image.d / interfaces @ 9404f8cd
History | View | Annotate | Download (3 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 | 79224631 | Lance Albertson | |
32 | 6fc975e1 | Lance Albertson | if [ -z "${TARGET}" -o ! -d "${TARGET}" ] ; then |
33 | e0f1ce56 | Lance Albertson | log_error "Missing target directory" |
34 | 6fc975e1 | Lance Albertson | exit 1 |
35 | 79224631 | Lance Albertson | fi |
36 | 79224631 | Lance Albertson | |
37 | 6fc975e1 | Lance Albertson | if [ -z "${NIC_COUNT}" ] ; then |
38 | e0f1ce56 | Lance Albertson | log_error "Missing NIC_COUNT" |
39 | 6fc975e1 | Lance Albertson | exit 1 |
40 | 79224631 | Lance Albertson | fi |
41 | 79224631 | Lance Albertson | |
42 | f6f223b8 | Lance Albertson | # Functions |
43 | 6fc975e1 | Lance Albertson | debian_setup() { |
44 | 6fc975e1 | Lance Albertson | if [ ! -d "${TARGET}/etc/network" ] ; then |
45 | e0f1ce56 | Lance Albertson | log_error "Missing target network directory" |
46 | 6fc975e1 | Lance Albertson | exit 1 |
47 | 6fc975e1 | Lance Albertson | fi |
48 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/network/interfaces << EOF |
49 | 79224631 | Lance Albertson | # This file describes the network interfaces available on your system |
50 | 79224631 | Lance Albertson | # and how to activate them. For more information, see interfaces(5). |
51 | 79224631 | Lance Albertson | |
52 | 79224631 | Lance Albertson | auto lo |
53 | 79224631 | Lance Albertson | iface lo inet loopback |
54 | 79224631 | Lance Albertson | |
55 | 79224631 | Lance Albertson | auto eth0 |
56 | 79224631 | Lance Albertson | iface eth0 inet dhcp |
57 | 79224631 | Lance Albertson | |
58 | 79224631 | Lance Albertson | EOF |
59 | 79224631 | Lance Albertson | |
60 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
61 | 6fc975e1 | Lance Albertson | echo "${FQDN}" > ${TARGET}/etc/hostname |
62 | 6fc975e1 | Lance Albertson | fi |
63 | 6fc975e1 | Lance Albertson | } |
64 | 6fc975e1 | Lance Albertson | |
65 | 6fc975e1 | Lance Albertson | redhat_setup() { |
66 | 6fc975e1 | Lance Albertson | if [ ! -d "${TARGET}/etc/sysconfig/network-scripts" ] ; then |
67 | e0f1ce56 | Lance Albertson | log_error "Missing target network directory" |
68 | 6fc975e1 | Lance Albertson | exit 1 |
69 | 6fc975e1 | Lance Albertson | fi |
70 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network-scripts/ifcfg-eth0 << EOF |
71 | 6fc975e1 | Lance Albertson | DEVICE=eth0 |
72 | 6fc975e1 | Lance Albertson | BOOTPROTO=dhcp |
73 | 6fc975e1 | Lance Albertson | ONBOOT=yes |
74 | 6fc975e1 | Lance Albertson | EOF |
75 | 6fc975e1 | Lance Albertson | |
76 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
77 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network << EOF |
78 | 6fc975e1 | Lance Albertson | NETWORKING=yes |
79 | 6fc975e1 | Lance Albertson | HOSTNAME=${FQDN} |
80 | 6fc975e1 | Lance Albertson | EOF |
81 | 6fc975e1 | Lance Albertson | else |
82 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network << EOF |
83 | 6fc975e1 | Lance Albertson | NETWORKING=yes |
84 | 6fc975e1 | Lance Albertson | EOF |
85 | 6fc975e1 | Lance Albertson | fi |
86 | 6fc975e1 | Lance Albertson | } |
87 | 6fc975e1 | Lance Albertson | |
88 | 6fc975e1 | Lance Albertson | gentoo_setup() { |
89 | 6fc975e1 | Lance Albertson | if [ ! -f "${TARGET}/etc/conf.d/net" ] ; then |
90 | e0f1ce56 | Lance Albertson | log_error "Missing target network file" |
91 | 6fc975e1 | Lance Albertson | exit 1 |
92 | 6fc975e1 | Lance Albertson | fi |
93 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/conf.d/net << EOF |
94 | 6fc975e1 | Lance Albertson | config_eth0=( "dhcp" ) |
95 | 6fc975e1 | Lance Albertson | EOF |
96 | cfc6ba79 | Lance Albertson | chroot ${TARGET} rc-update add net.eth0 default |
97 | 6fc975e1 | Lance Albertson | |
98 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
99 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/conf.d/hostname << EOF |
100 | 6f258fa8 | Lance Albertson | HOSTNAME="${SHORT_NAME}" |
101 | 6fc975e1 | Lance Albertson | EOF |
102 | 6fc975e1 | Lance Albertson | fi |
103 | 6fc975e1 | Lance Albertson | } |
104 | 6fc975e1 | Lance Albertson | |
105 | 6fc975e1 | Lance Albertson | suse_setup() { |
106 | 6fc975e1 | Lance Albertson | if [ ! -d ${TARGET}/etc/sysconfig/network ] ; then |
107 | e0f1ce56 | Lance Albertson | log_error "Missing target network directory" |
108 | 6fc975e1 | Lance Albertson | exit 1 |
109 | 6fc975e1 | Lance Albertson | fi |
110 | 6fc975e1 | Lance Albertson | cat > ${TARGET}/etc/sysconfig/network/ifcfg-eth0 << EOF |
111 | 0cba7e2a | Lance Albertson | BOOTPROTO='dhcp4' |
112 | 0cba7e2a | Lance Albertson | STARTMODE='auto' |
113 | 0cba7e2a | Lance Albertson | NAME='Ethernet Card 0' |
114 | 6fc975e1 | Lance Albertson | EOF |
115 | 6fc975e1 | Lance Albertson | if [ -n "${FQDN}" ] ; then |
116 | 6fc975e1 | Lance Albertson | echo "${FQDN}" > ${TARGET}/etc/HOSTNAME |
117 | 6fc975e1 | Lance Albertson | fi |
118 | 6fc975e1 | Lance Albertson | } |
119 | 6fc975e1 | Lance Albertson | |
120 | 08abb89f | Lance Albertson | # Main |
121 | abade4ea | Lance Albertson | get_os_type $TARGET |
122 | 08abb89f | Lance Albertson | |
123 | 08abb89f | Lance Albertson | if [ "${NIC_COUNT}" -gt 0 -a -n "${OS_TYPE}" ] ; then |
124 | 08abb89f | Lance Albertson | ${OS_TYPE}_setup |
125 | 08abb89f | Lance Albertson | else |
126 | 08abb89f | Lance Albertson | log_error "Unsupported OS_TYPE" |
127 | 08abb89f | Lance Albertson | fi |
128 | 08abb89f | Lance Albertson | |
129 | 08abb89f | Lance Albertson | |
130 | e1d2d9bd | Lance Albertson | exit 0 |