.gitcheck 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env sh
  2. # SPDX-FileCopyrightText: 2022 Caleb La Grange <thonkpeasant@protonmail.com>
  3. # SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
  4. # SPDX-License-Identifier: GPL-3.0-only
  5. git_name="lbmkplaceholder"
  6. git_email="placeholder@lbmkplaceholder.com"
  7. main()
  8. {
  9. if [ $# -gt 0 ]; then
  10. if [ "${1}" = "clean" ]; then
  11. clean > /dev/null 2> /dev/null
  12. else
  13. printf "%s: Unsupported argument\n" $0
  14. exit 1
  15. fi
  16. else
  17. set_placeholders > /dev/null 2> /dev/null
  18. fi
  19. }
  20. set_placeholders()
  21. {
  22. set_git_credentials
  23. # Check coreboot as well to prevent errors during building
  24. if [ ! -d coreboot ]; then
  25. return
  26. fi
  27. for x in coreboot/*; do
  28. if [ ! -d "${x}" ]; then
  29. continue
  30. fi
  31. (
  32. cd "${x}"
  33. set_git_credentials
  34. )
  35. done
  36. }
  37. set_git_credentials()
  38. {
  39. # Check if username and or email is set.
  40. if ! git config user.name || git config user.email ; then
  41. git config user.name \
  42. || git config user.name "${git_name}"
  43. git config user.email \
  44. || git config user.email "${git_email}"
  45. fi
  46. }
  47. clean()
  48. {
  49. unset_placeholders
  50. if [ ! -d coreboot ]; then
  51. return
  52. fi
  53. for x in coreboot/*; do
  54. if [ ! -d "${x}" ]; then
  55. continue
  56. fi
  57. (
  58. cd "${x}"
  59. unset_placeholders
  60. )
  61. done
  62. }
  63. unset_placeholders()
  64. {
  65. if [ "$(git config user.name)" = "${git_name}" ]; then
  66. git config --unset user.name
  67. fi
  68. if [ "$(git config user.email)" = "${git_email}" ]; then
  69. git config --unset user.email
  70. fi
  71. }
  72. main $@