Added client work scripts
[clearscm.git] / clients / HP / bin / fix_automounts
1 #!/bin/ksh
2 ################################################################################
3 #
4 # File:         fix_automounts
5 # Description:  Remounts exported file systems from a machine
6 # Author:       Andrew DeFaria (defaria@cup.hp.com)
7 # Language:     Korn Shell
8 # Created:      Tue Apr 21 11:59:57 PDT 1998
9 # Status:       Experimental (Do Not Distribute)
10 # Modifications: Removed the grep "(everyone)". In the past file systems were
11 #               exported to everyone and that is no longer the case. This does
12 #               mean that this script might attempt to mount things it can't
13 #               but there is no easy way to ascertain if the current machine
14 #               is allowed to mount given showmount -e output, especially if
15 #               that output is a netgroup. I could check this via ypmatch
16 #               but that'll take yet more smarts...
17 #               Andrew@DeFaria.com
18 #
19 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
20 #
21 ################################################################################
22 # Set me to command name
23 me=$(basename $0)
24
25 # Set adm_base
26 adm_base=${adm_base:-$HOME/adm}
27
28 # Set adm_fpath
29 adm_fpath=${adm_fpath:-$adm_base/functions}
30
31 # Source functions
32 . $adm_fpath/common
33
34 if [ $(id -u) -ne 0 ]; then
35   print -u2 "$me: Error: You must be root to execute this command!"
36   exit 1
37 fi
38
39 if [[ "$OS" = "10" ]] ; then
40   mount=/usr/sbin/mount
41 else
42   mount=/etc/mount
43 fi
44
45 if [ $# -lt 1 ]; then
46   print -u2 "Usage: <remote machine> [ <remote machine> ]"
47   exit 1
48 fi
49
50 function remount_filesystem {
51   machine=$1
52   mount_directory=$2
53   mount_over_directory=/tmp_mnt/net/$machine$2
54   if [ ! -d $mount_over_directory ]; then
55     print Making $mount_over_directory
56     mkdir -p $mount_over_directory
57   fi
58
59   if [ ! -d $mount_over_directory/lost+found ]; then
60     print Mounting $machine:$mount_directory to $mount_over_directory
61     $mount $machine:$mount_directory $mount_over_directory
62     status=$?
63     if [ $status -ne 0 ]; then
64       print -u2 "Warning: Unable to mount $machine:$mount_directory
65 $mount_over_directory (Status: $?)"
66     fi
67   fi
68 } # remount_filesystem
69
70 function kick_automounter {
71   automount_pid=$(ps -ef | grep automount | grep -v "grep automount" | grep -v "fix_automounts" | awk '{print $2}')
72
73   print Kicking automounter \($automount_pid\)
74   kill -HUP $automount_pid
75 } # kick_automounter
76
77 if [ "$OS" = "10" ]; then
78   showmount=/usr/sbin/showmount
79 else
80   showmount=/usr/etc/showmount
81 fi
82
83 for remote in "$@"; do
84   exported_filesystems=$($showmount -e $remote | grep -v "export list" |
85     cut -f1 -d' ')
86   for filesystem in $exported_filesystems; do
87     remount_filesystem $remote $filesystem
88   done
89 done
90
91 kick_automounter