summaryrefslogtreecommitdiffstats
path: root/contrib/trials-cleanup.sh
blob: 830f4e71f83941224f80c9f024bfe2f18679cd20 (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
#!/bin/sh
# Remove all but the N newest test run dirs (that have been started)

trial_rx_dir="$1"
trial_prep_dir="$2"
if [ -z "$trial_rx_dir" ]; then
	trial_rx_dir="/var/tmp/osmo-gsm-tester/trials"
fi
if [ -z "$trial_prep_dir" ]; then
	trial_prep_dir="/var/tmp/osmo-gsm-tester/.prep-trials"
fi

mkdir -p "$trial_prep_dir"

rm_trial() {
	trial_dir="$1"
	trial_name="$(basename "$trial_dir")"
	echo "Removing: $(ls -ld "$trial_dir")"
	# ensure atomic removal, so that the gsm-tester doesn't take it as a
	# newly added dir (can happen when the 'taken' marker is removed first).
	mv "$trial_dir" "$trial_prep_dir/"
	rm -rf "$trial_prep_dir/$trial_name"
}

# keep the N newest test session dirs that have been started: find all that
# have been started sorted by time, then discard all but the N newest ones.

for seen in $(ls -1t "$trial_rx_dir"/*/taken | tail -n +31); do
	rm_trial "$(dirname "$seen")"
done