From 8ef82d798e682a856c9720906255b690ffd6128d Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 7 Sep 2022 19:14:08 +0200 Subject: [PATCH] chore: keep config files in sync --- .pre-commit-config.yaml | 8 ++++++ tools/update-config-files.sh | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 tools/update-config-files.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 76dbfd419..8476b2a67 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,3 +70,11 @@ repos: pass_filenames: false language: script files: setup.py$ + + - id: config.yml + name: config.yml + description: Update config files + entry: tools/update-config-files.sh + pass_filenames: false + language: script + files: ^installer/config.yml$ diff --git a/tools/update-config-files.sh b/tools/update-config-files.sh new file mode 100755 index 000000000..724f19144 --- /dev/null +++ b/tools/update-config-files.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Keep configuration files in sync with installer/config.yml. + +set -u + +error() { + echo >&2 "error: $*" + exit 1 +} + +command -v ed > /dev/null || error "ed command not found!" + +CONFIG_ORIG_FILEPATH="installer/config.yml" + +# set_config +set_config() { + value="${1}" && shift + + # Build sed query + query="/^${1}:/\n" + while [[ $# -gt 1 ]]; do + shift + query+="/${1}:/\n" + done + query+="s|\(${1}:\).*|\1 ${value}|\n" + query+="wq" + + echo -e "$query" | ed --quiet "$CONFIG_FILEPATH" > /dev/null +} + +set_docker_config() { + set_config "postgres" database host + set_config "rabbitmq" rabbitmq host + set_config "liquidsoap" playout liquidsoap_host + set_config "0.0.0.0" liquidsoap server_listen_address + set_config "icecast" stream outputs .default_icecast_output host +} + +CONFIG_FILEPATH="docker/config.yml" +cp "$CONFIG_ORIG_FILEPATH" "$CONFIG_FILEPATH" + +set_docker_config + +CONFIG_FILEPATH="docker/example/config.yml" +cp "$CONFIG_ORIG_FILEPATH" "$CONFIG_FILEPATH" + +set_docker_config +set_config "http://localhost:8080" general public_url +set_config "some_secret_api_key" general api_key