Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / bin / update_view
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         update_view
5 # Description:  Updates a snapshot view
6 # Author:       Andrew@DeFaria.com
7 # Created:      Thu Dec 13 19:11:15  2001
8 # Language:     Bash Shell
9 # Modifications:
10 #
11 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
12 #
13 ################################################################################
14 # Set me to command name
15 me=$(basename $0)
16
17 # Source /etc/site_parms
18 if [ -f /etc/site_parms ]; then
19   . /etc/site_parms
20 else
21   echo "$me: WARNING: /etc/site_parms does not exist!"
22 fi
23
24 # Set adm_base
25 adm_base="$SITE_TOOLS_PATH/adm"
26
27 # Set adm_fpath
28 adm_fpath=${adm_fpath:-$adm_base/functions}
29
30 # Source functions
31 . $adm_fpath/common
32
33 function usage {
34   if [ ! -z "$1" ]; then
35     error "$1\n"
36   fi
37   display "$me: [-q|uiet ] [-v|erbose] [-d|ebug] [-usage] <view_tag>"
38   display "\t     [ <view_tag>... ]"
39   display
40   display "Where:"
41   display "\t-quiet:\t\tBe quiet"
42   display "\t-verbose:\tTurn on verbose mode"
43   display "\t-debug:\t\tTurn on debug mode"
44   display "\t-usage:\t\tDisplay usage"
45   display "\t<viewtag>\tView tag(s) to update"
46   exit 1
47 } # usage
48
49 # Get parameters
50 quiet="no"
51 while [ $# -ge 1 ]; do                                                          
52   case "$1" in                                                                  
53       -u|-usage)
54         usage
55       ;;
56
57       -v|-verbose)
58         verbose=yes
59       ;;                                                                        
60
61       -d|-debug)
62         debug=yes
63       ;;                                                                        
64
65       -q|-quiet)
66         quiet="yes"
67       ;;
68
69       *)
70         views_tags_to_update="$views_tags_to_update $1"
71       ;;
72
73   esac
74   shift
75 done
76
77 for viewtag in $views_tags_to_update; do
78   # First check to see if there is a snapshot view
79   viewpath="$SITE_SNAPSHOT_VIEW_PATH/$viewtag"
80   if [ -d "$viewpath" ]; then
81     verbose "Updating view $viewtag..."
82     cd $viewpath
83
84     if [ $quiet = "yes" ]; then
85       # If quiet then the logfile is discarded as well as the output from
86       # cleartool update.
87       logfile=/dev/null
88       cleartool update -force -log $logfile . > /dev/null 2>&1
89     else
90       # If not quiet then we let cleartool update place the .updt file 
91       # normally (i.e. in the view root directory) and capture the output
92       # of cleartool update so we can extract that pathname later
93       logfile=/tmp/$viewtag.update.log
94       cleartool update -force . > $logfile 2>&1
95     fi
96
97     if [ $? -eq 0 ]; then
98       verbose "Successfully updated $viewtag"
99       if [ -f $logfile ]; then
100         # Note that [ -f /dev/null ] fails (i.e. there is no real /dev/null
101         # file) so we skip the following, which is what we want to do here.
102         update_logfile_name=$(tail -1 $logfile | cut -f2 -d'"' | tr '\\\\' '/')
103         rm -f $logfile
104         # Cheap email:
105         cat <<EOF
106 The view $viewtag was successfully updated. Check logfile for results. 
107
108 Logfile: $update_logfile_name
109
110 You can double click on a view update logfile from the Windows Explorer to 
111 view the results in Clearcase.
112
113 WARNING: Remember view update logfiles will accumulate unless you remove them! 
114 EOF
115       fi
116     else
117       warning "Update of $viewtag failed"
118       display "See $logfile for more information"
119     fi
120   else
121     warning "View tag does not exist for the snapshot view: $viewtag"
122   fi
123 done