-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrtems-cron-cleandir
executable file
·122 lines (97 loc) · 2.25 KB
/
rtems-cron-cleandir
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /bin/sh
#
# Example invocation for a 5.x release snapshot
# ~/rtems-cron-helpers/rtems-cron-cleandir \
# -D ${HOME}/rtems-cron-5.0.0-m2005-1 \
USAGE=\
"usage: $progname [ -opts ]
-d do deep clean (default=no)
-D DIRECTORY top Directory (default=NOT_SET)
-u report disk usage before and after (default=no)
-v verbose (default=no)
Normal clean removes build artifacts.
Deep clean removes tools, sources, and patches.
"
# log an error to stderr
prerr()
{
echo "$*" >&2
}
fatal() {
[ "$1" ] && prerr $*
prerr "$USAGE"
exit 1
}
warn() {
[ "$1" ] && prerr $*
}
check_status()
{
if [ $1 -ne 0 ] ; then
shift
echo "FAILED: " "$*" >&2
exit 1
fi
}
# directory where run from
exedir=`dirname "$0"`
exedir=`( cd "${exedir}" && pwd )`
# Default Behavioral variables to set
verbose="no"
TOP=NOT_SET
do_du="no"
do_deep_clean="no"
while getopts "dD:uv" OPT
do
case "$OPT" in
d) do_deep_clean="yes";;
D) TOP="$OPTARG";;
u) do_du="yes";;
v) verbose="yes";;
*) fatal;;
esac
done
shiftcount=`expr $OPTIND - 1`
shift $shiftcount
test ${TOP} != "NOT_SET"
check_status $? "TOP directory not specified"
test -d ${TOP}
check_status $? "TOP directory does not exist -- ${TOP}"
######## Done checking arguments
if [ ${verbose} = "yes" ] ; then
echo "Top directory : " ${TOP}
echo "Do Deep Clean : " ${do_deep_clean}
echo "Report Disk Usage : " ${do_du}
echo "Verbose : " ${verbose}
echo
fi
# Disk usage before clean up
if [ ${do_du} = "yes" ] ; then
echo BEFORE: `du -s -h ${TOP}`
fi
# Now remove build artifacts
# clean rtems directory
cd ${TOP}/rtems
check_status $? "cd ${TOP}/rtems failed"
rm -rf *.log config-*.ini build b-*
./waf distclean >/dev/null
check_status $? "waf distclean failed"
# clean RSB
for RSBDIR in rtems bare
do
cd ${TOP}/rtems-source-builder/${RSBDIR}
check_status $? "cd ${TOP}/${RSBDIR} failed"
rm -rf build tmp l-* nohup* rsb*
if [ ${do_deep_clean} = "yes" ] ; then
rm -rf sources patches
fi
done
# Clean up tools -- only tools/5, etc.
if [ ${do_deep_clean} = "yes" ] ; then
rm -rf ${TOP}/tools/[5678]
fi
# Disk usage after clean up
if [ ${do_du} = "yes" ] ; then
echo AFTER: `du -s -h ${TOP}`
fi
exit 0