-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_upgrade.sh
More file actions
106 lines (89 loc) · 3.02 KB
/
deploy_upgrade.sh
File metadata and controls
106 lines (89 loc) · 3.02 KB
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
98
99
100
101
102
103
104
105
106
#!/bin/bash
if [ -z "$1" ] ; then
echo "usage: $0 -a single|cluster -h hostname|clustername"
echo "example:"
echo -e "$0 -a cluster -h APACHE,FTP \t# will upgrade all servers in apache and ftp clusters"
echo -e "$0 -a single -h apache01.atomia.hostcenter.com \t# will upgrade only apache01 server"
echo "allowed clusters: HOSTING DNS FTP APACHE1 APACHE2 APACHE3 MAIL MYSQL LB STORAGE AILINT MIGRATION PUPPET LOINT BACULA NAGIOS"
exit 1
fi
#Get current user ID
USER=`who am i | awk '{print $1}'`
USERKEY="/home/$USER/.ssh/id_rsa"
SERVERS="/opt/upgrade/servers.conf"
UPGRADED=0
HOSTS=""
#validates server types
function validate_type(){
config=$1
formated=`echo "$config" | tr ',' '\n'`
allowed="HOSTING DNS FTP APACHE1 APACHE2 APACHE3 MAIL MYSQL LB STORAGE AILINT MIGRATION PUPPET LOINT BACULA NAGIOS"
for types in $formated
do
echo "$allowed" | grep -q "$types"
comapre=$?
if [ $comapre -eq 1 ];then
echo "Type $types is not allowed. Allowed values are: $allowed"
exit 1
fi
done
return 0
}
function upgrade_cluster(){
TOUPGRADE=$1
while read -r line
do
VMCONFIG="$line"
if [[ $VMCONFIG != \#* ]]; then
IP=`echo "$VMCONFIG" | cut -d '*' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
TYPE=`echo "$VMCONFIG" | cut -d '*' -f3 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
FQDN=`echo "$VMCONFIG" | cut -d '*' -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
echo "$TOUPGRADE" | grep -q "$TYPE"
comapretype=$?
if [ $comapretype -eq 0 ];then
echo "Enter your passphrase for server: $FQDN"
ssh -n -i "$USERKEY" "$USER@$IP" sudo unattended-upgrade -d
echo "$FQDN ($IP) is completed! - $TYPE"
((UPGRADED++))
fi
fi
done < "$SERVERS"
echo "SERVERS UPGRADED IN TOTAL: $UPGRADED"
return 0
}
function upgrade_single(){
TOUPGRADE=$1
VM=`cat ${SERVERS} | grep "$TOUPGRADE"`
IP=`echo "$VM" | cut -d '*' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
FQDN=`echo "$VM" | cut -d '*' -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`
if [[ $IP == "" ]]; then
echo "Server $TOUPGRADE not found!"
exit 1
fi
echo "Enter your passphrase for server: $FQDN"
ssh -n -i "$USERKEY" "$USER@$IP" sudo unattended-upgrade -d
echo "$FQDN ($IP) is completed!"
return 0
}
while [ "$1" != "" ]; do
case $1 in
-a | --action )
ACTION=$2
shift 1
;;
-h | --hosts )
HOSTS=$2
shift 1
;;
esac
shift
done
if [[ $ACTION == "single" ]] ; then
upgrade_single "$HOSTS"
elif [[ $ACTION == "cluster" ]] ; then
validate_type "$HOSTS"
upgrade_cluster "$HOSTS"
else
echo "You have provided wrong ACTION: $ACTION !"
echo "ACTION allowed single or cluster."
fi