-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions
executable file
·72 lines (67 loc) · 2.28 KB
/
functions
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
###############################################
TOP='/root/autoinstall'
function get_ip(){
HOST_IP=`LC_ALL=C /sbin/ifconfig eth0 | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
MASK=`LC_ALL=C /sbin/ifconfig eth0 | grep -m 1 'inet addr:'| cut -d: -f4`
GW=`route -n | grep 'UG[ \t]' | awk '{print $2}'`
# echo ${HOST_IP}
# echo ${MASK}
# echo ${GW}
}
function set_ip(){
netconf='/etc/network/interfaces'
dns='dns-nameservers 61.139.2.69'
get_ip
if ( grep -q "iface eth0 inet dhcp" ${netconf} ) && ( ! grep -q "${HOST_IP}" ${netconf} )
then
sed -i 's/dhcp/static/' ${netconf}
echo "address ${HOST_IP}" >> ${netconf}
echo "netmask ${MASK}" >> ${netconf}
echo "gateway ${GW}" >> ${netconf}
echo ${dns} >> ${netconf}
elif ( grep -q "iface eth0 inet dhcp" ${netconf} ) && ( grep -q "${HOST_IP}" ${netconf} )
then
echo "/etc/network/interface file error" && exit 44
else
echo "please check interface file"
fi
}
function set_hostname(){
hosts='/etc/hosts'
h_name='/etc/hostname'
get_ip
ip=`echo ${HOST_IP} | cut -d. -f4`
if [ -z $ip ];then
echo "error" && exit 44
elif grep -q "${HOST_IP}" ${hosts}
then
echo "exist hosts record"
else
sed -i '/127.0.1.1/d' ${hosts}
echo "${HOST_IP} comp-$ip" >> ${hosts}
hostname "comp-$ip"
echo "comp-$ip" > ${h_name}
fi
}
function set_apt_sources(){
sources='/etc/apt/sources.list'
sed -i "s/172.18.200.144/cn.archive.ubuntu.com/g" ${sources}
filename='/etc/apt/sources.list.d/new.list'
echo 'deb http://apt.puppetlabs.com precise main' > ${filename}
echo 'deb-src http://apt.puppetlabs.com precise main' >> ${filename}
echo 'deb http://apt.puppetlabs.com precise dependencies' >> ${filename}
echo 'deb-src http://apt.puppetlabs.com precise dependencies' >> ${filename}
echo 'deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-proposed/folsom main' >> ${filename}
echo 'deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/folsom main' >> ${filename}
}
function set_novaconfig(){
conf="${TOP}/nova.conf"
novaconf='/etc/nova/nova.conf'
if [ -f ${conf} ] && [ -f ${novaconf} ]
then
cat ${conf} > ${novaconf}
sed -i -e "s/%local_ip%/${HOST_IP}/g" -e "s/%control_ip%/${CONTROL_IP}/g" -e "s/%mysql_password%/${MY_PW}/g" ${novaconf}
else
echo "nova config error" && exit 44
fi
}