source: branches/contrib/bitten/scripts/clean.sh @ 475

Last change on this file since 475 was 475, checked in by amain, 7 years ago

bitten: fix bug in clean.sh which couldn't handle the new dir layout

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/bin/bash
2#
3# Copyright (C) 2012 Johan van Zoomeren <amain@debwrt.net>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18if [ "${2}" == "" ]
19then
20cat <<EOF
21usage: $(basename $0) <method> <config/architecture/system/profile>
22
23Cleans builds in ${work:-<buildir>}.
24
25   method       keep-previous: keep previous build
26                keep-none: clean all previous builds
27   config       Bitten Recipe Config short name
28   architecture mips, mipsel, ...
29   system       ar71xx, ...
30   profile      ubntrspro, ....
31
32example:
33
34  clean.sh keep-last user/mips/ar71xx/ubntrspro
35
36EOF
37   
38   exit 1
39fi
40
41
42method=${1}
43work=~/build/${2}
44
45function keep()
46{
47   local method=${1:-keep-previous}
48   local keep_last=${2:-2}
49
50   echo "I: cleaning builds in ${work} using method '${method}'"
51
52   find ${work} -maxdepth 1 -regex ".*/[0-9]+"  \
53     | sort -V \
54     | head -n -${keep_last} \
55     | while read dir
56       do
57          echo -n "   ${dir}..."
58          sudo rm -rf ${dir}
59          echo "done"
60       done
61}
62
63case ${method} in
64   keep-none) keep ${method} 1;;
65   keep-previous) keep ${method} 2;;
66   *) echo "E: method '${method} not found";;
67esac
68
Note: See TracBrowser for help on using the repository browser.