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