.gitcheck 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env bash
  2. # SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  3. # SPDX-License-Identifier: GPL-3.0-only
  4. Fail(){
  5. printf "${@}\n"
  6. exit 1
  7. }
  8. Set_placeholder(){
  9. git config user.name || git config user.name 'osbmkplaceholder'
  10. git config user.email || git config user.email 'placeholder@osbmkplaceholder.com'
  11. }
  12. Clean(){
  13. if [ "$(git config user.name)" = "osbmkplaceholder" ]; then
  14. git config --unset user.name
  15. fi
  16. if [ "$(git config user.email)" = "placeholder@osbmkplaceholder.com" ]; then
  17. git config --unset user.email
  18. fi
  19. }
  20. Revision_check(){
  21. name=${1}
  22. while read -r line ; do
  23. set ${line} >/dev/null 2>&1
  24. case ${line} in
  25. rev:*)
  26. revision=${2}
  27. ;;
  28. loc:*)
  29. location=${2}
  30. ;;
  31. url:*)
  32. url=${2}
  33. ;;
  34. bkup_url:*)
  35. bkup_url=${2}
  36. ;;
  37. esac
  38. done <<< $(eval "awk ' /\{.*${name}.*}{/ {flag=1;next} /\}/{flag=0} flag { print }' resources/git/revisions")
  39. # Do not check for non-existent projects
  40. if [ ! -d ${location} ]; then
  41. return 0
  42. fi
  43. _cur_revision=$(cd ${location} && git rev-parse --verify HEAD)
  44. if [ "${_cur_revision}" = "${revision}" ]; then
  45. return 0
  46. elif $(git log -n15 --format=format:"%H" | grep -q "${revision}") ; then
  47. return 0
  48. else
  49. (
  50. cd ${location} || return 1
  51. # Avoid accidentally operating on parent git
  52. if [ ! -d '.git/' ]; then
  53. return 0
  54. fi
  55. # For modules with patches, the current git hash will be wrong, but the correct one
  56. # will be somewhere in the log.
  57. if $(git log -n15 --format=format:"%H" | grep -q "${revision}") ; then
  58. return 0
  59. else
  60. printf "WARNING: gitmodule ${name} is behind the current version in osbmk\nRun: './download gitmodule ${name}' to make sure you're at the latest version"
  61. fi
  62. )
  63. fi
  64. }
  65. Check_versions(){
  66. gitmodules=$(awk -F '[{}]' '/^{.*}{/ {print $2}' resources/git/revisions)
  67. for gitmodule in ${gitmodules} ; do
  68. Revision_check "${gitmodule}"
  69. done
  70. }
  71. Run(){
  72. if [ ! -d ".git/" ]; then
  73. git init
  74. fi
  75. if [ "${1}" = "clean" ]; then
  76. Clean
  77. else
  78. # Check if username and or email is set.
  79. if ! git config user.name || git config user.email ; then
  80. Set_placeholder
  81. fi
  82. fi
  83. }
  84. Run >/dev/null
  85. Check_versions