Added client work scripts
[clearscm.git] / clients / HP / bin / update_machine_info
1 #!/bin/ksh
2 ################################################################################
3 #
4 # File:         update_machine_info
5 # Description:  Updates machine infor file (/vob/admin/machines)
6 # Author:       Andrew@DeFaria.com
7 # Created:      Fri Apr 30 14:13:56 PDT 1999
8 # Language:     Korn Shell
9 #
10 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
11 #
12 ################################################################################
13 # Set me to command name
14 me=$(basename $0)
15
16 # Set adm_base
17 adm_base=${adm_base:-$HOME/adm}
18
19 # Set adm_fpath
20 adm_fpath=${adm_fpath:-$adm_base/functions}
21
22 # Source functions
23 . $adm_fpath/common
24
25 # Set machines
26 machines=${machines:-$adm_base/data/machines}
27
28 tmp_file=/tmp/machines.$$
29 machine=$(uname -n)
30 ip=$(getip $machine)
31 mod=$(uname -m)
32 osversion=$(uname -r)
33
34 verbose=false
35
36 while getopts v OPT; do
37   case $OPT in
38     v) verbose=true
39     ;;
40   esac
41 done
42
43 if [ -x /usr/atria/bin/cleartool ]; then
44   ccversion=$(/usr/atria/bin/cleartool -version | grep "ClearCase version" |
45 \
46     cut -f3 -d' ')
47   eclipseid=`ls -ld /usr/eclipse/etc 2> /dev/null | awk -F'> ' '{print $2}'
48 \
49     | awk -F/ '{print $3}'`
50   [ $? -ne 0 ] && eclipseid="No Eclipse" || eclipseid=${eclipseid#eclipse}
51 else
52   ccversion="Non ClearCase Machine"
53   eclipseid="No Eclipse"
54 fi
55
56 owner=Unknown
57 usage=Unknown
58 location=Unknown
59 phone=Unknown
60 class=Unknown
61
62 # Unix doesn't really have a way to store such information such as owner,
63 # usage and location. Attempt to ascertain this info from /etc/motd.
64 if [ -f /etc/motd ]; then
65   usage=$(grep "^Usage:" /etc/motd | tr -s " " | cut -f2- -d" ")
66   owner=$(grep "^Owner:" /etc/motd | tr -s " " | cut -f2- -d" ")
67   phone=$(grep "^Phone:  " /etc/motd | tr -s " " | cut -f2- -d" ")
68   class=$(grep "^Class:" /etc/motd | tr -s " " | cut -f2- -d" ")
69   location=$(grep "^Location:" /etc/motd | tr -s " " | cut -f2- -d" ")
70 fi
71
72 rm -f $tmp_file
73
74 if [ $verbose = "true" ]; then
75   print "Machine: $machine"
76   print "IP Address: $ip"
77   print "Model: $mod"
78   print "OS Version: $osversion"
79   print "ClearCase Version: $ccversion"
80   print "Owner: $owner"
81   print "Phone: $phone"
82   print "Usage: $usage"
83   print "Class: $class"
84   print "Location: $location\n"
85   print "Eclipse ID: $eclispeid\n"
86   print "Updating machine list...\c"
87 fi
88
89 # Add machine if not already present
90 grep "^$machine" $machines > /dev/null 2>&1
91
92 if [ $? -ne 0 ]; then
93   print "$machine" >> $machines
94 fi
95
96 while read line; do
97   if [ "$(print $line | cut -f1 -d:)" = $machine ]; then
98     print
99 "$machine:$ip:$mod:$osversion:$ccversion:$owner:$phone:$usage:$class:$location:$eclipseid"
100 >> $tmp_file
101   else
102     print $line >> $tmp_file
103   fi
104 done < $machines
105
106 mv $tmp_file $machines
107
108 if [ $verbose = "true" ]; then
109   print "done"
110 fi