Blame SOURCES/set_config.sh

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