-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync-vob
executable file
·87 lines (77 loc) · 1.9 KB
/
sync-vob
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
#!/bin/sh
usage()
{
cat >&2 <<__EOF__
Usage: $(basename $0) < save [ -d ] | fetch [ -v <view> ] | purge >
Commands:
save -- Stash modified files under ${HOME}/src/.
fetch -- Sync files from ${HOME}/src/<view> to /usr/src/.
purge -- Remove stashed files.
Options:
-d -- Only stash modified files under the current directory.
-v view -- Specify the view to fetch files from. An attempt to guess
will be made if the view isn't specified.
__EOF__
exit ${1-1}
}
log()
{
echo "$(basename $0): $1" 1>&2
}
if [ "$1" != save -a "$1" != fetch -a "$1" != purge ]; then
usage
fi
CMD=$1
shift
if [ $CMD = save -o $CMD = purge ]; then
CVIEW=$(cleartool pwv -short 2>/dev/null)
if [ -z "$CVIEW" -o "$CVIEW" = "** NONE **" ]; then
log "Error determining the current view."
exit 1
fi
else # $CMD is 'fetch'.
case $(uname -i 2>/dev/null) in
STOCK)
CVIEW=mjohnston_plt_svos_8_2
;;
SPB)
CVIEW=mjohnston_plt_mts_8_2
;;
*)
log "Couldn't determine view based on uname info."
exit 1
;;
esac
fi
SRCDIR=${HOME}/src/${CVIEW}
case $CMD in
save)
currdir=
if [ $# -gt 0 ]; then
if [ $1 = "-d" ]; then
currdir=$(pwd)
else
usage
fi
fi
for file in $(cleartool lsco -cview -avobs -short); do
expr "$file" : "${currdir}/" >/dev/null 2>&1 || continue
dstdir=$(echo ${SRCDIR}$(dirname "$file") | sed 's?vobs/[^/]*/??')
mkdir -p "$dstdir"
if [ -f "$file" ]; then
log "saving $file to $dstdir"
cp -f "$file" "$dstdir"
fi
done
;;
fetch)
cd $SRCDIR
for file in $(find . -type f); do
log "copying $file to /usr/$file."
cp -f $file /usr/$file
done
;;
purge)
find ${SRCDIR} -type f -exec rm -f {} \;
;;
esac