Stephan Massalt | 752d3b6 | 2020-02-01 17:19:46 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Austin Schuh | 512b98f | 2020-12-28 13:12:16 -0800 | [diff] [blame] | 3 | # Set default for disk utilisation |
| 4 | readonly DMAX="${1:-80%}" |
| 5 | # Cache folder |
James Kuszmaul | 8c9ab9a | 2024-01-14 20:10:41 -0800 | [diff] [blame] | 6 | readonly CACHE_FOLDER="${HOME}/.cache/bazel/" |
| 7 | readonly BUILDS_FOLDER="${HOME}/builds/${BUILDKITE_AGENT_NAME}/spartan-robotics/" |
Austin Schuh | 512b98f | 2020-12-28 13:12:16 -0800 | [diff] [blame] | 8 | # Retrieve disk usages in percentage |
| 9 | readonly DSIZE="$(df -hlP "${CACHE_FOLDER}" | sed 1d | awk '{print $5}')" |
Stephan Massalt | 752d3b6 | 2020-02-01 17:19:46 -0800 | [diff] [blame] | 10 | |
Austin Schuh | 512b98f | 2020-12-28 13:12:16 -0800 | [diff] [blame] | 11 | if [[ ${DSIZE} > ${DMAX} ]]; then |
| 12 | echo "$(hostname): Disk over ${DMAX} Clean up needed on node." |
James Kuszmaul | 8c9ab9a | 2024-01-14 20:10:41 -0800 | [diff] [blame] | 13 | # Ensure that everything has permissions such that it can be deleted. |
| 14 | chmod --recursive 777 ${CACHE_FOLDER} |
| 15 | chmod --recursive 777 "${BUILDS_FOLDER}"/*_output_base |
Austin Schuh | 512b98f | 2020-12-28 13:12:16 -0800 | [diff] [blame] | 16 | rm -rf "${CACHE_FOLDER}" |
James Kuszmaul | 8c9ab9a | 2024-01-14 20:10:41 -0800 | [diff] [blame] | 17 | # Don't delete the git checkout. |
| 18 | rm -rf "${BUILDS_FOLDER}"/*_output_base |
Stephan Massalt | 752d3b6 | 2020-02-01 17:19:46 -0800 | [diff] [blame] | 19 | else |
Austin Schuh | 512b98f | 2020-12-28 13:12:16 -0800 | [diff] [blame] | 20 | echo "$(hostname): No clean up needed. Disk usage is at: ${DSIZE}" |
Stephan Massalt | 752d3b6 | 2020-02-01 17:19:46 -0800 | [diff] [blame] | 21 | fi |