2020-06-04 16:15:57 +01:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2020-07-16 09:43:58 +01:00
|
|
|
#### Detect Toolkit Project Root ####
|
2020-07-16 13:55:18 +01:00
|
|
|
# if realpath is not available, create a semi-equivalent function
|
|
|
|
command -v realpath >/dev/null 2>&1 || realpath() {
|
|
|
|
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
|
|
|
|
}
|
2020-07-16 09:43:58 +01:00
|
|
|
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
|
|
|
|
|
2020-06-17 10:19:38 +01:00
|
|
|
function usage() {
|
|
|
|
echo "Usage: bin/init"
|
|
|
|
echo ""
|
|
|
|
echo "Initialises local configuration files in the 'config/' directory"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2020-06-16 13:20:30 +01:00
|
|
|
function check_existing_config() {
|
2020-07-16 09:43:58 +01:00
|
|
|
if [[ -f "$TOOLKIT_ROOT/config/overleaf.rc" ]] \
|
|
|
|
|| [[ -f "$TOOLKIT_ROOT/config/variables.env" ]] \
|
|
|
|
|| [[ -f "$TOOLKIT_ROOT/config/version" ]]; then
|
2020-06-16 13:20:30 +01:00
|
|
|
echo "ERROR: Config files already exist, exiting "
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-04 16:15:57 +01:00
|
|
|
function set_up_config_files() {
|
2020-06-16 13:39:19 +01:00
|
|
|
echo "Copying config files to 'config/'"
|
2020-07-16 09:43:58 +01:00
|
|
|
cp "$TOOLKIT_ROOT/lib/config-seed/overleaf.rc" "$TOOLKIT_ROOT/config/"
|
|
|
|
cp "$TOOLKIT_ROOT/lib/config-seed/variables.env" "$TOOLKIT_ROOT/config/"
|
|
|
|
cp "$TOOLKIT_ROOT/lib/config-seed/version" "$TOOLKIT_ROOT/config/"
|
2020-06-04 16:15:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function __main__() {
|
2020-06-17 10:19:38 +01:00
|
|
|
if [[ "${1:-null}" == "help" ]] || [[ "${1:-null}" == "--help" ]]; then
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
fi
|
2020-06-16 13:20:30 +01:00
|
|
|
check_existing_config
|
2020-06-04 16:15:57 +01:00
|
|
|
set_up_config_files
|
|
|
|
}
|
|
|
|
|
|
|
|
__main__ "$@"
|