-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·38 lines (32 loc) · 850 Bytes
/
cleanup.sh
File metadata and controls
executable file
·38 lines (32 loc) · 850 Bytes
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
#!/bin/bash
KEEPVERSIONS=3
CLEANUPDIRS="build/dev-20 build/master-20 build/os2web-master-20 build/os2web-dev-20"
DONTDEL=""
for i in $(ls -d build/*latest)
do
DONTDEL="$DONTDEL "$(basename $(readlink -f $i))
done
DELDIRS=""
for DIR in $CLEANUPDIRS
do
ls -d -r $DIR* 2>/dev/null | awk "NR>$KEEPVERSIONS"
DELDIRS="$DELDIRS "$(ls -d -r $DIR* 2>/dev/null | awk "NR>$KEEPVERSIONS")
done
# Try to avoid deleting the latest symlink
for i in $DONTDEL
do
if [[ "$DELDIRS" == *"$i"* ]]; then
echo "$i is used in a latest symlink. Aborting"
exit 2
fi
done
# trim spaces
DELDIRS=$(echo $DELDIRS | xargs)
if [ "$DELDIRS" == "" ]
then
echo "Nothing to delete"
exit 1
else
read -p "Going to delete the above dir(s) (all old builds except the newest $KEEPVERSIONS). Press ctrl-c to cancel or any key to continue"
rm -rf $DELDIRS
fi