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