mirror of
https://github.com/overleaf/toolkit.git
synced 2025-04-19 23:38:06 +02:00
Scripts to rebrand environment variables
This commit is contained in:
parent
64de593745
commit
58f427a381
4 changed files with 110 additions and 15 deletions
21
bin/up
21
bin/up
|
@ -35,6 +35,22 @@ function check_config() {
|
|||
fi
|
||||
}
|
||||
|
||||
function check_sharelatex_env_vars() {
|
||||
local invalid_prefix="SHARELATEX_"
|
||||
if [[ "$IMAGE_VERSION_MAJOR" -lt 5 ]]; then
|
||||
invalid_prefix="OVERLEAF_"
|
||||
fi
|
||||
|
||||
if grep -q "$invalid_prefix" "$TOOLKIT_ROOT/config/variables.env"; then
|
||||
echo "WARNING: some environment variables defined in config/variables.env"
|
||||
echo "contain '$invalid_prefix' in their name"
|
||||
echo "Starting with Overleaf CE and Server Pro 5.0.0 the environment variables"
|
||||
echo "use the prefix 'OVERLEAF_' instead of '_SHARELATEX'."
|
||||
echo "Please check your config/version and config/variables.env files"
|
||||
prompt "Do you want to continue?"
|
||||
fi
|
||||
}
|
||||
|
||||
function initiate_mongo_replica_set() {
|
||||
echo "Initiating Mongo replica set..."
|
||||
"$TOOLKIT_ROOT/bin/docker-compose" up -d mongo
|
||||
|
@ -52,9 +68,10 @@ function __main__() {
|
|||
exit
|
||||
fi
|
||||
|
||||
check_config
|
||||
read_config
|
||||
read_image_version
|
||||
check_config
|
||||
check_sharelatex_env_vars
|
||||
read_config
|
||||
|
||||
if [[ "$MONGO_ENABLED" == "true" && "$IMAGE_VERSION_MAJOR" -ge 4 ]]; then
|
||||
initiate_mongo_replica_set
|
||||
|
|
50
bin/update-env
Executable file
50
bin/update-env
Executable file
|
@ -0,0 +1,50 @@
|
|||
#! /usr/bin/env bash
|
||||
# shellcheck source-path=..
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
#### Detect Toolkit Project Root ####
|
||||
# if realpath is not available, create a semi-equivalent function
|
||||
command -v realpath >/dev/null 2>&1 || realpath() {
|
||||
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
||||
}
|
||||
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
|
||||
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
|
||||
TOOLKIT_ROOT="$(realpath "$SCRIPT_DIR/..")"
|
||||
if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
|
||||
echo "ERROR: could not find root of overleaf-toolkit project (inferred project root as '$TOOLKIT_ROOT')"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
|
||||
|
||||
function usage() {
|
||||
echo "Usage: bin/update-env"
|
||||
echo ""
|
||||
echo "Updates config/variables.env, adding new environment variables"
|
||||
echo ""
|
||||
echo "This program will pass any extra flags to docker compose,"
|
||||
echo "for example: 'bin/up -d' will run in detached mode"
|
||||
}
|
||||
|
||||
function __main__() {
|
||||
if [[ "${1:-null}" == "help" ]] || [[ "${1:-null}" == "--help" ]]; then
|
||||
usage
|
||||
exit
|
||||
fi
|
||||
|
||||
# read_image_version
|
||||
echo "This script will update your config/variables.env."
|
||||
echo "We recommend backing up your config with bin/backup-config."
|
||||
prompt "Do you want to continue?"
|
||||
|
||||
echo "Creating backup file config/__old-variables.env"
|
||||
cp config/variables.env config/__old-variables.env
|
||||
|
||||
echo "Replacing 'SHARELATEX_' with 'OVERLEAF_' in config/variables.env"
|
||||
sed -i "s/SHARELATEX_/OVERLEAF_/g" "$TOOLKIT_ROOT/config/variables.env"
|
||||
|
||||
echo "Done."
|
||||
}
|
||||
|
||||
__main__ "$@"
|
46
bin/upgrade
46
bin/upgrade
|
@ -15,6 +15,8 @@ if [[ ! -d "$TOOLKIT_ROOT/bin" ]] || [[ ! -d "$TOOLKIT_ROOT/config" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
|
||||
|
||||
function usage() {
|
||||
echo "Usage: bin/upgrade"
|
||||
echo ""
|
||||
|
@ -87,22 +89,27 @@ function show_changes() {
|
|||
echo "----------"
|
||||
}
|
||||
|
||||
function handle_image_upgrade() {
|
||||
local user_image_version
|
||||
user_image_version="$(head -n 1 "$TOOLKIT_ROOT/config/version")"
|
||||
local seed_image_version
|
||||
seed_image_version="$(head -n 1 "$TOOLKIT_ROOT/lib/config-seed/version")"
|
||||
function read_seed_image_version() {
|
||||
SEED_IMAGE_VERSION="$(head -n 1 "$TOOLKIT_ROOT/lib/config-seed/version")"
|
||||
if [[ ! "$SEED_IMAGE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.[0-9]+(-RC[0-9]*)?(-with-texlive-full)?$ ]]; then
|
||||
echo "ERROR: invalid config-seed/version '${SEED_IMAGE_VERSION}'"
|
||||
exit 1
|
||||
fi
|
||||
SEED_IMAGE_VERSION_MAJOR=${BASH_REMATCH[1]}
|
||||
SEED_IMAGE_VERSION_MINOR=${BASH_REMATCH[2]}
|
||||
}
|
||||
|
||||
if [[ ! "$seed_image_version" > "$user_image_version" ]]; then
|
||||
function handle_image_upgrade() {
|
||||
if [[ ! "$SEED_IMAGE_VERSION" > "$IMAGE_VERSION" ]]; then
|
||||
echo "No change to docker image version"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "New docker image version available ($seed_image_version)"
|
||||
echo "Current image version is '$user_image_version' (from config/version)"
|
||||
echo "New docker image version available ($SEED_IMAGE_VERSION)"
|
||||
echo "Current image version is '$IMAGE_VERSION' (from config/version)"
|
||||
|
||||
local user_image_major_version="$(echo "$user_image_version" | awk -F. '{print $1}')"
|
||||
local seed_image_major_version="$(echo "$seed_image_version" | awk -F. '{print $1}')"
|
||||
local user_image_major_version="$(echo "$IMAGE_VERSION" | awk -F. '{print $1}')"
|
||||
local seed_image_major_version="$(echo "$SEED_IMAGE_VERSION" | awk -F. '{print $1}')"
|
||||
if [[ "$seed_image_major_version" > "$user_image_major_version" ]]; then
|
||||
echo "WARNING: this is a major version update, please check the Release Notes for breaking changes before proceeding:"
|
||||
echo "* https://github.com/overleaf/overleaf/wiki#release-notes"
|
||||
|
@ -112,11 +119,11 @@ function handle_image_upgrade() {
|
|||
read -r -p "Upgrade image? [y/n] " should_upgrade
|
||||
|
||||
if [[ ! "$should_upgrade" =~ [Yy] ]]; then
|
||||
echo "Keeping image version '$user_image_version'"
|
||||
echo "Keeping image version '$IMAGE_VERSION'"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Upgrading config/version from $user_image_version to $seed_image_version"
|
||||
echo "Upgrading config/version from $IMAGE_VERSION to $SEED_IMAGE_VERSION"
|
||||
|
||||
## Offer to stop docker services
|
||||
local services_stopped="false"
|
||||
|
@ -148,9 +155,17 @@ function handle_image_upgrade() {
|
|||
## Set the new image version
|
||||
echo "Backing up old version file to config/__old-version"
|
||||
cp "$TOOLKIT_ROOT/config/version" "$TOOLKIT_ROOT/config/__old-version"
|
||||
echo "Over-writing config/version with $seed_image_version"
|
||||
echo "Over-writing config/version with $SEED_IMAGE_VERSION"
|
||||
cp "$TOOLKIT_ROOT/lib/config-seed/version" "$TOOLKIT_ROOT/config/version"
|
||||
|
||||
if [[ "$IMAGE_VERSION_MAJOR" -le 4 && "$SEED_IMAGE_VERSION_MAJOR" -ge 5 ]]; then
|
||||
echo "Renaming environment variables in config/variables.env"
|
||||
prompt "Proceed with the environment variable renaming?"
|
||||
echo "Backing up old variables.env file to config/__old-variables.env"
|
||||
cp "$TOOLKIT_ROOT/config/variables.env" "$TOOLKIT_ROOT/config/__old-variables.env"
|
||||
sed -i "s/SHARELATEX_/OVERLEAF_/g" "$TOOLKIT_ROOT/config/variables.env"
|
||||
fi
|
||||
|
||||
## Maybe offer to start services again
|
||||
if [[ "${services_stopped:-null}" == "true" ]]; then
|
||||
local should_start="n"
|
||||
|
@ -202,8 +217,13 @@ function __main__() {
|
|||
|| [[ "${1:-null}" == "--help" ]] ; then
|
||||
usage && exit
|
||||
fi
|
||||
|
||||
handle_git_update
|
||||
|
||||
read_seed_image_version
|
||||
read_image_version
|
||||
handle_image_upgrade
|
||||
|
||||
echo "Done"
|
||||
exit 0
|
||||
}
|
||||
|
|
|
@ -17,3 +17,11 @@ function read_image_version() {
|
|||
IMAGE_VERSION_MAJOR=${BASH_REMATCH[1]}
|
||||
IMAGE_VERSION_MINOR=${BASH_REMATCH[2]}
|
||||
}
|
||||
|
||||
prompt() {
|
||||
read -p "$1 (y/n): " choice
|
||||
if [[ ! "$choice" =~ [Yy] ]]; then
|
||||
echo "Exiting."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue