Blame SOURCES/set_config.sh

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