You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had to copy saltstack default config files into local ones. So I've created a little script to compare local to default files to keep track of changes by SO updates. Perhaps it's useful for others, too.
so-diff.sh:
#!/bin/sh
#
# Script for diff'ing changes in local config files to default files
#
# May be useful for making sure SO updates haven't changed anything
# in default config files which must be transferred to customized local ones
#
# V0.01: 2021-06-07: initial version (Gebhard)
# V0.02: 2021-06-08: tidying up (Gebhard)
#
# set default verbosity level
VERBOSE="0"
# vertical line
LINE="################################################################################"
usage () {
echo "${LINE}"
echo " This script (${0}) assists in situations where"
echo " local saltstack files have to be maintained as copies of default files."
echo " In these cases care must be taken that new / changed configurations in"
echo " default files (e.g. introduced by updates) are manually transferred into"
echo " the local copy of that file to maintain consistency."
echo " This script will iterate through the local saltstack configuration files"
echo " and see if a default configuration file with the same name can be found"
echo " for each file. If so, then both files will be diff'ed."
echo " In normal, non-verbose mode only files where modifications or additions"
echo " in the default file are observed, are diff'ed in detail. If a local file"
echo " has only additions in comparision to the respective default one, a note"
echo " is printed and no diff is shown."
echo " In verbose mode the diff is always shown."
echo " File can be excluded from this analysis, see config section of the script."
echo " In very verbose mode the to-be-ignored files are not ignored, so every"
echo " difference is shown."
echo " If modifications / additions in default files are found, exit code is set"
echo " to 10."
echo " ${0} [-v|--verbose|-vv|--veryverbose|-h|--help]"
echo "${LINE}"
exit 1
}
# parse command line arguments
case ${1} in
-v|--verbose)
VERBOSE="1" # show diff even when the local file only contains addition
;;
-vv|--veryverbose)
VERBOSE="2" # like VERBOSE=1, and ignore the ignore list
;;
-h|--help)
usage
;;
esac
# Configuration
# main directory
DIRROOT="/opt/so/saltstack"
# directory for local stuff below main directory
DIRLOCAL="${DIRROOT}/local"
# directory containing SO maintained stuff below main directory
DIRDEFAULT="${DIRROOT}/default"
# list of files to ignore, relative to $DIRLOCAL, starting with "./",
# e.g. ./salt/elasticsearch/files/ingest/syslog
FILEIGNORE=""
# vertical line
LINE="######################################################################################################################"
# default exit code
EXIT=0
# if VERBOSE=2 is chosen: remove ignore list and set to normal verbose mode (1)
if [ ${VERBOSE} == "2" ] ; then
VERBOSE="1"
FILEIGNORE=""
fi
# search is done relative to local config dir so we can easily look for respective default file
cd ${DIRLOCAL}
# iterate through local config files
for FILELOCAL in `find . -type f` ; do
# construct name for corresponding deault file
FILEDEFAULT="${DIRDEFAULT}/${FILELOCAL}"
# see if corresponding default file exists
if [ -f ${FILEDEFAULT} ] ; then
# only compare both files if local file is not on ignore list
if [ `echo "${FILEIGNORE}" | grep "${FILELOCAL}" | wc -l` -eq 0 ] ; then
# local and default file exist and not on ignore list -> compare
echo "${LINE}"
echo "Local File: ${DIRLOCAL}/${FILELOCAL}"
ls -la ${DIRLOCAL}/${FILELOCAL}
echo "Respective Default File: ${FILEDEFAULT}"
ls -la ${FILEDEFAULT}
DIFF=`diff ${FILEDEFAULT} ${FILELOCAL}`
# see if we have only additional lines or also removed / changed lines
if [ `echo "${DIFF}" | grep "^< " | wc -l` -gt 0 ] ; then
# found modiciations / missing lines -> show always
echo "### WARNING: removed / changed lines found!"
EXIT=10
echo "${DIFF}"
elif [ ${VERBOSE} == "1" ] ; then
# verbose: always show diff
echo "${DIFF}"
else
# non-verbose mode, only local additions found
echo "### Only local additions found. Diff not shown."
fi
echo "${LINE}"
fi
fi
done
exit ${EXIT}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I had to copy saltstack default config files into local ones. So I've created a little script to compare local to default files to keep track of changes by SO updates. Perhaps it's useful for others, too.
so-diff.sh
:Beta Was this translation helpful? Give feedback.
All reactions