Blame SOURCES/set_config.sh

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