-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathneed.sh
executable file
·54 lines (45 loc) · 959 Bytes
/
need.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
#! /usr/bin/env bash
PORT=../portable-git
HERE=./portable
#e=echo
copy() {
for f in $*; do
t=$PORT/$f
h=$HERE/$f
if [ -d $t ]; then
$e mkdir -p $h
$e cp -pr $t/ $h
continue
elif [ ! -f $t ]; then
echo "$0: Can't find $f .." 1>&2
continue
fi
b=$(dirname $h)
$e mkdir -p $b
$e cp $t $HERE/$f
done
}
sync() {
find $HERE -type f | \
while read f; do
b=${f##$HERE/}
t=$PORT/$b
[ $t -nt $f ] && cp -v $t $f
done
}
die() {
echo "$@" 1>&2
exit 1
}
if [ "x$1" = "x" ]; then
die "Usage: $0 copy|sync file|dir [file|dir ...]"
fi
op=$1; shift
case "$op" in
copy|cp) copy "$@" ;;
sync|syn) sync ;;
*)
echo "Usage: $0 copy|sync file|dir [file|dir ...]"
exit 1
;;
esac