-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchangeIP.sh
70 lines (66 loc) · 1.71 KB
/
changeIP.sh
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
#!/usr/bin/env bash
#
# Author: Aman Hanjrah
# Date: 27 Mar 2015
# License: GPLv2.0
#
# Start
main() {
. ./vars.sh
vzlist -a
listFile=$(mktemp)
chkCtid
rmJunk
}
chkCtid() {
LIST=$(vzlist -a | cut -d' ' -f8 | grep -v '^$' > "$listFile")
echo -e "${BGre}Enter the CTID for which you want to change Disk space for:${RCol}"
read -e userCtid
if [[ -z "$userCtid" ]]; then
echo -e "${BRed}This cannot be empty, try again${RCol}"
chkCtid
fi
grep -w "$userCtid" "$listFile" >> /dev/null
if [[ $? -ne 0 ]]; then
echo -e "${BRed}CTID that you have mentioned, does not exist, try again:${RCol}"
chkCtid
else
chkIP
fi
}
chkIP() {
echo -e "${BGre}Provide a valid IP address:${RCol}"
read -e userIP
if echo "$userIP" | egrep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' >> /dev/null 2<&1 #check if IP provided by user is in X.X.X.X format and no alphabets are there
then
validIP="$(echo $userIP | awk -F'.' '$1 <=254 && $2 <= 254 && $3 <= 254 && $4 <= 254')" >> /dev/null 2<&1 #check if the value of each octect is between 0-254, if not, error is shown
if [ -z "$validIP" ]; then
echo -e "${BRed}Invalid IP address, octets must be less than 255. Try again${RCol}"
sleep 2
chkIP
else
changeIP
fi
else
echo -e "${BRed}Invalid IP address, try again!${RCol}"
sleep 2
chkIP
fi
}
changeIP() {
stopCtid
vzctl set "$userCtid" --ipdel all --save >> /dev/null 2<&1
vzctl set "$userCtid" --ipadd "$userIP" --save >> /dev/null 2<&1
if [[ $? = 0 ]]; then
startCtid
echo -e "${BGre}Successful!${RCol}"
sleep 3
sh master.sh
exit $?
else
echo -e "${BRed}Oh boy! something went wrong!\nExiting!${RCol}"
sleep 3
exit $?
fi
}
main