update 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  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. update=./resources/scripts/update
  24. listmodes() {
  25. for mode in "${update}"/*; do
  26. printf '%s\n' "${mode##*/}"
  27. done
  28. }
  29. # Takes exactly one mode as parameter
  30. listoptions() {
  31. for option in "${update}"/"${1}"/*; do
  32. printf '%s\n' "${option##*/}"
  33. done
  34. }
  35. help() {
  36. cat <<- EOF
  37. USAGE: ./update <MODE> <OPTION>
  38. possible values for 'mode':
  39. $(listmodes)
  40. Example: ./update coreboot configs
  41. Example: ./update coreboot configs x60
  42. Refer to the osboot documentation for more information.
  43. EOF
  44. }
  45. die() {
  46. printf 'Error: %s\n' "${@}" 1>&2
  47. exit 1
  48. }
  49. if [ $# -lt 1 ]; then
  50. die "Wrong number of arguments specified. See './update help'."
  51. fi
  52. mode="${1}"
  53. [ "${mode}" = help ] && help && exit 0
  54. if [ $# -gt 1 ]; then
  55. option="${2}"
  56. shift 2
  57. case "${option}" in
  58. list)
  59. printf "Available options for mode '%s':\n\n" "${mode}"
  60. listoptions "${mode}"
  61. ;;
  62. all)
  63. for option in $(listoptions "${mode}"); do
  64. "${update}"/"${mode}"/"${option}" $@
  65. done
  66. ;;
  67. *)
  68. if [ -d "${update}"/"${mode}"/ ]; then
  69. if [ -f "${update}"/"${mode}"/"${option}" ]; then
  70. "${update}"/"${mode}"/"${option}" $@
  71. else
  72. help
  73. die "Invalid option for '${mode}'. See './update ${mode} list'."
  74. fi
  75. else
  76. help
  77. die "Invalid mode '${mode}'. See './update help'."
  78. fi
  79. esac
  80. else
  81. help
  82. exit 0
  83. fi