-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade_phpMyAdmin.sh
executable file
·135 lines (111 loc) · 3.46 KB
/
upgrade_phpMyAdmin.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
#!/bin/bash
abort() {
echo '
***************
*** ABORTED ***
***************
' >&2
echo "An error occurred on line $1. Exiting..." >&2
date -Iseconds >&2
exit 1
}
trap 'abort $LINENO' ERR
set -e -o pipefail
quit() {
trap : 0
exit 0
}
# Asks if [Yn] if script shoud continue, otherwise exit 1
# $1: msg or nothing
# Example call 1: askContinueYn
# Example call 1: askContinueYn "Backup DB?"
askContinueYn() {
if [[ $1 ]]; then
msg="$1 "
else
msg=""
fi
# http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias
read -e -p "${msg}Continue? [Y/n] " response
response=${response,,} # tolower
if [[ $response =~ ^(yes|y|)$ ]] ; then
# echo ""
# OK
:
else
echo "Aborted"
exit 1
fi
}
# https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8
echo "Checking PHPMyAdmin version..."
# TAG=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
VERSION=$(curl -sL https://www.phpmyadmin.net/downloads/ | grep -e "<h2[^>]*>phpMyAdmin .*</h2>" | perl -pe's%.*<h2[^>]*>phpMyAdmin (\d+\.\d+\.\d+)</h2>.*%\1%' | head -1)
echo
# read -e -p "Upgrade to version (e.g. 0.59.0): " VERSION
interactive=true
check_version=true
while test $# -gt 0; do
case $1 in
-h|--help)
echo "Upgrade phpMyAdmin"
echo
echo "$0 [options]"
echo
echo "Options:"
echo "-a Automatic mode"
echo "-C Ignore version check"
echo "-h, --help Help"
quit
;;
-a)
interactive=false
shift
;;
-C)
check_version=false
shift
;;
esac
done
BIN="public_html"
DOWNLOADS="."
DEST="phpmyadmin"
OLDVERSION=$(cat $BIN/$DEST/_VERSION.txt || echo "")
echo -e "\nUpgrade phpMyAdmin $VERSION"
echo -e "Current version: $OLDVERSION\n"
if [ "$VERSION" = "$OLDVERSION" ] && $check_version; then
echo "Versions are equal."
quit
fi
NAME="phpMyAdmin-$VERSION-all-languages"
GZ="$NAME.tar.gz"
cmd="wget --trust-server-names https://files.phpmyadmin.net/phpMyAdmin/$VERSION/phpMyAdmin-$VERSION-all-languages.tar.gz -O $DOWNLOADS/$GZ"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="echo -e '\nSize [Byte]'; stat --printf='%s\n' $DOWNLOADS/$GZ; echo -e '\nMD5'; md5sum $DOWNLOADS/$GZ; echo -e '\nSHA256'; sha256sum $DOWNLOADS/$GZ;"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="mkdir -p $BIN/$NAME; tar -xzf $DOWNLOADS/$GZ -C $BIN"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="echo $VERSION > $BIN/$NAME/_VERSION.txt; echo $VERSION > $BIN/$NAME/_VERSION_$VERSION.txt"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="[ -d $DEST.old ] && rm -r $DEST.old || echo 'No old dir to delete'"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="mv -iT $BIN/$DEST $DEST.old"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="mv -iT $BIN/$NAME $BIN/$DEST"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="cp -ir $DEST.old/.htaccess $DEST.old/.well-known $DEST.old/config.inc.php $BIN/$DEST"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
cmd="rm $DOWNLOADS/$GZ"
if $interactive ; then askContinueYn "$cmd"; fi
eval "$cmd"
echo -e "\nUpdate done!"
quit