mirror of
https://github.com/overleaf/toolkit.git
synced 2025-04-19 15:28:06 +02:00
Add scripts to rebrand variables.env and overleaf.rc
This commit is contained in:
parent
5787d8f3c8
commit
cfe060b4f4
3 changed files with 55 additions and 12 deletions
|
@ -19,9 +19,9 @@ fi
|
|||
source "$TOOLKIT_ROOT/lib/shared-functions.sh"
|
||||
|
||||
function usage() {
|
||||
echo "Usage: bin/update-env"
|
||||
echo "Usage: bin/update-env-vars-5-0"
|
||||
echo ""
|
||||
echo "Updates config/variables.env, adding new environment variables"
|
||||
echo "Updates config/variables.env to ensure variables are renamed from 'SHARELATEX_' to 'OVERLEAF_'"
|
||||
echo ""
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,11 @@ function __main__() {
|
|||
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?"
|
||||
|
||||
rebrand_sharelatex_env_variables
|
||||
rebrand_sharelatex_env_variables 'variables.env'
|
||||
|
||||
echo "Done."
|
||||
}
|
||||
|
|
43
bin/rename-rc-vars
Executable file
43
bin/rename-rc-vars
Executable file
|
@ -0,0 +1,43 @@
|
|||
#! /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/rename-rc-vars"
|
||||
echo ""
|
||||
echo "Updates config/overleaf.rc to ensure variables are renamed from 'SHARELATEX_' to 'OVERLEAF_'"
|
||||
echo ""
|
||||
}
|
||||
|
||||
function __main__() {
|
||||
if [[ "${1:-null}" == "help" ]] || [[ "${1:-null}" == "--help" ]]; then
|
||||
usage
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "This script will update your config/overleaf.rc."
|
||||
echo "We recommend backing up your config with bin/backup-config."
|
||||
prompt "Do you want to continue?"
|
||||
|
||||
rebrand_sharelatex_env_variables 'overleaf.rc'
|
||||
|
||||
echo "Done."
|
||||
}
|
||||
|
||||
__main__ "$@"
|
|
@ -27,18 +27,19 @@ prompt() {
|
|||
}
|
||||
|
||||
rebrand_sharelatex_env_variables() {
|
||||
local filename=$1
|
||||
set +o pipefail
|
||||
sharelatex_occurrences=$(grep -o "SHARELATEX_" "$TOOLKIT_ROOT/config/variables.env" | wc -l | sed 's/ //g')
|
||||
sharelatex_occurrences=$(grep -o "SHARELATEX_" "$TOOLKIT_ROOT/config/$filename" | wc -l | sed 's/ //g')
|
||||
set -o pipefail
|
||||
if [ "$sharelatex_occurrences" -gt 0 ]; then
|
||||
echo "Found $sharelatex_occurrences lines with SHARELATEX_"
|
||||
echo "Found $sharelatex_occurrences lines with SHARELATEX_ in $filename"
|
||||
local timestamp=$(date "+%Y.%m.%d-%H.%M.%S")
|
||||
echo "Creating backup file config/__old-variables.env.$timestamp"
|
||||
cp config/variables.env config/__old-variables.env.$timestamp
|
||||
echo "Replacing 'SHARELATEX_' with 'OVERLEAF_' in config/variables.env"
|
||||
sed -i "s/SHARELATEX_/OVERLEAF_/g" "$TOOLKIT_ROOT/config/variables.env"
|
||||
echo "Updated $sharelatex_occurrences lines in $TOOLKIT_ROOT/config/variables.env"
|
||||
echo "Creating backup file config/__old-$filename.$timestamp"
|
||||
cp config/$filename config/__old-$filename.$timestamp
|
||||
echo "Replacing 'SHARELATEX_' with 'OVERLEAF_' in config/$filename"
|
||||
sed -i "s/SHARELATEX_/OVERLEAF_/g" "$TOOLKIT_ROOT/config/$filename"
|
||||
echo "Updated $sharelatex_occurrences lines in $TOOLKIT_ROOT/config/$filename"
|
||||
else
|
||||
echo "No 'SHARELATEX_' ocurrences found in config/variables.env"
|
||||
echo "No 'SHARELATEX_' ocurrences found in config/$filename"
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue