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