clean-hashserver-database 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. set -euo pipefail
  3. SSTATE_DIR=""
  4. BB_HASHCLIENT=""
  5. BB_HASHSERVER=""
  6. ALIVE_DB_MARK="alive"
  7. CLEAN_DB="false"
  8. THRESHOLD_AGE="3600"
  9. function help() {
  10. cat <<HELP_TEXT
  11. Usage: $0 --sstate-dir path --hashclient path --hashserver-address address \
  12. [--mark value] [--clean-db] [--threshold-age seconds]
  13. Auxiliary script remove unused or no longer relevant entries from the hashequivalence database, based
  14. on the files available on the sstate directory.
  15. -h | --help) Show this help message and exit
  16. -a | --hashserver-adress) bitbake-hashserver address
  17. -c | --hashclient) Path to bitbake-hashclient
  18. -m | --mark) Marker string to mark database entries
  19. -s | --sstate-dir) Path to the sstate dir
  20. -t | --threshold-age) Remove unused entries older than SECONDS old (default: 3600)
  21. --clean-db) Remove all unmarked and unused entries from the database
  22. HELP_TEXT
  23. }
  24. function argument_parser() {
  25. while [ $# -gt 0 ]; do
  26. case "$1" in
  27. -h | --help) help; exit 0 ;;
  28. -a | --hashserver-address) BB_HASHSERVER="$2"; shift ;;
  29. -c | --hashclient) BB_HASHCLIENT="$2"; shift ;;
  30. -m | --mark) ALIVE_DB_MARK="$2"; shift ;;
  31. -s | --sstate-dir) SSTATE_DIR="$2"; shift ;;
  32. -t | --threshold-age) THRESHOLD_AGE="$2"; shift ;;
  33. --clean-db) CLEAN_DB="true";;
  34. *)
  35. echo "Argument '$1' is not supported" >&2
  36. help >&2
  37. exit 1
  38. ;;
  39. esac
  40. shift
  41. done
  42. function validate_mandatory_argument() {
  43. local var_value="$1"
  44. local error_message="$2"
  45. if [ -z "$var_value" ]; then
  46. echo "$error_message"
  47. help >&2
  48. exit 1
  49. fi
  50. }
  51. validate_mandatory_argument "$SSTATE_DIR" "Please provide the path to the sstate dir."
  52. validate_mandatory_argument "$BB_HASHCLIENT" "Please provide the path to bitbake-hashclient."
  53. validate_mandatory_argument "$BB_HASHSERVER" "Please provide the address of bitbake-hashserver."
  54. }
  55. # -- main code --
  56. argument_parser $@
  57. # Mark all db sstate hashes
  58. find "$SSTATE_DIR" -name "*.tar.zst" | \
  59. sed 's/.*:\([^_]*\)_.*/unihash \1/' | \
  60. $BB_HASHCLIENT --address "$BB_HASHSERVER" gc-mark-stream "$ALIVE_DB_MARK"
  61. # Remove unmarked and unused entries
  62. if [ "$CLEAN_DB" = "true" ]; then
  63. $BB_HASHCLIENT --address "$BB_HASHSERVER" gc-sweep "$ALIVE_DB_MARK"
  64. $BB_HASHCLIENT --address "$BB_HASHSERVER" clean-unused "$THRESHOLD_AGE"
  65. fi