#!/bin/sh # clean up unnecessary data # shellcheck disable=SC2119,SC2120 # shellcheck source=../lib/load-configuration . "${0%/*}/../lib/load-configuration" # TODO: clean database, too # we only clean if run interactive or if no one is logged in if ! tty -s && \ [ -n "$(users)" ]; then >&2 echo 'Skipping clean up.' exit fi if [ -s "${work_dir}/build-master-sanity" ]; then >&2 echo 'Build master is not sane.' exit fi # remove logs where package is not broken/locked anymore { find "${build_log_directory}/error" -maxdepth 1 -type f -printf 'file %f\n' # shellcheck disable=SC2016 printf 'SELECT "mysql",`failed_builds`.`log_file` FROM `failed_builds`;\n' | \ mysql_run_query | \ tr '\t' ' ' } | \ sort -k2,2 -k1,1 | \ uniq -uf 1 | \ sed -n ' s/^file // T p ' | \ while read -r file; do rm "${build_log_directory}/error/${file}" done # only keep 10 newest logs per failed package and fail_reason # shellcheck disable=SC2016 { printf 'SELECT' printf ' CONCAT(`failed_builds`.`reason`,"-",`failed_builds`.`build_assignment`),' printf '`failed_builds`.`id`,' printf '`failed_builds`.`log_file`' printf ' FROM `failed_builds`' printf ' WHERE `log_file_exists`' printf ' ORDER BY' printf ' `failed_builds`.`reason`,' printf '`failed_builds`.`build_assignment`,' printf '`failed_builds`.`date` DESC;\n' } | \ mysql_run_query | \ { count=0 old_group='' while read -r group id log_file; do if [ "${group}" != "${old_group}" ]; then count=0 old_group="${group}" fi if [ ${count} -ge 10 ]; then rm "${build_log_directory}/error/${log_file}" printf '%s,' "${id}" fi count=$((count+1)) done } | \ sed ' s/,$/);\n/ s/^/DELETE FROM `failed_builds` WHERE `failed_builds`.`id` IN (/ ' | \ mysql_run_query # only keep namcap logs of last 2 weeks for succeeded packages find "${build_log_directory}/success" -maxdepth 1 -type f -mtime +14 \ -not -exec zgrep -q '^+.*ELF file .* has text relocations' '{}' \; \ -delete exit 0