Blame SOURCES/set_config.sh

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