phpMyAdminがSourceForgeから撤退した以上、今新しいphpMyAdminの更新スクリプトは必要になる。
この前にもごく簡単なスクリプトを利用してアップデートしたけど、今phpMyAdmin自身のサイトはhttp://xxxx/latest/downloadという固定型の更新リンクを対応してないから、今回の新しい方はアップデートチェックやバージョンの比較も対応しなきゃいけない。
さて、閑話休題、早速新しいスクリプトを紹介しよう。
. ├── current ├── latest └── update_phpmyadmin.sh
初めての利用する前にはcurrentというファイルに今phpMyAdminのバージョンを書き込まなきゃ、じゃないとこのスクリプトは正常にバージョンの比較できなくなる。
user@host:~/scripts/phpmyadmin$ cat current 4.4.11
$PHPMYADMIN_HOMEと$VERSION_CHKこの2つの変数を変更することを忘れずにね
#!/bin/bash
SCRIPT_HOME=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
PHPMYADMIN_HOME="/var/www/phpmyadmin"
TIMESTAMP=`date "+%s%N"`
VERSION_CHK="https://domain.com/phpmyadmin/version_check.php?&_nocache=""$TIMESTAMP"
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
if [[ `whoami` != "root" ]]; then
echo "Please run as root"
exit 1
fi
cd $SCRIPT_HOME
curl "$VERSION_CHK" 2>/dev/null | sed -r "s/.*version\":\"([0-9\\.]*)\".*/\\1/" > latest
CURRENT=`cat current`
LATEST=`cat latest`
echo "The current version is: $CURRENT"
echo "The latest version is: $LATEST"
vercomp $CURRENT $LATEST
case $? in
0) echo "No updates"; exit 0;;
1) echo "You are ahead of the latest one?!"; exit 1;;
2) echo "Updating to $LATEST from $CURRENT, are your sure? [y/n]";;
esac
read CONTINUE
if [[ $CONTINUE != "y" ]]; then
exit 0
fi
wget --content-disposition "https://files.phpmyadmin.net/phpMyAdmin/$LATEST/phpMyAdmin-$LATEST-all-languages.tar.xz"
TAR_FILE=`find $SCRIPT_HOME -name "phpMyAdmin-*.tar.xz" -print`
if [[ -z $TAR_FILE ]]; then
echo "Download failed"
else
echo "$TAR_FILE is successfully download"
tar Jxvf $TAR_FILE
TAR_DIRECTORY=`find $SCRIPT_HOME -name "phpMyAdmin-*" -type d -print`
cp "$PHPMYADMIN_HOME/config.inc.php" "$TAR_DIRECTORY/"
rm -rf "$PHPMYADMIN_HOME"
mv "$TAR_DIRECTORY" "$PHPMYADMIN_HOME"
#do a chown if you need
#chown user:group "$PHPMYADMIN_HOME" -R
echo "phpMyAdmin successfully updated"
rm $TAR_FILE
echo $LATEST > current
echo "All done"
fi
