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