Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(manager): deprecate SB_DEFAULT_SERVER_NAME on install #1498

Merged
merged 5 commits into from
Feb 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 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,26 @@ 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
# List from https://www.json.org/json-en.html.
$'"' ) escaped="\\\"";;
$'\\') escaped="\\\\";;
$'/' ) escaped="\\/";;
$'\b') escaped="\\b";;
$'\f') escaped="\\f";;
$'\n') escaped="\\n";;
$'\r') escaped="\\r";;
$'\t') escaped="\\t";;
esac
echo -n "${escaped}"
done
}

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