-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgecoscc-ini-fixer.sh
196 lines (164 loc) · 6.63 KB
/
gecoscc-ini-fixer.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
LANG="C"
DATE=`date +%Y%m%d%H%M%S`
PWD=`pwd`
SUPERV="/etc/init.d/supervisord"
GCC221="https://github.com/gecos-team/gecoscc-ui/archive/2.2.1.tar.gz"
NGINXC="/opt/nginx/etc/sites-enabled/gecoscc.conf"
CHEFPK="https://packages.chef.io/files/stable/chef/13.5.3/el/6/chef-13.5.3-1.el6.x86_64.rpm"
CHEFCL="chef-13.5.3-1.el6.x86_64"
function updateGECOSCC() {
echo "found outdated version of GECOSCC --> updating... "
$SUPERV stop
local OLDVER="2.2.0"
local NEWVER="2.2.1"
cp -r /opt/gecosccui-$OLDVER /opt/gecosccui-$NEWVER
sed -i 's|/opt/gecosccui-2.2.0|/opt/gecosccui-2.2.1|g' $SUPERV
sed -i 's|/opt/gecosccui-2.2.0|/opt/gecosccui-2.2.1|g' /opt/gecosccui-$NEWVER/bin/*
sed -i 's|/opt/gecosccui-2.2.0|/opt/gecosccui-2.2.1|g' /opt/gecosccui-$NEWVER/gecoscc.ini
sed -i 's|/opt/gecosccui-2.2.0|/opt/gecosccui-2.2.1|g' /opt/gecosccui-$NEWVER/supervisord.conf
cd /tmp
curl -s -L -O $GCC221
mkdir -p /tmp/$DATE
tar xfz 2.2.1.tar.gz -C /tmp/$DATE
source /opt/rh/python27/enable
source /opt/gecosccui-$NEWVER/bin/activate
cd /tmp/$DATE/gecoscc-ui-2.2.1
python setup.py build
python setup.py install
easy_install dist/gecoscc-2.2.1-py2.7.egg
cd /opt/gecosccui-$NEWVER/lib/python2.7/site-packages/gecoscc-2.2.1-py2.7.egg
cp -r * /opt/gecosccui-$NEWVER/lib/python2.7/site-packages/
chown -R gecoscc:gecoscc /opt/gecosccui-$NEWVER/sessions
chown -R gecoscc:gecoscc /opt/gecosccui-$NEWVER/supervisor
chown -R gecoscc:gecoscc /opt/gecosccui-$NEWVER/supervisord.conf
$SUPERV start
echo 'done.'
}
function processGecosccini() {
local CHANGED='no'
echo -n "backing up $GCCINI on $GCCINI-$DATE... "
cp -f $GCCINI $GCCINI-$DATE
echo 'done.'
if [ `grep -c "http://forja.guadalinex.org/webs/gecos/doc/v2/doku.php" $GCCINI` -eq '1' ] ; then
echo -n "found wrong help URL --> changing... " && \
sed -i 's|^help_manual_url = http://forja.guadalinex.org/webs/gecos/doc/v2/doku.php|help_manual_url = https://github.com/gecos-team/gecos-doc/wiki/Politicas:|' $GCCINI && \
CHANGED='yes' && \
echo 'done.'
fi
if [ `grep -c "^worker_class = gevent" $GCCINI` -eq '1' ] ; then
echo -n "found wrong gevent definition --> changing... " && \
sed -i 's/^worker_class = gevent/worker_class = gecoscc.socks.GecosGeventSocketIOWorker/' $GCCINI && \
CHANGED='yes' && \
echo 'done.'
fi
if [ `grep -c "v2.gecos.guadalinex.org/gems" $GCCINI` -eq '1' ] ; then
echo -n "found wrong gems repository --> changing... " && \
sed -i 's|^firstboot_api.gem_repo = http://v2.gecos.guadalinex.org/gems|firstboot_api.gem_repo = http://v3.gecos.guadalinex.org/gems|' $GCCINI && \
CHANGED='yes' && \
echo 'done.'
fi
if [ `grep -c "^timeout = 600" $GCCINI` -eq '1' ] ; then
echo -n "found wrong timeout --> changing... " && \
sed -i 's/^timeout = 600/timeout = 1800/' $GCCINI && \
CHANGED='yes' && \
echo 'done.'
fi
if [ `grep -c "http://v3.gecos.guadalinex.org/gecos/" $GCCINI` -eq '0' ] ; then
echo -n "found no Guadalinex v3 repos --> changing... " && \
sed -i 's|"http://v2.gecos.guadalinex.org/gecos/",|"http://v2.gecos.guadalinex.org/gecos/", "http://v3.gecos.guadalinex.org/gecos/",|' $GCCINI && \
sed -i 's|"http://v2.gecos.guadalinex.org/ubuntu/",|"http://v2.gecos.guadalinex.org/ubuntu/", "http://v3.gecos.guadalinex.org/ubuntu/",|' $GCCINI && \
sed -i 's|"http://v2.gecos.guadalinex.org/mint/"|"http://v2.gecos.guadalinex.org/mint/", "http://v3.gecos.guadalinex.org/mint/"|' $GCCINI && \
CHANGED='yes' && \
echo 'done.'
fi
if [ `grep -c "GECOS_VERSION" $GCCINI` -gt '0' ] ; then
echo -n "found \$GECOS_VERSION variable --> changing... " && \
sed -i "s/\${GECOS_VERSION}/$GCCVER/g" $GCCINI && \
CHANGED='yes' && \
echo 'done.'
fi
if [ x$CHANGED = 'xno' ] ; then
echo -n "there had been no changes, deleting backup file... "
[ -f $GCCINI-$DATE ] && rm -f $GCCINI-$DATE
echo 'done.'
fi
}
function processNginxConf() {
if [ `grep -c proxy_http_version $NGINXC` -eq '0' ] ; then
echo -n "nginx has no proxy_http_version definition --> changing... " && \
sed -i '/proxy_pass http:\/\/@app;/a\\n proxy_http_version 1.1;' $NGINXC
echo 'done.'
/etc/init.d/nginx restart
fi
}
function updatePackagesLists() {
if [ -x $GCCDIR/bin/pmanage ] ; then
local LOG="$PWD/`date +%Y%m%d`_packages_list_upgrade.log"
echo 'upgrading lists of packages...'
[ -f /opt/rh/python27/enable ] && source /opt/rh/python27/enable
[ -f $GCCDIR/bin/activate ] && source $GCCDIR/bin/activate
echo "a file called $LOG will contain all the output from this process"
$GCCDIR/bin/pmanage $GCCINI synchronize_repositories >> $LOG 2>&1
echo 'done.'
else
echo "WARNING: packages list upgrade hasn't been done because there is no pmanage executable"
fi
}
if [ ! $(id -u) = 0 ]; then
echo 'ERROR: you must be root to run this script'
exit 1
fi
if [ ! -f $SUPERV ] ; then
echo "ERROR: $SUPERV not found."
exit 1
else
CURVER=`grep '^EXECUTE=' $SUPERV | cut -d/ -f3 | cut -d- -f2`
if [ $CURVER != '2.2.1' ] ; then
updateGECOSCC
else
echo -n "Right version of gecoscc-ui has been detected. Do you want to overwrite it? (y/N): "
read OVERWR
if [ x"$OVERWR" = 'xy' ] ; then
echo "Overwriting gecoscc-ui... "
$SUPERV stop
sed -i 's/2.2.1/2.2.0/g' $SUPERV
mv /opt/gecosccui-$CURVER /opt/gecosccui-$CURVER-$DATE
echo "done."
echo "Former directory has been moved to /opt/gecosccui-$CURVER-$DATE"
echo -n "Now will go through updating process. Press enter to continue... "
read
updateGECOSCC
else
echo "Doing nothing."
fi
fi
fi
GCCVER='2.2.1'
GCCDIR="/opt/gecosccui-$GCCVER"
GCCINI="$GCCDIR/gecoscc.ini"
PY_GCC="$GCCDIR/lib/python2.7/site-packages/gecoscc"
if [ ! -f $GCCINI ] ; then
echo "ERROR: $GCCINI not found"
echo 'Is this a real GECOSCC server?'
exit 1
else
processGecosccini
fi
if [ ! -f $NGINXC ] ; then
echo "ERROR: $NGINXC not found"
exit 1
else
processNginxConf
fi
if [ x`rpm -qa chef` != x$CHEFCL ] ; then
echo "chef package not found, installing version 13.5.3 --> installing... " && \
rpm -Uvh $CHEFPK && \
echo 'done.'
fi
echo 'restarting GECOSCC to apply changes...'
$SUPERV restart
echo 'done.'
updatePackagesLists
exit 0