-
Notifications
You must be signed in to change notification settings - Fork 8
/
remove
executable file
·157 lines (129 loc) · 3.8 KB
/
remove
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
#!/bin/bash
# MageSpawner Remover
#
# Copyright 2011-2013 Matthias Zeis
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# System Requirements:
# - bash
# - The following executables must be locatable in your $PATH
# mysql
#
version="0.6.0"
usage="\
MageSpawner Remover (v$version)
MageSpawner Remover is a tool for removing Magento installations set up by
MageSpawner.
THIS IS NOT MEANT TO BE USED ON PRODUCTION ENVIORNMENTS!
Usage:
./remove
Then follow the instructions on the screen.
Consult the README for further information.
Options:
--help display this help message
--usage display this help message
--version display the version of this script
--mageshopcode [code] code of the shop to be deleted
Get more information at
http://matthias-zeis.com"
###########################
## Common options: help, usage and version number
if [ "$1" = "--help" ]; then
echo "$usage"
exit 0
elif [ "$1" = "--usage" ]; then
echo "$usage"
exit 0
elif [ "$1" = "--version" ]; then
echo "$version"
exit 0
fi
###########################
## Parse the arguments
parse_arguments ()
{
while :
do
case $1 in
-h | --help | --usage | -\?)
echo "$usage"
exit 0
;;
--mageshopcode)
MAGE_SHOP_CODE=$2
shift 2
;;
--) # End of all options
shift
break
;;
-*)
echo "WARN: Unknown option (ignored): $1" >&2
shift
;;
*) # no more options. Stop while loop
break
;;
esac
done
return 0
}
###########################
## Get Magento shop (= subdomain) name.
get_mage_name ()
{
if [[ -z "$MAGE_SHOP_CODE" ]]; then
echo "Which shop do you want to uninstall? Provide only the subdomain part of the domains provided."
ls -1 ${MAGE_BASE_DIR}
while true; do
read -p "Shop code: " MAGE_SHOP_CODE
MAGE_SHOP_DIR="${MAGE_BASE_DIR}${MAGE_SHOP_CODE}.${MAGE_DOMAIN}"
if [ -d "${MAGE_SHOP_DIR}" ]; then
break;
else
break;
echo "Shop does not exist. Please retry."
fi
done
else
MAGE_SHOP_DIR="${MAGE_BASE_DIR}${MAGE_SHOP_CODE}.${MAGE_DOMAIN}"
fi
return 0
}
###########################
## Main script
parse_arguments "$@"
echo -e "Welcome to the Magento uninstall script.\n"
if [[ ! -f ${0%/*}/config.conf ]]; then
echo -e 'config.conf not found.\nPlease copy config.conf.sample to config.conf and adjust your settings.'
exit 1
fi
. ${0%/*}/config.conf
MYSQL=$(which mysql) || { echo >&2 'MySQL executable not found'; exit 1; }
if [ "$EUID" -ne 0 ] && [ "$LINUX_USE_SUDO" != "false" ]; then
CMDRM="sudo rm"
else
CMDRM="rm"
fi
get_mage_name
DB_NAME="${DB_NAMEPREFIX}${MAGE_SHOP_CODE}"
DB_SQL="DROP DATABASE ${DB_NAME};"
echo -e "\nDeleting files..."
$CMDRM -rf ${MAGE_SHOP_DIR}
echo -e "Files deleted.\n"
echo "Deleting database..."
$MYSQL -u${DB_USER} -p${DB_PASS} -e "${DB_SQL}"
echo -e "Database deleted.\n"
echo "Shop was deleted successfully. Please delete vhost entries and host config as needed."
exit