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+
67old_ee_version=" 2.2.3"
78branch=$1
89
10+ # Define echo function
911# Blue color
1012
1113function ee_lib_echo()
@@ -23,6 +25,28 @@ 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 pre depedencies"
43+ apt-get -y install python3 python3-apt python3-setuptools python3-dev sqlite3 git
44+ if [[ $? -ne 0 ]]; then
45+ ee_lib_echo_fail " Unable to install pre depedencies"
46+ exit 1
47+ fi
48+ }
49+
2650function sync_db()
2751{
2852 mkdir /var/lib/ee
@@ -122,103 +146,96 @@ function sync_db()
122146}
123147
124148
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
149+ function install_ee3()
150+ {
151+ # Remove old clone of EasyEngine (ee) if any
152+ rm -rf /tmp/easyengine & >> /dev/null
137153
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
154+ # Clone EE 3.0 Python branch
155+ ee_lib_echo " Cloning EasyEngine 3.0"
156+ if [ " $branch " = " " ]; then
157+ branch=python
158+ fi
145159
146- # Capture errors
147- function ee_lib_error()
148- {
149- echo " [ ` date` ] $( tput setaf 1) $@ $( tput sgr0) "
150- exit $2
151- }
160+ 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
152161
153- # Execute: apt-get update
154- ee_lib_echo " Executing apt-get update "
155- apt-get update & >> /dev/null
162+ cd /tmp/easyengine
163+ ee_lib_echo " Installing EasyEngine 3.0 "
164+ python3 setup.py install || ee_lib_error " Unable to install EasyEngine 3.0, exit status " 1
156165
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
166+ }
164167
165- # Install sqlite3
166- ee_lib_echo " Installing sqlite3"
167- apt-get -y install sqlite3
168+ function update_to_ee3()
169+ {
170+ # Preserve old configuration
171+ ee_lib_echo " Updating EasyEngine 3.0 configuration"
172+
173+ grant_host=$( grep grant-host /etc/easyengine/ee.conf | awk ' { print $3 }' )
174+ db_name=$( grep db-name /etc/easyengine/ee.conf | awk ' { print $3 }' )
175+ db_user=$( grep db-name /etc/easyengine/ee.conf | awk ' { print $3 }' )
176+ wp_prefix=$( grep prefix /etc/easyengine/ee.conf | awk ' { print $3 }' )
177+ wp_user=$( grep ' user ' /etc/easyengine/ee.conf | grep -v db-user | awk ' { print $3 }' )
178+ wp_pass=$( grep password /etc/easyengine/ee.conf | awk ' { print $3 }' )
179+ wp_email=$( grep email /etc/easyengine/ee.conf | awk ' { print $3 }' )
180+ ip_addr=$( grep ip-address /etc/easyengine/ee.conf | awk -F' =' ' { print $2 }' )
181+
182+ sed -i " s/ip-address.*/ip-address = ${ip_addr} /" /etc/ee/ee.conf && \
183+ sed -i " s/grant-host.*/grant-host = ${grant_host} /" /etc/ee/ee.conf && \
184+ sed -i " s/db-name.*/db-name = ${db-name} /" /etc/ee/ee.conf && \
185+ sed -i " s/db-user.*/db-user = ${db_user} /" /etc/ee/ee.conf && \
186+ sed -i " s/prefix.*/prefix = ${wp_prefix} /" /etc/ee/ee.conf && \
187+ sed -i " s/^user.*/user = ${wp_user} /" /etc/ee/ee.conf && \
188+ sed -i " s/password.*/password = ${wp_password} /" /etc/ee/ee.conf && \
189+ sed -i " s/email.*/email = ${wp_email} /" /etc/ee/ee.conf || ee_lib_error " Unable to update configuration, exit status " 1
190+
191+
192+ # Remove old EasyEngine
193+ ee_lib_echo " Removing EasyEngine 2"
194+ 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
168195
169- if [[ $? -ne 0 ]]; then
170- ee_lib_echo_fail " Unable to install sqlite3 on system"
171- exit 1
172- fi
196+ }
173197
174- sync_db
198+ function git_init()
199+ {
200+ # Do git intialisation on EasyEngine configuration
201+ cd /etc/ee
202+ if [ ! -d /etc/ee/.git ]; then
203+ git init > /dev/null
204+ fi
205+ git add .
206+ git commit -am " Installed/Updated to EasyEngine 3" > /dev/null
175207
176- # Remove old version of EasyEngine (ee)
177- rm -rf /tmp/easyengine & >> /dev/null
208+ }
178209
179- # Clone EE 3.0 Python branch
180- ee_lib_echo " Cloning EasyEngine 3.0"
181- if [ " $branch " = " " ]; then
182- branch=python
210+ # Checking permissions
211+ if [[ $EUID -ne 0 ]]; then
212+ ee_lib_echo_fail " Sudo privilege required..."
213+ ee_lib_echo_fail " Uses: wget -qO ee rt.cx/ee && sudo bash ee"
214+ exit 1
183215fi
184216
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
217+ # Check old EasyEngine is installed or not
218+ if [ ! -f /usr/local/sbin/easyengine ]; then
219+ # Check latest EasyEngine is installed or not
220+ if [ ! -f /usr/local/bin/ee ]; then
221+ install_dep
222+ install_ee3
223+ git_init
224+ else
225+ ee_lib_echo_fail " EasyEngine 3 allready installed on ur system"
226+ exit 1
227+ fi
228+ else
229+ # Check old EasyEngine version
230+ ee version | grep ${old_ee_version} & >> /dev/null
231+ if [[ $? -ne 0 ]]; then
232+ ee_lib_echo_fail " EasyEngine $old_ee_version not found on your system"
233+ ee_lib_echo_fail " Please update it using command: ee update"
234+ exit 1
235+ fi
236+ install_dep
237+ sync_db
238+ install_ee3
239+ update_to_ee3
240+ git_init
221241fi
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