Last active
March 17, 2022 20:19
-
-
Save SeinopSys/3fb639fd92adc33e2ae8 to your computer and use it in GitHub Desktop.
Bash script file for updating phpMyAdmin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# <Config> | |
backuppath="/path/to/backups" | |
pmapath="/path/to/phpMyAdmin" | |
# </Config> | |
# Colors | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
RESET='\033[0m' | |
echo "phpMyAdmin updater sh script - by @DJDavid98" | |
# Check paths | |
if ! [ -d "${backuppath}" ]; then | |
echo -e "${RED}Backup path is not a folder${RESET}"; | |
exit 1; | |
fi | |
if ! [ -d "${pmapath}" ]; then | |
echo -e "${RED}phpMyAdmin path is not a folder${RESET}"; | |
exit 1; | |
fi | |
# Check if first command line parameter is empty | |
if [ -z "$1" ] | |
then | |
# If yes, try getting latest version | |
echo -e "${YELLOW}ZIP file URL missing, looking for latest version...${RESET}" | |
url=$(curl -sL https://www.phpmyadmin.net/downloads/ | grep -Po '(?<=href=")https://files\.phpmyadmin\.net/phpMyAdmin/[\d\.]+/phpMyAdmin-[\d\.]+-english\.zip(?=")' -m 1) | |
if [ -z "$url" ] | |
then | |
echo -e "${RED}Couldn't find latest version${RESET}" | |
exit 1 | |
else | |
echo -e "${GREEN}Found latest version${RESET}" | |
fi | |
else | |
# otherwise, use speciied URL | |
url=$1 | |
fi | |
# Check if URL appears to be vaid | |
if ! [[ "$url" =~ ^https://files\.phpmyadmin\.net/phpMyAdmin/[0-9\.]+/phpMyAdmin-[0-9\.]+-(english|all-languages)\.zip$ ]]; | |
then | |
echo -e "${RED}Invalid ZIP file URL${RESET}" | |
exit 1 | |
fi | |
# Go to phpMyAdmin folder | |
cd ${pmapath} | |
# Backup user configuration | |
if [ -f config.inc.php ]; | |
then | |
echo "Backing up configuration..." | |
cp config.inc.php ${backuppath}/config.inc.php | |
fi | |
# Get ZIP file | |
echo "Downloading ZIP file..." | |
wget -O ${backuppath}/_pma.zip ${url} | |
if [ ! -f "${backuppath}/_pma.zip" ] | |
then | |
echo -e "${RED}File download failed, aborting${RESET}" | |
exit 1 | |
fi | |
# Empty folder and decompress ZIP | |
echo "Emptying folder..." | |
rm -R * | |
echo "Decompressing ZIP file..." | |
unzip -o ${backuppath}/_pma.zip -d . > /dev/null | |
rm ${backuppath}/_pma.zip | |
mv * _tmp | |
if [ -d "_tmp" ]; then | |
mv _tmp/* . | |
rm -R _tmp > /dev/null | |
fi | |
# Restore backed up configuration, if any | |
if [ -f "${backuppath}/config.inc.php" ]; | |
then | |
echo "Restoring configuration..." | |
cp ${backuppath}/config.inc.php config.inc.php | |
fi | |
# Finish | |
echo -e "${GREEN}phpMyAdmin updated${RESET}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment