]> arthur.barton.de Git - netdata.git/commitdiff
detect stock versions of config files and replace them with the newer versions
authorCosta Tsaousis <costa@tsaousis.gr>
Thu, 14 Jul 2016 15:26:39 +0000 (18:26 +0300)
committerCosta Tsaousis <costa@tsaousis.gr>
Thu, 14 Jul 2016 15:26:39 +0000 (18:26 +0300)
configs.signatures [new file with mode: 0644]
netdata-installer.sh

diff --git a/configs.signatures b/configs.signatures
new file mode 100644 (file)
index 0000000..8ec38b5
--- /dev/null
@@ -0,0 +1,86 @@
+declare -A configs_signatures=(
+       ['0056936ce99788ed9ae1c611c87aa6d8']='apps_groups.conf'
+       ['18ee1c6197a4381b1c1631ef6129824f']='apps_groups.conf'
+       ['2f4a85fedecce1bf425fa1039f6b021e']='apps_groups.conf'
+       ['3af522d65b50a5e447607ffb28c81ff5']='apps_groups.conf'
+       ['4a448831776de8acf2e0bdc4cc994cb4']='apps_groups.conf'
+       ['5bf51bb24fb41db9b1e448bd060d3f8c']='apps_groups.conf'
+       ['636d032928ea0f4741eab264fb49c099']='apps_groups.conf'
+       ['647361e99b5f4e0d73470c569bb9461c']='apps_groups.conf'
+       ['6a47af861ad3dd112124c37fbf09672b']='apps_groups.conf'
+       ['79a37756869d9b4629285922572d6b9b']='apps_groups.conf'
+       ['99c1617448abbdc493976ab9bda5ce02']='apps_groups.conf'
+       ['9c0185ceff15415bc59b2ce2c1f04367']='apps_groups.conf'
+       ['a0ee8f351f213c0e8af9eb7a4a09cb95']='apps_groups.conf'
+       ['a7cceeafb1e6ef1ead503ab65f687902']='apps_groups.conf'
+       ['a837986be634fd7648bcdf939019424a']='apps_groups.conf'
+       ['a9cd91675467c5426f5b51c47602c889']='apps_groups.conf'
+       ['acaa6731a272f6d251afb357e99b518f']='apps_groups.conf'
+       ['bb51112d01ff20053196a57632df8962']='apps_groups.conf'
+       ['d9258e671d0d0b6498af1ce16ef030d2']='apps_groups.conf'
+       ['ebd0612ccc5807524ebb2b647e3e56c9']='apps_groups.conf'
+       ['f2f1b8656f5011e965ac45b818cf668d']='apps_groups.conf'
+       ['fdea185e0e52b459b48852aa37f20e0f']='apps_groups.conf'
+       ['4ccb06fff1ce06dc5bc80e0a9f568f6e']='charts.d.conf'
+       ['4e995acb0d6fd77403a2a9dca984b55b']='charts.d.conf'
+       ['535e5113b07b0fc6f3abd59546c276f6']='charts.d.conf'
+       ['a02d14124b19c635c1426cee2e98bac5']='charts.d.conf'
+       ['ca026d7c779f0a7cb7787713c5be5c47']='charts.d.conf'
+       ['6b917300747e7e8314844237e2462261']='python.d/apache_cache.conf'
+       ['e0e96cc47ed61d6492416be5236cd4d3']='python.d/apache_cache.conf'
+       ['5278ebbae19c60db600f0a119cb3664e']='python.d/apache.conf'
+       ['5829812db29598db5857c9f433e96fef']='python.d/apache.conf'
+       ['6bf0de6e3b251b765b10a71d8c5c319d']='python.d/apache.conf'
+       ['38d1bf04fe9901481dd6febcc0404a86']='python.d.conf'
+       ['4b775fb31342f1478b3773d041a72911']='python.d.conf'
+       ['99a3de85d1e7826ed64a5f8576712e5d']='python.d.conf'
+       ['9e0553ebdc21b64295873fc104cfa79d']='python.d.conf'
+       ['a2944a309f8ce1a3195451856478d6ae']='python.d.conf'
+       ['af44cc53aa2bc5cc8935667119567522']='python.d.conf'
+       ['b27f10a38a95edbbec20f44a4728b7c4']='python.d.conf'
+       ['b32164929eda7449a9677044e11151bf']='python.d.conf'
+       ['b8969be5b3ceb4a99477937119bd4323']='python.d.conf'
+       ['d55be5bb5e108da1e7645da007c53cd4']='python.d.conf'
+       ['f82924563e41d99cdae5431f0af69155']='python.d.conf'
+       ['7830066c46a7e5f9682b8d3f4566b4e5']='python.d/cpufreq.conf'
+       ['b5b5a8d6d991fb1cef8d80afa23ba114']='python.d/cpufreq.conf'
+       ['dc0d2b96378f290eec3fcf98b89ad824']='python.d/cpufreq.conf'
+       ['a8bb4e1d0525f59692778ad8f675a77a']='python.d/example.conf'
+       ['ae5ac0a3521e50aa6f6eda2a330b4075']='python.d/example.conf'
+       ['e5f32f54d6d6728f21f9ac26f37d6573']='python.d/example.conf'
+       ['15e32114994b92be7853b88091e7c6fb']='python.d/exim.conf'
+       ['73125ae64d5c6e9361944cd9bd14844e']='python.d/exim.conf'
+       ['a94af1c808aafdf00537d85ff2197ec8']='python.d/exim.conf'
+       ['2a0794fd43eadf30a51805bc9ba2c64d']='python.d/hddtemp.conf'
+       ['731a1fcfe9b2da1b9d685056a59541b8']='python.d/hddtemp.conf'
+       ['d74dc63fbe631dab9a2ff1b0f5d71719']='python.d/hddtemp.conf'
+       ['1ea8e8ef1fa8a3a0fcdfba236f4cb195']='python.d/mysql.conf'
+       ['5379cdc26d7725e2b0d688d785816cef']='python.d/mysql.conf'
+       ['7deb236ec68a512b9bdd18e6a51d76f7']='python.d/mysql.conf'
+       ['88f77865f75c9fb61c97d700bd4561ee']='python.d/mysql.conf'
+       ['b0f0a0ac415e4b1a82187b80d211e83b']='python.d/mysql.conf'
+       ['df381f3a7ca9fb2b4b43ae7cb7a4c492']='python.d/mysql.conf'
+       ['061c45b0e34170d357e47883166ecf40']='python.d/nginx.conf'
+       ['21924a6ab8008d16ffac340f226ebad9']='python.d/nginx.conf'
+       ['c61948101e0e6846679682794ee48c5b']='python.d/nginx.conf'
+       ['3ca696189911fb38a0319ddd71e9a395']='python.d/phpfpm.conf'
+       ['8c1d41e2c88aeca78bc319ed74c8748c']='python.d/phpfpm.conf'
+       ['b8b87574fd496a66ede884c5336493bd']='python.d/phpfpm.conf'
+       ['c88fb430f35b7d8f08775d84debffbd2']='python.d/phpfpm.conf'
+       ['d7e0bd12d4a60a761dcab3531a841711']='python.d/phpfpm.conf'
+       ['142a5b693d34b0308bb0b8aec71fad79']='python.d/postfix.conf'
+       ['ca249db7a0637d55abb938d969f9b486']='python.d/postfix.conf'
+       ['39571e9fad9b759200c5d5b2ee13feb4']='python.d/redis.conf'
+       ['b915126262d08aa9da81de539a58a3fb']='python.d/redis.conf'
+       ['837480f77ba1a85677a36747fbc2cd2e']='python.d/sensors.conf'
+       ['cfecf298bdafaa7e0a3a263548e82132']='python.d/sensors.conf'
+       ['64070d856ab1b47a18ec871e49bbc13b']='python.d/squid.conf'
+       ['78bb08809dffcb62e9bc493840f9c039']='python.d/squid.conf'
+       ['78e0065738394f5bf15023f41d66ed4b']='python.d/squid.conf'
+       ['7d8bd884ec26cb35d16c4fc05f969799']='python.d/squid.conf'
+       ['91cf3b3d42cac969b8b3fd4f531ecfb3']='python.d/squid.conf'
+       ['ade389c1b6efe0cff47c33e662731f0a']='python.d/squid.conf'
+       ['e3e5bc57335c489f01b8559f5c70e112']='python.d/squid.conf'
+       ['0388b873d0d7e47c19005b7241db77d8']='python.d/tomcat.conf'
+       ['f7a99e94231beda85c6254912d8d31c1']='python.d/tomcat.conf'
+)
index 10f546746fda55b3b3f1d801316cb3ac1d3539ee..3a7a8d353065d6c6fe36a35d66b385d9138f9bde 100755 (executable)
@@ -78,6 +78,48 @@ usage() {
 USAGE
 }
 
+md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null)"
+get_git_config_signatures() {
+       local x s file md5
+
+       [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
+       [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
+
+       echo >configs.signatures.tmp
+
+       for x in $(find conf.d -name \*.conf)
+       do
+               x="${x/conf.d\//}"
+               echo "${x}"
+               for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
+               do
+                       git checkout ${c} "conf.d/${x}" || continue
+                       s="$(cat "conf.d/${x}" | md5sum | cut -d ' ' -f 1)"
+                       echo >>configs.signatures.tmp "${x}:${s}"
+                       echo "    ${s}"
+               done
+               git checkout HEAD "conf.d/${x}" || break
+       done
+
+       cat configs.signatures.tmp |\
+               grep -v "^$" |\
+               sort -u |\
+               {
+                       echo "declare -A configs_signatures=("
+                       IFS=":"
+                       while read file md5
+                       do
+                               echo "  ['${md5}']='${file}'"
+                       done
+                       echo ")"
+               } >configs.signatures
+
+       rm configs.signatures.tmp
+
+       return 0
+}
+
+
 while [ ! -z "${1}" ]
 do
        if [ "$1" = "--install" ]
@@ -100,6 +142,10 @@ do
                then
                usage
                exit 1
+       elif [ "$1" = "get_git_config_signatures" ]
+               then
+               get_git_config_signatures && exit 0
+               exit 1
        else
                echo >&2
                echo >&2 "ERROR:"
@@ -336,13 +382,32 @@ fi
 echo >&2 "Compiling netdata ..."
 run make || exit 1
 
+declare -A configs_signatures=()
+if [ -f "configs.signatures" ]
+       then
+       source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
+fi
+
 # backup user configurations
 installer_backup_suffix="${PID}.${RANDOM}"
 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
 do
        if [ -f "${x}" ]
                then
-               cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
+               if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
+                       then
+                       cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
+               else
+                       f="${x/*\/etc\/netdata\//}"
+                       md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
+                       if [ "${configs_signatures[${md5}]}" = "${f}" ]
+                               then
+                               echo >&2 "File '${x}' is stock version."
+                       else
+                               echo >&2 "File '${x}' has been edited by user."
+                               cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
+                       fi
+               fi
 
        elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
                then