Skip to content

Commit

Permalink
chore(manager): deprecate SB_DEFAULT_SERVER_NAME on install (Jigsaw-C…
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna authored Feb 5, 2024
1 parent 28d2b2e commit 64c4f94
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/server_manager/install_scripts/install_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ function write_config() {
if (( FLAGS_KEYS_PORT != 0 )); then
config+=("\"portForNewAccessKeys\": ${FLAGS_KEYS_PORT}")
fi
# Use printf to escape (%q) the hostname.
config+=("$(printf '"hostname": "%q"' "${PUBLIC_HOSTNAME}")")
if [[ -n "${SB_DEFAULT_SERVER_NAME:-}" ]]; then
config+=("\"name\": \"$(escape_json_string "${SB_DEFAULT_SERVER_NAME}")\"")
fi
config+=("\"hostname\": \"$(escape_json_string "${PUBLIC_HOSTNAME}")\"")
echo "{$(join , "${config[@]}")}" > "${STATE_DIR}/shadowbox_server_config.json"
}

Expand Down Expand Up @@ -342,9 +344,6 @@ docker_command=(
# Where to report metrics to, if opted-in.
-e "SB_METRICS_URL=${SB_METRICS_URL:-}"
# The default server name, if not set in the config.
-e "SB_DEFAULT_SERVER_NAME=${SB_DEFAULT_SERVER_NAME:-}"
# The Outline server image to run.
"${SB_IMAGE}"
)
Expand Down Expand Up @@ -546,6 +545,30 @@ function is_valid_port() {
(( 0 < "$1" && "$1" <= 65535 ))
}

function escape_json_string() {
local input=$1
for ((i = 0; i < ${#input}; i++)); do
local char="${input:i:1}"
local escaped="${char}"
case "${char}" in
$'"' ) escaped="\\\"";;
$'\\') escaped="\\\\";;
*)
if [[ "${char}" < $'\x20' ]]; then
case "${char}" in
$'\b') escaped="\\b";;
$'\f') escaped="\\f";;
$'\n') escaped="\\n";;
$'\r') escaped="\\r";;
$'\t') escaped="\\t";;
*) escaped=$(printf "\u%04X" "'${char}")
esac
fi;;
esac
echo -n "${escaped}"
done
}

function parse_flags() {
local params
params="$(getopt --longoptions hostname:,api-port:,keys-port: -n "$0" -- "$0" "$@")"
Expand Down

0 comments on commit 64c4f94

Please sign in to comment.