-
-
Save bonelifer/61fe94752242e6c914261870284fa3cc to your computer and use it in GitHub Desktop.
phpbb3 updater
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 | |
# Source: https://gist.github.com/yhojann-cl/37df5c5ee2300e7a7b3ff292703a63f3 | |
# Define username, domain, database name, translation language, local path, and remote path variables | |
USERNAME="hackerdev.net" | |
DOMAIN="hackerdev.net" | |
DB_NAME="hackerdev" | |
TRANS_LANGUAGE="spanish_formal_honorifics" | |
LOCAL_PATH="/home/localuser/public_html" | |
REMOTE_PATH="/home/remoteuser/public_html" | |
echo '+ Checking current version ...' | |
LOCAL_VERSION=$(ssh ${USERNAME}@${DOMAIN} ' | |
mysql '${DB_NAME}' -e " | |
SELECT config_value | |
FROM phpbb_config | |
WHERE config_name = 0x76657273696f6e | |
"; | |
' | sed -n 2p) | |
echo "+ The current forum version is PHPBB-${LOCAL_VERSION}" | |
echo '+ Checking public version ...' | |
# Download the webpage content and store it in a variable | |
WEBPAGE_CONTENT=$(curl -s 'https://www.phpbb.com/downloads/') | |
# Extract the version number using a refined regex pattern | |
REMOTE_VERSION=$(echo "$WEBPAGE_CONTENT" | grep -oP 'phpBB-\d+\.\d+\.\d+\.zip' | head -n 1 | grep -oP '\d+\.\d+\.\d+') | |
# Debugging information to ensure correct extraction | |
echo "Extracted Remote Version: ${REMOTE_VERSION}" | |
# If REMOTE_VERSION is empty, log an error message | |
if [ -z "$REMOTE_VERSION" ]; then | |
echo "Error: Failed to extract the remote version from the webpage content." | |
exit 1 | |
fi | |
echo "+ The current public version is PHPBB-${REMOTE_VERSION}" | |
if [ "$LOCAL_VERSION" != "$REMOTE_VERSION" ]; then | |
echo '+ The forum needs an update.' | |
echo '+ Downloading the latest version of phpBB ...' | |
rm -f '/tmp/phpbb3.zip' | |
wget -q "https://www.phpbb.com/files/release/phpBB-${REMOTE_VERSION}.zip" -O /tmp/phpbb3.zip | |
echo '+ Extracting ...' | |
mkdir -p '/tmp/phpbb3/' | |
unzip -q '/tmp/phpbb3.zip' -d '/tmp/phpbb3/' | |
rm -f '/tmp/phpbb3.zip' | |
rm -rf '/tmp/phpbb3/phpBB3/install/' | |
echo '+ Applying changes to the current project ...' | |
rsync -tvrz --delete \ | |
--exclude="/config.php" \ | |
--exclude="/cache/" \ | |
--exclude="/download/" \ | |
--exclude="/files/" \ | |
--exclude="/store/" \ | |
--exclude="/images/" \ | |
--exclude="/styles/ClearByte/" \ | |
'/tmp/phpbb3/phpBB3/' \ | |
${LOCAL_PATH} | |
rm -rf '/tmp/phpbb3/' | |
echo '+ Getting information about the Spanish translation package ...' | |
TRANSLATION_PAGE_CONTENT=$(curl -s "https://www.phpbb.com/customise/db/translation/${TRANS_LANGUAGE}") | |
# Extract download links using grep and awk | |
DOWNLOAD_LINK=$(echo "$TRANSLATION_PAGE_CONTENT" | grep -oP '<a class="download-button" href="\Khttps://www.phpbb.com/customise/db/download/\d+' | head -n 1) | |
# Debugging information to ensure correct extraction | |
echo "Download Link: ${DOWNLOAD_LINK}" | |
# If DOWNLOAD_LINK is empty, log an error message | |
if [ -z "$DOWNLOAD_LINK" ]; then | |
echo "Error: Failed to extract the download link from the translation page content." | |
exit 1 | |
fi | |
# Download the translation package | |
echo "+ Downloading ${TRANS_LANGUAGE} translation package from: $DOWNLOAD_LINK" | |
wget -q "$DOWNLOAD_LINK" -P '/tmp/' | |
# Extract downloaded zip file | |
echo '+ Extracting downloaded translation package ...' | |
unzip -q '/tmp/*.zip' -d '/tmp/' | |
# Apply changes to the current project | |
echo '+ Applying changes to the current project ...' | |
rsync -tvrz \ | |
/tmp/*${TRANS_LANGUAGE}*/ \ | |
${LOCAL_PATH} | |
rm -rf '/tmp/*${TRANS_LANGUAGE}*/' | |
# Sync changes on the server | |
echo '+ Syncing changes on the server ...' | |
rsync -tvrz --delete --progress \ | |
--exclude="/config.php" \ | |
--exclude="/cache/" \ | |
--exclude="/download/" \ | |
--exclude="/files/" \ | |
--exclude="/store/" \ | |
--exclude="/images/" \ | |
--exclude="/styles/ClearByte/" \ | |
${LOCAL_PATH} \ | |
${USERNAME}@${DOMAIN}:${REMOTE_PATH}/ | |
# Clear cache | |
echo '+ Clearing cache ...' | |
ssh ${USERNAME}@${DOMAIN} ' | |
rm -rf '${REMOTE_PATH}'/cache/production/; | |
rm -rf '${REMOTE_PATH}'/cache/installer/; | |
' | |
# Migrate database | |
echo '+ Migrating database ...' | |
ssh ${USERNAME}@${DOMAIN} ' | |
php '${REMOTE_PATH}'/bin/phpbbcli.php db:migrate --safe-mode | |
' | |
echo '+ Update completed.' | |
else | |
echo "+ The forum does not need an update." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment