-
Notifications
You must be signed in to change notification settings - Fork 9
/
pma-update.sh
executable file
·230 lines (177 loc) · 5.96 KB
/
pma-update.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/sh
##
# PHPMYADMIN UPDATE SCRIPT
# https://github.com/stefansl/pma-updatescript/
# Author: Stefan Schulz-Lauterbach, Michael Riehemann, Igor Buyanov
##
# SETTINGS
# Please check this settings. Without changing
# location and pma your installation will not work!
#
# Instead of changing these values below,
# you can place them in a .pma-updaterc file in the
# home folder from the user this script runs as.
##
LOCATION="" # Directory of PMA installation. Without a slash at the end. For example: LOCATION="/var/www"
PMA="" # Name of the PMA folder. For example: pma or phpMyAdmin
LANGUAGE="" # Language of PMA. Leave it blank for all languages or specify a language pack, for example: english
USER="" # User of files
GROUP="" # Group of files
CTYPE="tar.gz" # Compression type. default "tar.gz". tar.bz2 is possible, too.
LOGLEVEL=1 # set 0 for quiet mode (no output)
# set 1 to output warnings (DEFAULT)
# set 2 to output all messages
DELETE=0 # set 1 to delete directory examples
VERSIONLINK="https://www.phpmyadmin.net/home_page/version.php"
DOWNLOADURL="https://files.phpmyadmin.net/phpMyAdmin"
FORCE="off"
CONFIG_FILE=~/.pma-updaterc
################################################
# #
# DON'T CHANGE ANYTHING FROM HERE #
# unless you're not into shell scripting #
# #
################################################
# Output help
usage() {
echo "usage: sh pma-update.sh [-hvf] [-r version]";
echo "-h this help";
echo "-v output all warnings";
echo "-f force download, even if this version is installed already";
echo "-r version choose a different version than the latest.";
}
# If user based config exists, load it
if [ -f $CONFIG_FILE ]; then
command . $CONFIG_FILE;
fi
# Output warnings
log() {
if [ $LOGLEVEL -gt 0 ]; then
echo "$@";
fi
}
# Output additional messages
info() {
if [ $LOGLEVEL -eq 2 ]; then
echo "$@";
fi
}
# Options
params="$(getopt -o hvfr: -l help --name "$cmdname" -- "$@")"
if [ $? -ne 0 ]; then
usage
fi
eval set -- "$params"
unset params
while true
do
case "$1" in
-v) LOGLEVEL=2;;
-f) FORCE=on;;
-r) VERSION="$2"; shift;;
-h|--help)
usage
exit;;
--)
shift
break;;
*)
usage;;
esac
shift
done
# Check location settings
if [ -z "$LOCATION" -o -z "$PMA" ]; then
log "Please, check your settings. The variables LOCATION, PMA are mandatory!";
exit 1;
fi
# Get the local installed version
if [ -f $LOCATION/$PMA/README ]; then
VERSIONLOCAL=$(sed -n 's/^Version \(.*\)$/\1/p' $LOCATION/$PMA/README);
info "Found local installation version" $VERSIONLOCAL;
else
log "Did not found a working installation. Please, check the script settings.";
exit 1;
fi
# If $USER or $GROUP empty, read from installed phpMyAdmin
if [ -z "$USER" ]; then
USER=$(stat -c "%U" $LOCATION/$PMA/index.php);
fi
if [ -z "$GROUP" ]; then
GROUP=$(stat -c "%G" $LOCATION/$PMA/index.php);
fi
# Check user/group settings
if [ -z "$USER" -o -z "$GROUP" ]; then
log "Please, check your settings. Set USER and GROUP, please!";
exit 1;
fi
if [ -z "$LANGUAGE" ]; then
LANGUAGE="all-languages";
fi
# Get latest version
if [ -n "$VERSION" ]; then
# Check the versions
if [ "$VERSION" = "$VERSIONLOCAL" ]; then
info "phpMyAdmin $VERSIONLOCAL is already installed!";
if [ "$FORCE" != "on" ]; then
exit 0;
fi
info "I will install it anyway.";
fi
else
# Find out latest version
VERSION=$(wget -q -O /tmp/phpMyAdmin_Update.html $VERSIONLINK && sed -ne '1p' /tmp/phpMyAdmin_Update.html);
# Check the versions
if [ "$VERSION" = "$VERSIONLOCAL" ]; then
info "You have the latest version of phpMyAdmin installed!";
if [ "$FORCE" != "on" ]; then
exit 0;
fi
info "I will install it anyway.";
fi
fi
# Set output parameters
WGETLOG="-q";
VERBOSELOG="";
if [ "$CTYPE" = "tar.gz" ]; then
TARLOG="xzf";
elif [ "$CTYPE" = "tar.bz2" ]; then
TARLOG="xjf";
fi
if [ $LOGLEVEL -eq 2 ]; then
WGETLOG="-v";
VERBOSELOG="-v";
TARLOG=${TARLOG}v;
fi
# Start update
if [ -n "$VERSION" ]; then
cd $LOCATION;
MYLOCATION=`pwd`;
if [ $MYLOCATION != $LOCATION ]; then
log "An error occured while changing the directory. Please check your settings! Your given directory: $LOCATION";
pwd;
else
wget $WGETLOG --directory-prefix=$LOCATION $DOWNLOADURL/$VERSION/phpMyAdmin-$VERSION-$LANGUAGE.$CTYPE
if [ -f "$LOCATION/phpMyAdmin-$VERSION-$LANGUAGE.$CTYPE" ]; then
tar $TARLOG phpMyAdmin-$VERSION-$LANGUAGE.$CTYPE || exit 1;
mv $VERBOSELOG $LOCATION/$PMA/config.inc.php $LOCATION/phpMyAdmin-$VERSION-$LANGUAGE/
rm -R $VERBOSELOG $LOCATION/$PMA
mv $VERBOSELOG $LOCATION/phpMyAdmin-$VERSION-$LANGUAGE $LOCATION/$PMA
chown -R $VERBOSELOG $USER:$GROUP $LOCATION/$PMA
# Remove downloaded package
rm $VERBOSELOG phpMyAdmin-$VERSION-$LANGUAGE.$CTYPE
# Remove setup-folder for security issues
rm -R $VERBOSELOG $LOCATION/$PMA/setup
if [ $DELETE -eq 1 ]; then
# Remove examples-folder
rm -R $VERBOSELOG $LOCATION/$PMA/examples
fi
log "PhpMyAdmin successfully updated from version $VERSIONLOCAL to $VERSION in $LOCATION. Enjoy!"
else
log "An error occured while downloading phpMyAdmin. Downloading unsuccessful from: $DOWNLOADURL/$VERSION/phpMyAdmin-$VERSION-$LANGUAGE.$CTYPE.";
fi
fi
else
log "Something went wrong while getting the version of phpMyAdmin. :("
log "Maybe this link here is dead: $VERSIONLINK";
fi