Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / bin / setup_rhosts
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         setup_rhosts
5 # Description:  Sets up a users ~/.rhosts file
6 # Author:       Andrew@DeFaria.com
7 # Created:      Fri Apr 30 14:13:56 PDT 1999
8 # Modifications:Thu Mar  7 11:25:36  2002: Adapted for Windows/Cygwin.
9 # Language:     Korn Shell
10 #
11 # (c) Copyright 2002, 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 # Check if root
34 if is_root; then
35   error "You should not run the script as root!" 1
36 fi
37
38 rhosts=$HOME/.rhosts
39 rhosts_loc=$HOME/.rhosts.loc
40
41 # Generate new $rhosts
42
43 if [ -f $rhosts_loc ]; then
44   cp $rhosts_loc $rhosts
45 else
46   rm -f $rhosts
47 fi
48
49 # Loop through all machines in the domain and add them to the .rhosts file:
50 for machine in $(net view | grep -e "\\\\" | cut -f3 -d\\ | cut -f1 -d' ' | tr [:upper:] [:lower:]); do
51   if [ ${#machine} -lt 8 ]; then
52      echo -e "$machine\t\t$USER" >> $rhosts
53   else
54     echo -e "$machine\t$USER" >> $rhosts
55   fi
56 done
57
58 # Insure proper permissions
59 chmod 644 $rhosts