Advertisement
626Pilot

ConfigComparator.sh

Mar 5th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.37 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl) with additions from Sungeun K. Jeon (https://github.com/chamnit/grbl)
  4. # Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  5. # Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. # You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
  7.  
  8. # ----------------------------
  9. # Functions
  10. # ----------------------------
  11.  
  12. # ANSI color helpers
  13. setColor () {
  14.         echo -n "\033[$1m"
  15. }
  16. resetColor () {
  17.         echo -n "\033[0m"
  18. }
  19.  
  20. # Online help
  21. printHelp () {
  22.  
  23.         echo    "\n" \
  24.                 "From time to time, new settings are added to Smoothie's config file. If you're\n" \
  25.                 "maintaining your own fork, you can use this script to verify that your config\n" \
  26.                 "isn't missing anything new.\n"
  27.  
  28.         setColor "1;37"
  29.         echo    "USAGE: ./ConfigComparator.sh upstreamConfigFile yourConfigFile" \
  30.                 "\n"
  31.         resetColor
  32.  
  33. }
  34.  
  35. # Find keywords (first token in line) that are present in the first file, but not the second.
  36. # Lines must begin with an alpha char, so we don't accidentally register options mentioned in comments as
  37. # though they were valid options that will be parsed by Smoothie.
  38. checkMismatches () {
  39.  
  40.         # Extract only keywords (line must start with alpha char, so we ignore whitespace, comments, =, etc.)
  41.         KEYWORDS=`cat "$1" |awk {'print $1'} |uniq |grep '^[[:alpha:]].*'`
  42.  
  43.         # See which keywords are in FILE1, but not FILE2.
  44.         mismatches=0
  45.         for i in $KEYWORDS; do
  46.  
  47.                 cmd="eval grep '^$i\.*' $2"
  48.                 out=`$cmd`
  49.                 if [ -z "$out" ]; then
  50.                         echo "Keyword '$i' not found in $2."
  51.                         mismatches=$((mismatches+1))
  52.                 fi
  53.  
  54.         done
  55.  
  56.         echo "Found $mismatches mismatches."
  57.  
  58. }
  59.  
  60.  
  61.  
  62. # ----------------------------
  63. # Program Entry
  64. # ----------------------------
  65.  
  66. setColor "1;36"
  67. echo "Smoothie Config Comparator by 626Pilot"
  68. setColor "1;37"
  69. echo "--------------------------------------"
  70. echo ""
  71. resetColor
  72.  
  73. FILE1="$1"
  74. FILE2="$2"
  75.  
  76. if [ ! -e "$FILE1" ]; then
  77.         echo "File '$FILE1' not found."
  78.         printHelp
  79.         exit 1
  80. fi
  81.  
  82. if [ ! -e "$FILE2" ]; then
  83.         echo "File '$FILE2' not found."
  84.         printHelp
  85.         exit 1
  86. fi
  87.  
  88. setColor "1;32"
  89. echo "Checking for new options:"
  90. setColor "0;32"
  91.  
  92. checkMismatches $FILE1 $FILE2
  93.  
  94. echo ""
  95.  
  96. setColor "1;31"
  97. echo "Checking for POTENTIALLY obsolete options. Anything that's unique to your branch can be ignored."
  98. echo "The rest may be old options that have been removed!"
  99. setColor "0;31"
  100.  
  101. checkMismatches $FILE2 $FILE1
  102.  
  103. resetColor
  104.  
  105. echo
  106. echo "Please note that commented lines (beginning with #) are IGNORED! This means"
  107. echo "that, for example, 'panel.contrast' will be found, but '#panel.contrast'"
  108. echo "will not."
  109. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement