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