15c6a1
#!/bin/bash
15c6a1
# Copyright (C) 2017, Red Hat, Inc.
15c6a1
#
15c6a1
# set_config.sh will copy a configuration from $1 to $2, in the process
15c6a1
# checking that the sha header for $1 matches the header in $2
15c6a1
15c6a1
source configlib.sh
15c6a1
15c6a1
if (( $# < 2 )); then
15c6a1
    echo "$0: source dest [comment-marker]"
15c6a1
    exit 1
15c6a1
fi
15c6a1
15c6a1
if [ ! -f "$1" ]; then
15c6a1
    echo "Source file $1 must exist."
15c6a1
    exit 1
15c6a1
fi
15c6a1
src_file=$1
15c6a1
shift
15c6a1
15c6a1
if [ ! -f "$1" ]; then
15c6a1
    echo "Dest file $1 must exist."
15c6a1
    exit 1
15c6a1
fi
15c6a1
dst_file=$1
15c6a1
shift
15c6a1
15c6a1
comment_sep=${1:-#}
15c6a1
15c6a1
export LANG=en_US.utf8
15c6a1
15c6a1
DEST_FILE_SHA=""
15c6a1
SRC_FILE_SHA=""
15c6a1
15c6a1
calc_sha DEST_FILE_SHA "$dst_file" "$comment_sep" || echo "Failed to calc sha"
15c6a1
retr_sha SRC_FILE_SHA "$src_file" "$comment_sep" || echo "Failed to retrieve sha"
15c6a1
15c6a1
if [ "$DEST_FILE_SHA" != "$SRC_FILE_SHA" ]; then
15c6a1
    echo "ERROR: The requisite starting sha from $dst_file does not match the"
15c6a1
    echo "       specified sha in $src_file."
15c6a1
    echo "[ $DEST_FILE_SHA ] vs [ $SRC_FILE_SHA ]"
15c6a1
    exit 1
15c6a1
fi
15c6a1
15c6a1
mv "$dst_file" "$dst_file".OLD
15c6a1
cp "$src_file" "$dst_file"
15c6a1
echo "copied 1 config file."
15c6a1
exit 0