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