Last active
September 2, 2019 20:28
-
-
Save Eihen/97af4c55d2a05bca184d127a3cd6c409 to your computer and use it in GitHub Desktop.
Simple application version manager
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 | |
# Application name | |
APP_NAME="PHP" | |
# Active application directory | |
# The directory with all the versions of the application must be this directory prefixed with the version | |
PHP_ROOT="/c/${APP_NAME}" | |
# The file that keeps the current application version | |
CURRENT_FILE="${HOME}/.${APP_NAME}-current" | |
# Check if there's a currently selected version | |
CURRENT_VERSION= | |
if [ -f "${CURRENT_FILE}" ]; then | |
CURRENT_VERSION="$(cat ${CURRENT_FILE})" | |
fi | |
# Check if the requested version is already active | |
if [ "${CURRENT_VERSION}" -eq "${1}" ]; then | |
echo "${APP_NAME} version ${1} is already selected." | |
exit 0 # Nothing to do, but the request version is selected | |
fi | |
# Check if the folder with the requested version exists | |
if [ ! -d "${PHP_ROOT}${1}" ]; then | |
echo "The ${APP_NAME} version ${1} could not be found." | |
exit 1 | |
fi | |
# Check if the directory of the selected version exists | |
if [ -d "${PHP_ROOT}" ]; then | |
# Check if the current version could be retrieved from the $CURRENT_FILE | |
if [ ! "${CURRENT_VERSION}" ]; then | |
# If the directory exists and the version file don't, there's a problem the script can't solve | |
echo "There's a currently selected version of ${APP_NAME}, but the version file (${CURRENT_FILE}) could not be found."; | |
echo "This requires manual intervention, either create the file ${CURRENT_FILE} with the current version as content or move the ${PHP_ROOT} folder." | |
exit 1 | |
fi | |
# Move the currently selected version to a version directory name | |
mv "${PHP_ROOT}" "${PHP_ROOT}${CURRENT_VERSION}" | |
fi | |
# Move the requested version to the selected version | |
mv "${PHP_ROOT}${1}" "${PHP_ROOT}" | |
# Stores the currently selected version in the file | |
echo "${1}" > "${CURRENT_FILE}" | |
echo "${APP_NAME} version ${1} selected." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment