Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/cleanup
blob: 93af0bc468fefcf21c69de0f805ab23e581d1cdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh

# clean up unnecessary data

. "${0%/*}/../conf/default.conf"

# 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 1
fi

# remove blocked/broken/locked markes of packages not on the buildlist anymore

(
  ls "${work_dir}/package-states" | \
    grep '\.broken$\|\.b\?locked$' | \
    sed '
      s|^\(.*\)\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)$|state \0 \1 \2 \3 \4 \5|
    '
  awk '{
    print "order " $1 "." $2 "." $3 "." $4 " " $1 " " $2 " " $3 " " $4 " broken"
    print "order " $1 "." $2 "." $3 "." $4 " " $1 " " $2 " " $3 " " $4 " blocked"
    print "order " $1 "." $2 "." $3 "." $4 " " $1 " " $2 " " $3 " " $4 " locked"
  }' "${work_dir}/build-list"
) | \
  sort -k3 | \
  uniq -uf2 | \
  grep '^state ' | \
  awk '{print $2}' | \
  sed "s|^|${work_dir}/package-states/|" | \
  xargs -rn1 rm

# remove logs where package is not broken/locked anymore

(
  ls "${build_log_directory}" | \
    sed 's|\.[^.]\+\.build-log\.gz$||' | \
    sort -u
  ls "${work_dir}/package-states" | \
    grep '\.broken$\|\.locked$' | \
    sed '
      s|\.[^.]\+$||
      p
    '
) | \
  sort | \
  uniq -u | \
  while read -r s t; do
    rm -f "${build_log_directory}/${s}."*
  done

# only keep 10 newest logs per package

ls "${build_log_directory}" | \
  sed 's|^\(.*\)\(\.\([^.]\+\)\.build-log\.gz\)$|\1\2 \3 \1|' | \
  sort -k3,3 -k2r,2 | \
  uniq -f2 --group=prepend | \
  (
    count=0
    while read -r a b c; do
      if [ -z "${a}" ]; then
        count=0
        continue
      fi
      if [ ${count} -ge 10 ]; then
        echo "${build_log_directory}/${a}"
      fi
      count=$((${count}+1))
    done
  ) | \
  xargs -rn1 rm

# remove old package meta data
delete_old_metadata