blob: d135a7d32459e86b86f24ef818cc2561f2f8ef10 (
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#!/bin/bash
# parameters
MIRROR_DIR="/srv/http/mirror/mirror.archlinux32.org"
ARCHIVE_DIR="/srv/http/mirror/archive.archlinux32.org"
usage() {
>&2 echo ""
>&2 echo "cleanup-isos: cleanup mirror and archive ISOs of Archlinux32"
>&2 echo ""
>&2 echo "possible options:"
>&2 echo " -h|--help: show this help and exit."
>&2 echo " --mirror-dir where are the ISOs stored on the mirror, default is '$MIRROR_DIR'."
>&2 echo " --archive-dir where are the ISOs stored in the archive, default is '$ARCHIVE_DIR'."
>&2 echo " -n do not do anything, just print what would be done."
[ -z "$1" ] && exit 1 || exit "$1"
}
# fail on first error
set -e
# cleanup hook
tmp_dir="$(mktemp -d)"
cleanup() {
rm -rf --one-file-system "${tmp_dir}"
}
trap cleanup EXIT
eval set -- "$(
getopt -o hn \
--long help \
--long mirror-dir: \
--long archive-dir: \
-n "$(basename "$0")" -- "$@" || \
echo usage
)"
mirror_dir="${MIRROR_DIR}"
archive_dir="${ARCHIVE_DIR}"
do_it=1
while [ $# -gt 0 ]; do
case "$1" in
'--mirror-dir')
shift
mirror_dir="$1"
;;
'--archive-dir')
shift
archive_dir="$1"
;;
'-n')
do_it=0
;;
'--help'|'-h')
usage 0
;;
'--')
shift
break
;;
*)
printf 'Whoops, option "%s" is not yet implemented!\n' "$1" >&2
exit 42
;;
esac
shift
done
if [ $# -gt 0 ]; then
>&2 echo 'Too many arguments.'
exit 2
fi
archiso_dir="${mirror_dir}/archisos/"
archived_archiso_dir="${archive_dir}/iso/"
echo "checking for old isos in '${archiso_dir}'..."
find "${archiso_dir}" \( -name 'archlinux32-*' -o -name 'archlinux-*' \) -not -name 'archlinux32-'"${date}"'-*' \
| while read -r to_delete; do
archived_file="${archived_archiso_dir}/${to_delete#${archiso_dir}/}"
if [ -f "${to_delete}" -a -f "${archived_file}" ]; then
if diff -q "${to_delete}" "${archived_file}" >/dev/null; then
rm "${to_delete}"
printf '%s\n' "${to_delete}" \
| sed '
s@^.*/@@
s/\./\\./g
s@.*@/ \0$/d@
'
fi
fi
done \
>> "${tmp_dir}/delete-regex"
sed -i -f "${tmp_dir}/delete-regex" "${archiso_dir}/sha512sums"
sed -i -f "${tmp_dir}/delete-regex" "${archiso_dir}/md5sums"
echo '... done.'
exit 0
|