-
Notifications
You must be signed in to change notification settings - Fork 383
/
restyaboard_uninstall.sh
140 lines (123 loc) · 4.32 KB
/
restyaboard_uninstall.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
#!/bin/bash
#
# Restyaboard uninstall
#
# Usage: ./restyaboard_uninstall.sh
#
# Copyright (c) 2014-2019 Restya.
# Dual License (OSL 3.0 & Commercial License)
{
if [[ $EUID -ne 0 ]];
then
echo "This script must be run as root"
exit 1
fi
POSTGRES_DBHOST=localhost
POSTGRES_DBNAME=restyaboard
POSTGRES_DBUSER=restya
POSTGRES_DBPASS=hjVl2!rGd
POSTGRES_DBPORT=5432
DOWNLOAD_DIR=/opt/restyaboard
version=$(cat ${DOWNLOAD_DIR}/release)
set -x
whoami
echo $(cat /etc/issue)
OS_REQUIREMENT=$(lsb_release -i -s)
if ([ "$OS_REQUIREMENT" = "" ])
then
echo "lsb_release is not enabled, please install \"yum install -y redhat-lsb-core\" command before running uninstall script"
exit 1
fi
set +x
echo -e "Uninstall script will uninstall version ${version}, drop database ${POSTGRES_DBNAME} with user ${POSTGRES_DBUSER} and password ${POSTGRES_DBPASS}, installed files and its directories which are related to restyaboard, crons and nginx configuration. To continue enter \"y\" or to quit the process and edit the version and database details enter \"n\" (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
set +x
echo "Enter the reason for uninstalling the Restyaboard:"
read -r reason
while [[ -z "$reason" ]]
do
read -r -p "Enter the reason for uninstalling the Restyaboard:" reason
done
curl -v -L -G -d "app=board&ver=${version}&reason=${reason}&os=${OS_REQUIREMENT}" "https://restya.com/uninstall.php"
set +x
echo "Enter your document root (where your Restyaboard was installed. e.g., /usr/share/nginx/html/restyaboard):"
read -r dir
while [[ -z "$dir" ]]
do
read -r -p "Enter your document root (where your Restyaboard was installed. e.g., /usr/share/nginx/html/restyaboard):" dir
done
echo "Removing PostgreSQL user and database..."
psql -U postgres -c "DROP USER IF EXISTS ${POSTGRES_DBUSER};"
psql -U postgres -c "DROP DATABASE ${POSTGRES_DBNAME};"
echo "Removing Restyaboard files and its directories..."
rm -rf $dir
echo "Removing Restyaboard conf file"
rm -rf /etc/nginx/conf.d/restyaboard.conf
echo "Removing Restyaboard temporary files..."
rm -rf "$dir/tmp/cache/restya_site_url_for_shell.php"
rm -rf "$dir/tmp/cache/restya_client_information.php"
echo "Clearing the Restyaboard crons"
sed -i '/\*\/5 \* \* \* \* $dir\/server\/php\/shell\/instant_email_notification.sh > \/dev\/null 2> \/dev\/null/d' /var/spool/cron/crontabs/root
sed -i '/\0 \* \* \* \* $dir\/server\/php\/shell\/periodic_email_notification.sh > \/dev\/null 2> \/dev\/null/d' /var/spool/cron/crontabs/root
sed -i '/\*\/30 \* \* \* \* $dir\/server\/php\/shell\/imap.sh > \/dev\/null 2> \/dev\/null/d' /var/spool/cron/crontabs/root
sed -i '/\*\/5 \* \* \* \* $dir\/server\/php\/shell\/card_due_notification.sh > \/dev\/null 2> \/dev\/null/d' /var/spool/cron/crontabs/root
sed -i '/\*\/5 \* \* \* \* $dir\/server\/php\/shell\/webhook.sh > \/dev\/null 2> \/dev\/null/d' /var/spool/cron/crontabs/root
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
set +x
echo "Uninstall script is going to uninstall PHP, are you sure want to remove (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
apt-get remove php* -y
apt-get purge php* -y
esac
set +x
echo "Uninstall script is going to uninstall PostgreSQL, are you sure want to remove (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
apt-get --purge remove postgresql-* -y
esac
set +x
echo "Uninstall script is going to uninstall nginx, are you sure want to remove (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
apt-get purge nginx nginx-common -y
esac
else
set +x
echo "Uninstall script is going to uninstall PHP, are you sure want to remove (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
yum remove php*
esac
set +x
echo "Uninstall script is going to uninstall PostgreSQL, are you sure want to remove (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
yum remove postgresql-*
esac
set +x
echo "Uninstall script is going to uninstall nginx, are you sure want to remove (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
yum remove nginx
esac
fi
rm -rf ${DOWNLOAD_DIR}/release
esac
} 2>&1 | tee -a restyaboard_uninstall.log