-
Notifications
You must be signed in to change notification settings - Fork 28
/
packing.sh
74 lines (61 loc) · 1.13 KB
/
packing.sh
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
#!/bin/bash
if test $# -lt 2 || test $# -gt 4; then
echo ""
echo "Wrong! check the follow usages!"
echo "usages : $0 <source_dir> <target_dir> [group] [project]"
echo "example : $0 data archieves"
echo "example : $0 data archieves Apache CAMEL"
echo ""
echo ""
exit 1
fi
curdir=$('pwd')
last_term=""
last_string()
{
string=$1
new=${string#*$2}
if [ "$string" != "$new" ]; then
last_string $new $2
new=$last_term
fi
last_term=$new
return
}
# start work
TARGET="$2"
SGROUP="$3"
SPROJECT="$4"
echo ""
echo ""
echo "start packing..."
for var in "$1"/*
do
if test -f $var; then
continue
fi
last_string $var "/"
group=$last_term
if test "$SGROUP" != "" && test "$group" != "$SGROUP" ; then
continue
fi
if test ! -d "$2/$group"; then
mkdir "$2/$group"
fi
for entry in "$var"/*
do
last_string $entry "/"
project=$last_term
if test -d $entry
then
if test "$SPROJECT" != "" && test "$project" != "$SPROJECT"; then
continue
fi
echo "packing $entry to $2/$group/$project.tar"
cd $1/$group/$project
tar -cf $curdir/$2/$group/$project.tar ./
cd $curdir
fi
done
done
echo "Done!"