Skip to content

Commit 46c473b

Browse files
author
gau1991
committed
Merged install and update script to single script
1 parent 02c1720 commit 46c473b

File tree

1 file changed

+115
-90
lines changed

1 file changed

+115
-90
lines changed

upgrade renamed to install

Lines changed: 115 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
22

33
# EasyEngine update script.
4-
# This script is designed to update current EasyEngine from 2.2.2 to 3.x
5-
# Define echo function
4+
# This script is designed to install latest EasyEngine or
5+
# to update current EasyEngine from 2.x to 3.x
6+
67
old_ee_version="2.2.3"
78
branch=$1
89

10+
# Define echo function
911
# Blue color
1012

1113
function ee_lib_echo()
@@ -23,6 +25,36 @@ function ee_lib_echo_fail()
2325
echo $(tput setaf 1)$@$(tput sgr0)
2426
}
2527

28+
# Capture errors
29+
function ee_lib_error()
30+
{
31+
echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)"
32+
exit $2
33+
}
34+
35+
function install_dep()
36+
{
37+
# Execute: apt-get update
38+
ee_lib_echo "Executing apt-get update"
39+
apt-get update &>> /dev/null
40+
41+
# Install Python3 on users system
42+
ee_lib_echo "Installing Python3"
43+
apt-get -y install python3 python3-apt python3-setuptools python3-dev
44+
if [[ $? -ne 0 ]]; then
45+
ee_lib_echo_fail "Unable to install Python3 on system"
46+
exit 1
47+
fi
48+
49+
# Install sqlite3
50+
ee_lib_echo "Installing sqlite3"
51+
apt-get -y install sqlite3
52+
if [[ $? -ne 0 ]]; then
53+
ee_lib_echo_fail "Unable to install sqlite3 on system"
54+
exit 1
55+
fi
56+
}
57+
2658
function sync_db()
2759
{
2860
mkdir /var/lib/ee
@@ -122,103 +154,96 @@ function sync_db()
122154
}
123155

124156

125-
# Checking permissions
126-
if [[ $EUID -ne 0 ]]; then
127-
ee_lib_echo_fail "Sudo privilege required..."
128-
ee_lib_echo_fail "Uses: wget -qO ee rt.cx/ee && sudo bash ee"
129-
exit 1
130-
fi
131-
132-
# Check old EasyEngine is installed or not
133-
if [ ! -f /usr/local/sbin/easyengine ]; then
134-
ee_lib_echo_fail "EasyEngine 2.0 not found"
135-
exit 1
136-
fi
157+
function install_ee3()
158+
{
159+
# Remove old clone of EasyEngine (ee) if any
160+
rm -rf /tmp/easyengine &>> /dev/null
137161

138-
# Check old EasyEngine version
139-
ee version | grep ${old_ee_version} &>> /dev/null
140-
if [[ $? -ne 0 ]]; then
141-
ee_lib_echo_fail "EasyEngine $old_ee_version not found on your system"
142-
ee_lib_echo_fail "Please update is using command: ee update"
143-
exit 1
144-
fi
162+
# Clone EE 3.0 Python branch
163+
ee_lib_echo "Cloning EasyEngine 3.0"
164+
if [ "$branch" = "" ]; then
165+
branch=python
166+
fi
145167

146-
# Capture errors
147-
function ee_lib_error()
148-
{
149-
echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)"
150-
exit $2
151-
}
168+
git clone -b $branch https://github.com/rtCamp/easyengine.git /tmp/easyengine --quiet > /dev/null || ee_lib_error "Unable to clone EasyEngine, exit status" 1
152169

153-
# Execute: apt-get update
154-
ee_lib_echo "Executing apt-get update"
155-
apt-get update &>> /dev/null
170+
cd /tmp/easyengine
171+
ee_lib_echo "Installing EasyEngine 3.0"
172+
python3 setup.py install || ee_lib_error "Unable to install EasyEngine 3.0, exit status " 1
156173

157-
# Install Python3 on users system
158-
ee_lib_echo "Installing Python3"
159-
apt-get -y install python3 python3-apt python3-setuptools python3-dev
160-
if [[ $? -ne 0 ]]; then
161-
ee_lib_echo_fail "Unable to install Python3 on system"
162-
exit 1
163-
fi
174+
}
164175

165-
# Install sqlite3
166-
ee_lib_echo "Installing sqlite3"
167-
apt-get -y install sqlite3
176+
function update_to_ee3()
177+
{
178+
# Preserve old configuration
179+
ee_lib_echo "Updating EasyEngine 3.0 configuration"
180+
181+
grant_host=$(grep grant-host /etc/easyengine/ee.conf | awk '{ print $3 }')
182+
db_name=$(grep db-name /etc/easyengine/ee.conf | awk '{ print $3 }')
183+
db_user=$(grep db-name /etc/easyengine/ee.conf | awk '{ print $3 }')
184+
wp_prefix=$(grep prefix /etc/easyengine/ee.conf | awk '{ print $3 }')
185+
wp_user=$(grep 'user ' /etc/easyengine/ee.conf | grep -v db-user |awk '{ print $3 }')
186+
wp_pass=$(grep password /etc/easyengine/ee.conf | awk '{ print $3 }')
187+
wp_email=$(grep email /etc/easyengine/ee.conf | awk '{ print $3 }')
188+
ip_addr=$(grep ip-address /etc/easyengine/ee.conf |awk -F'=' '{ print $2 }')
189+
190+
sed -i "s/ip-address.*/ip-address = ${ip_addr}/" /etc/ee/ee.conf && \
191+
sed -i "s/grant-host.*/grant-host = ${grant_host}/" /etc/ee/ee.conf && \
192+
sed -i "s/db-name.*/db-name = ${db-name}/" /etc/ee/ee.conf && \
193+
sed -i "s/db-user.*/db-user = ${db_user}/" /etc/ee/ee.conf && \
194+
sed -i "s/prefix.*/prefix = ${wp_prefix}/" /etc/ee/ee.conf && \
195+
sed -i "s/^user.*/user = ${wp_user}/" /etc/ee/ee.conf && \
196+
sed -i "s/password.*/password = ${wp_password}/" /etc/ee/ee.conf && \
197+
sed -i "s/email.*/email = ${wp_email}/" /etc/ee/ee.conf || ee_lib_error "Unable to update configuration, exit status " 1
198+
199+
200+
# Remove old EasyEngine
201+
ee_lib_echo "Removing EasyEngine 2"
202+
rm -rf /etc/bash_completion.d/ee /etc/easyengine/ /usr/share/easyengine/ /usr/local/lib/easyengine /usr/local/sbin/easyengine /usr/local/sbin/ee /var/log/easyengine
168203

169-
if [[ $? -ne 0 ]]; then
170-
ee_lib_echo_fail "Unable to install sqlite3 on system"
171-
exit 1
172-
fi
204+
}
173205

174-
sync_db
206+
function git_init()
207+
{
208+
# Do git intialisation on EasyEngine configuration
209+
cd /etc/ee
210+
if [ ! -d /etc/ee/.git ]; then
211+
git init > /dev/null
212+
fi
213+
git add .
214+
git commit -am "Installed/Updated to EasyEngine 3" > /dev/null
175215

176-
# Remove old version of EasyEngine (ee)
177-
rm -rf /tmp/easyengine &>> /dev/null
216+
}
178217

179-
# Clone EE 3.0 Python branch
180-
ee_lib_echo "Cloning EasyEngine 3.0"
181-
if [ "$branch" = "" ]; then
182-
branch=python
218+
# Checking permissions
219+
if [[ $EUID -ne 0 ]]; then
220+
ee_lib_echo_fail "Sudo privilege required..."
221+
ee_lib_echo_fail "Uses: wget -qO ee rt.cx/ee && sudo bash ee"
222+
exit 1
183223
fi
184224

185-
git clone -b $branch https://github.com/rtCamp/easyengine.git /tmp/easyengine > /dev/null || ee_lib_error "Unable to clone EasyEngine, exit status" 1
186-
187-
cd /tmp/easyengine
188-
ee_lib_echo "Installing EasyEngine 3.0"
189-
python3 setup.py install || ee_lib_error "Unable to install EasyEngine 3.0, exit status " 1
190-
191-
# Preserve old configuration
192-
ee_lib_echo "Updating EasyEngine 3.0 configuration"
193-
194-
grant_host=$(grep grant-host /etc/easyengine/ee.conf | awk '{ print $3 }')
195-
db_name=$(grep db-name /etc/easyengine/ee.conf | awk '{ print $3 }')
196-
db_user=$(grep db-name /etc/easyengine/ee.conf | awk '{ print $3 }')
197-
wp_prefix=$(grep prefix /etc/easyengine/ee.conf | awk '{ print $3 }')
198-
wp_user=$(grep 'user ' /etc/easyengine/ee.conf | grep -v db-user |awk '{ print $3 }')
199-
wp_pass=$(grep password /etc/easyengine/ee.conf | awk '{ print $3 }')
200-
wp_email=$(grep email /etc/easyengine/ee.conf | awk '{ print $3 }')
201-
ip_addr=$(grep ip-address /etc/easyengine/ee.conf |awk -F'=' '{ print $2 }')
202-
203-
sed -i "s/ip-address.*/ip-address = ${ip_addr}/" /etc/ee/ee.conf && \
204-
sed -i "s/grant-host.*/grant-host = ${grant_host}/" /etc/ee/ee.conf && \
205-
sed -i "s/db-name.*/db-name = ${db-name}/" /etc/ee/ee.conf && \
206-
sed -i "s/db-user.*/db-user = ${db_user}/" /etc/ee/ee.conf && \
207-
sed -i "s/prefix.*/prefix = ${wp_prefix}/" /etc/ee/ee.conf && \
208-
sed -i "s/^user.*/user = ${wp_user}/" /etc/ee/ee.conf && \
209-
sed -i "s/password.*/password = ${wp_password}/" /etc/ee/ee.conf && \
210-
sed -i "s/email.*/email = ${wp_email}/" /etc/ee/ee.conf || ee_lib_error "Unable to update configuration, exit status " 1
211-
212-
213-
# Remove old EasyEngine
214-
ee_lib_echo "Removing EasyEngine 2"
215-
rm -rf /etc/bash_completion.d/ee /etc/easyengine/ /usr/share/easyengine/ /usr/local/lib/easyengine /usr/local/sbin/easyengine /usr/local/sbin/ee /var/log/easyengine
216-
217-
ee_lib_echo "Doing GIT init"
218-
cd /etc/ee
219-
if [ ! -d /etc/ee/.git ]; then
220-
git init > /dev/null
225+
# Check old EasyEngine is installed or not
226+
if [ ! -f /usr/local/sbin/easyengine ]; then
227+
# Check latest EasyEngine is installed or not
228+
if [ ! -f /usr/local/bin/ee ]; then
229+
install_dep
230+
install_ee3
231+
git_init
232+
else
233+
ee_lib_echo_fail "EasyEngine 3 allready installed on ur system"
234+
exit 1
235+
fi
236+
else
237+
# Check old EasyEngine version
238+
ee version | grep ${old_ee_version} &>> /dev/null
239+
if [[ $? -ne 0 ]]; then
240+
ee_lib_echo_fail "EasyEngine $old_ee_version not found on your system"
241+
ee_lib_echo_fail "Please update it using command: ee update"
242+
exit 1
243+
fi
244+
sync_db
245+
install_dep
246+
install_ee3
247+
update_to_ee3
248+
git_init
221249
fi
222-
git commit -am "Update EasyEngine 2 to EasyEngine 3" > /dev/null
223-
224-
ee_lib_echo "Successfully update to EasyEngine 3"

0 commit comments

Comments
 (0)