update 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env bash
  2. # generic update scripts for updating configs and such
  3. #
  4. # Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org>
  5. # Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
  6. # Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. [ "x${DEBUG+set}" = 'xset' ] && set -v
  22. set -u -e
  23. projectname="$(cat projectname)"
  24. ./resources/scripts/misc/versioncheck
  25. update=./resources/scripts/update
  26. listmodes() {
  27. for mode in "${update}"/*; do
  28. printf '%s\n' "${mode##*/}"
  29. done
  30. }
  31. # Takes exactly one mode as parameter
  32. listoptions() {
  33. for option in "${update}"/"${1}"/*; do
  34. printf '%s\n' "${option##*/}"
  35. done
  36. }
  37. help() {
  38. cat <<- EOF
  39. USAGE: ./update <MODE> <OPTION>
  40. possible values for 'mode':
  41. $(listmodes)
  42. Example: ./update coreboot configs
  43. Example: ./update coreboot configs x60
  44. Refer to the ${projectname} documentation for more information.
  45. EOF
  46. }
  47. die() {
  48. printf 'Error: %s\n' "${@}" 1>&2
  49. exit 1
  50. }
  51. if [ $# -lt 1 ]; then
  52. die "Wrong number of arguments specified. See './update help'."
  53. fi
  54. mode="${1}"
  55. [ "${mode}" = help ] && help && exit 0
  56. if [ $# -gt 1 ]; then
  57. option="${2}"
  58. shift 2
  59. case "${option}" in
  60. list)
  61. printf "Available options for mode '%s':\n\n" "${mode}"
  62. listoptions "${mode}"
  63. ;;
  64. all)
  65. for option in $(listoptions "${mode}"); do
  66. "${update}"/"${mode}"/"${option}" $@
  67. done
  68. ;;
  69. *)
  70. if [ -d "${update}"/"${mode}"/ ]; then
  71. if [ -f "${update}"/"${mode}"/"${option}" ]; then
  72. "${update}"/"${mode}"/"${option}" $@
  73. else
  74. help
  75. die "Invalid option for '${mode}'. See './update ${mode} list'."
  76. fi
  77. else
  78. help
  79. die "Invalid mode '${mode}'. See './update help'."
  80. fi
  81. esac
  82. else
  83. help
  84. exit 0
  85. fi