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