opkg-check-config 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /bin/sh
  2. #
  3. # opkg config checker and upgrade script
  4. #
  5. # Copyright (C) 2014 Paul Barker
  6. #
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by the
  9. # Free Software Foundation; either version 2, or (at your option) any
  10. # later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. set -e
  17. if [ "$#" -eq 2 ]; then
  18. file_in=$1
  19. file_out=$2
  20. inplace=0
  21. elif [ "$#" -eq 1 ]; then
  22. file_in=$1
  23. file_out=`mktemp`
  24. inplace=1
  25. else
  26. cat 1>&2 << EOF
  27. Usage: $0 <file_in> <file_out>
  28. The script reads an opkg config file specified by <file_in> and performs
  29. sanity checks. It may automatically fix some errors, especially those where the
  30. config syntax or option names have changed during an opkg upgrade. The fixed
  31. file will be written to <file_out> if this argument is given, otherwise
  32. <file_in> will be fixed in place. Warning and error messages will be printed to
  33. stderr.
  34. EOF
  35. exit 1
  36. fi
  37. # v0.2.x to v0.3.0 upgrade: lists_dir syntax has changed
  38. #
  39. # The old lists_dir statement had the syntax 'lists_dir ext path' where 'ext'
  40. # was ignored. The new syntax is 'option lists_dir path'.
  41. awk_lists_dir='$1 == "lists_dir" { print "option lists_dir " $3 ; \
  42. print "Fixed: " $0 " -> option lists_dir " $3 > "/dev/stderr" ; \
  43. next }'
  44. # Combine scripts and add terminating '1' statement which will print all
  45. # unmatched lines (assuming each match finishes with 'next').
  46. awk_script="$awk_lists_dir 1"
  47. # Run awk_script
  48. awk "$awk_script" < $file_in > $file_out
  49. if [ "$inplace" -eq 1 ]; then
  50. mv $file_out $file_in
  51. fi