Review shell scripts
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -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."
|
||||
|
Reference in New Issue
Block a user