|
#!/bin/sh |
|
|
|
# Source of this script: https://gist.github.com/williamdes/883f2158f17e9ed5a83d892ada56f5df |
|
# Revision: 01-2025-0002 |
|
|
|
set -eu |
|
|
|
ROOT=${1:-/var/www/html/} |
|
GROUP=${2:-www-data} |
|
USER=${3:-www-data} |
|
VERSION=${4:-""} |
|
FOLDER_NAME=${5:-phpmyadmin} |
|
PHPMYADMIN_RELEASE_GPG_KEY="3D06A59ECE730EB71B511C17CE752F178259BD92" |
|
|
|
# Source : https://stackoverflow.com/a/9018877/5155484 |
|
ROOT="${ROOT%/}" |
|
|
|
FOLDER_PATH="${ROOT}/${FOLDER_NAME}" |
|
|
|
if ! [ -x "$(command -v tar)" ]; then |
|
echo 'Error: tar is not installed: apt install -y tar' >&2 |
|
exit 1 |
|
fi |
|
|
|
HAS_SHA256_COMMAND=1 |
|
|
|
if ! [ -x "$(command -v sha256sum)" ]; then |
|
echo 'Warning: sha256sum is not installed: apt install -y coreutils' >&2 |
|
HAS_SHA256_COMMAND=0 |
|
fi |
|
|
|
HAS_GPG_COMMAND=1 |
|
|
|
if ! [ -x "$(command -v gpg)" ]; then |
|
echo 'Warning: gpg is not installed: apt install -y gpg' >&2 |
|
HAS_GPG_COMMAND=0 |
|
fi |
|
|
|
WGET_CURL='wget -O' |
|
|
|
if [ ! -x "$(command -v wget)" ] && [ ! -x "$(command -v curl)" ]; then |
|
echo 'Error: curl or wget is not installed. One of them is needed.' >&2 |
|
echo 'Use: apt install -y curl or apt install -y wget' >&2 |
|
exit 1 |
|
fi |
|
|
|
if [ -x "$(command -v curl)" ]; then |
|
WGET_CURL='curl --fail -# -o' |
|
fi |
|
|
|
EXTENSION='gz' |
|
# -z, --gzip, --gunzip, --ungzip |
|
TAR_EXTRACT='z' |
|
|
|
if [ -x "$(command -v xz)" ]; then |
|
EXTENSION='xz' |
|
# -J, --xz |
|
TAR_EXTRACT='J' |
|
fi |
|
|
|
if [ -z "${VERSION}" ]; then |
|
echo "Detecting last version" |
|
DATA="$(${WGET_CURL} - 'https://www.phpmyadmin.net/home_page/version.txt')" |
|
VERSION="$(echo $DATA | cut -d ' ' -f 1)" |
|
else |
|
echo "Using manual version" |
|
fi |
|
|
|
FILENAME="phpMyAdmin-${VERSION}-all-languages.tar.${EXTENSION}" |
|
URL="https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/${FILENAME}" |
|
|
|
# TODO: OVH hosting blocks all URLs but not GitHub |
|
# Use: https://github.com/phpmyadmin/composer/archive/refs/tags/5.2.1.zip |
|
# And composer install |
|
IS_DEV_VERSION=0 |
|
|
|
if [ -z "${VERSION##*snapshot*}" ]; then |
|
URL="https://files.phpmyadmin.net/snapshots/${FILENAME}" |
|
echo "Using manual snapshot version" |
|
IS_DEV_VERSION=1 |
|
fi |
|
|
|
echo "Url: $URL" |
|
echo "Version: $VERSION" |
|
echo "Root-Folder: ${ROOT}" |
|
echo "Folder: ${FOLDER_PATH}" |
|
DOWNLOADED_FILE_PATH="${ROOT}/${FILENAME}" |
|
echo "Downloaded-File-Path: ${DOWNLOADED_FILE_PATH}" |
|
|
|
${WGET_CURL} "${DOWNLOADED_FILE_PATH}" "$URL" |
|
|
|
if [ $HAS_SHA256_COMMAND -gt 0 ]; then |
|
${WGET_CURL} "${DOWNLOADED_FILE_PATH}.sha256" "$URL.sha256" |
|
cd ${ROOT} |
|
sha256sum -c "${DOWNLOADED_FILE_PATH}.sha256" |
|
cd - > /dev/null |
|
rm "${DOWNLOADED_FILE_PATH}.sha256" |
|
fi |
|
|
|
if [ $HAS_GPG_COMMAND -gt 0 ] && [ $IS_DEV_VERSION -eq 0 ]; then |
|
echo 'Verifying the release' |
|
${WGET_CURL} "${DOWNLOADED_FILE_PATH}.asc" "$URL.asc" |
|
${WGET_CURL} "${ROOT}/phpmyadmin.keyring" https://files.phpmyadmin.net/phpmyadmin.keyring |
|
gpg --dearmor "${ROOT}/phpmyadmin.keyring" |
|
rm "${ROOT}/phpmyadmin.keyring" |
|
gpg --no-default-keyring --keyring "${ROOT}/phpmyadmin.keyring.gpg" --verify "${DOWNLOADED_FILE_PATH}.asc" |
|
# Make the key trusted |
|
echo "${PHPMYADMIN_RELEASE_GPG_KEY}:6:" | gpg --no-default-keyring --keyring "${ROOT}/phpmyadmin.keyring.gpg" --import-ownertrust |
|
rm "${DOWNLOADED_FILE_PATH}.asc" "${ROOT}/phpmyadmin.keyring.gpg" |
|
echo 'Verified the release' |
|
fi |
|
|
|
if [ -d "${FOLDER_PATH}" ] && [ -f "${FOLDER_PATH}/config.inc.php" ]; then |
|
mv "${FOLDER_PATH}/config.inc.php" "${ROOT}/config.inc.php" |
|
echo 'Backup of config.inc.php done' |
|
fi |
|
|
|
HAS_TMP=0 |
|
|
|
if [ -d "${FOLDER_PATH}" ] && [ -d "${FOLDER_PATH}/tmp" ]; then |
|
HAS_TMP=1 |
|
echo 'Found a tmp dir' |
|
fi |
|
|
|
if [ -d "${FOLDER_PATH}" ]; then |
|
echo "Deleting the old dir contents ..." |
|
rm -r "${FOLDER_PATH}/" |
|
fi |
|
|
|
if [ ! -d "${FOLDER_PATH}" ]; then |
|
echo "Creating the ${FOLDER_PATH} folder" |
|
mkdir "${FOLDER_PATH}/" |
|
chmod 770 "${FOLDER_PATH}/" |
|
chown ${GROUP}:${USER} "${FOLDER_PATH}/" |
|
fi |
|
|
|
echo "Un-tar (${EXTENSION}) ..." |
|
tar -x${TAR_EXTRACT} --strip-components=1 --directory="${FOLDER_PATH}" -f "${DOWNLOADED_FILE_PATH}" |
|
rm "${DOWNLOADED_FILE_PATH}" |
|
|
|
if [ -d "${FOLDER_PATH}" ] && [ -f "${ROOT}/config.inc.php" ]; then |
|
mv "${ROOT}/config.inc.php" "${FOLDER_PATH}/config.inc.php" |
|
echo 'Restore of config.inc.php done' |
|
fi |
|
|
|
echo 'Changing file mods and rights' |
|
|
|
# rwx for owner, rx for group, r for others |
|
find "${FOLDER_PATH}" -type d -exec chmod 0755 {} + |
|
# rw for owner, r for group, r for others |
|
find "${FOLDER_PATH}" -type f -exec chmod 0644 {} + |
|
|
|
chown ${GROUP}:${USER} -R "${FOLDER_PATH}" |
|
|
|
if [ ${HAS_TMP} -eq 1 ]; then |
|
mkdir "${FOLDER_PATH}/tmp" |
|
echo 'Re-created a tmp dir' |
|
chmod 770 "${FOLDER_PATH}/tmp" |
|
chown ${GROUP}:${USER} "${FOLDER_PATH}/tmp" |
|
fi |
|
|
|
echo 'Removing setup and examples directories, you do not need them' |
|
# See: https://docs.phpmyadmin.net/en/qa_5_2/faq.html#how-can-i-reduce-the-installed-size-of-phpmyadmin-on-disk |
|
rm -r "${FOLDER_PATH}/examples/" |
|
# Does not exist on 6.0 |
|
rm -rf "${FOLDER_PATH}/setup/" |
|
# Does not exist on 5.2 |
|
rm -rf "${FOLDER_PATH}/public/setup/" |
|
echo 'Removing source directories and some files, you do not need them' |
|
rm "${FOLDER_PATH}/CONTRIBUTING.md" |
|
|
|
# doc is docs in 6.0 |
|
|
|
# Does not exist on 6.0 |
|
rm -rf "${FOLDER_PATH}/doc/html/_sources/" |
|
# Does not exist on 5.2 |
|
rm -rf "${FOLDER_PATH}/docs/html/_sources/" |
|
|
|
# Does not exist on 5.2 |
|
rm -rf "${FOLDER_PATH}/resources/js/src/" |
|
# Does not exist on 6.0 |
|
rm -rf "${FOLDER_PATH}/js/src/" |
|
# Does not exist on 6.0 |
|
rm -rf "${FOLDER_PATH}/js/config/" |
|
# Does not exist on 5.2 |
|
rm -f "${FOLDER_PATH}/js/global.d.ts" |
|
# Does not exist on 6.0 |
|
rm -f "${FOLDER_PATH}/babel.config.json" |
|
# Does not exist on 5.2 |
|
rm -f "${FOLDER_PATH}/webpack.config.cjs" |
|
# Does not exist on 6.0 |
|
rm -f "${FOLDER_PATH}/.rtlcssrc.json" |
|
# Does not exist on 6.0 |
|
rm -f "${FOLDER_PATH}/libraries/language_stats.inc.php" |
|
|
|
echo "Done !" |