Review shell scripts

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-01-22 14:07:22 +00:00
parent 8f94687b2b
commit bcbda92c46
27 changed files with 273 additions and 259 deletions

View File

@@ -1,13 +1,13 @@
SOURCE_FILE=$(realpath -m "$1")
TARGET_FILE=$(realpath -m "$2")
source=$(realpath -m "$1")
target=$(realpath -m "$2")
if [[ -f "${TARGET_FILE}" ]]; then
TEMP_FILE=$(mktemp)
awk -F '=' 'NR==FNR{a[$1]=$0;next}($1 in a){$0=a[$1]}1' "${SOURCE_FILE}" "${TARGET_FILE}" > "${TEMP_FILE}"
mv "${TEMP_FILE}" "${TARGET_FILE}"
if [[ -f "$target" ]]; then
temp=$(mktemp)
awk -F '=' 'NR==FNR{a[$1]=$0;next}($1 in a){$0=a[$1]}1' "$source" "$target" > "$temp"
mv "$temp" "$target"
else
mkdir -p "$(dirname "${TARGET_FILE}")"
cp "${SOURCE_FILE}" "${TARGET_FILE}"
mkdir -p "$(dirname "$target")"
cp "$source" "$target"
fi
echo "Configuration file ${TARGET_FILE} has been updated."
echo "Configuration file $target has been updated."