Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / mkpasswd
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         mkpasswd
5 # Description:  Create password file for cygwin
6 # Author:       Andrew@DeFaria.com
7 # Created:      Thu Oct  4 10:21:05  2001
8 # Language:     Bash Shell
9 # Modifications:
10 #
11 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
12 #
13 ################################################################################
14 # Set up PATH
15 PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
16
17 # Set me to command name
18 me=$(basename $0)
19
20 # Set commonarea
21 commonarea="//sonscentral/Corporate/Software"
22
23 # Set adm_base
24 adm_base=${adm_base:-$commonarea/adm}
25
26 # Set adm_fpath
27 adm_fpath=${adm_fpath:-$adm_base/functions}
28
29 # Source functions
30 . $adm_fpath/common
31
32 # Global variables
33 tmpfile="/tmp/$me"
34 master_passwd="$commonarea/etc/passwd"
35 master_group="$commonarea/etc/group"
36
37 function usage {
38   display "Usage: $me -[v|erbose] -[d|ebug] -[u|sage]"
39 } # usage
40
41 # Process options
42 while [ $# -ge 1 ]; do
43   case "$1" in
44     -usage)
45       usage
46     ;;
47
48     -v|-verbose)
49       verbose=yes
50     ;;
51
52     -d|-debug)
53       debug=yes
54     ;;
55   esac
56   shift
57 done
58
59 # First create passwd file
60 verbose "Creating master passwd file"
61 /bin/mkpasswd -d -o 0 > $tmpfile
62
63 # Now modify output
64 # Change home directories
65 verbose "Fixing US home directories"
66 sed 's/\/\/sonscentral/\/us/' $tmpfile > $tmpfile.2
67 mv $tmpfile.2 $tmpfile
68 verbose "Fixing China home directories"
69 sed 's/\/\/sons-shanghai/\/china/' $tmpfile > $tmpfile.2
70
71 # Remove unnecessary $'s
72 verbose "Removing extra $'s"
73 sed 's/\$//' $tmpfile.2 > $tmpfile
74
75 # Now determine the real users from the psuedo users. We determine this by
76 # verifying that there home directory exists.
77 verbose "Determining real users"
78
79 rm -f $tmpfile.2
80
81 IFS=:
82
83 sed 's/\\/\\\\/' $tmpfile | while read user pass uid gid geos home shell; do
84   # sonscenter is an old machine that no longer exists. It's now sonscentral.
85   if [[ $home = \/\/sonscenter* ]]; then
86     warning "Skipping user $user because $home does not exist"
87   elif [ -z "$home" ]; then
88     verbose "Puesdo user $user found (home directory is blank)"
89     echo "$user::$uid:$gid:$geos:$home:$shell" >> $tmpfile.2
90   elif [ -d "$home" ]; then
91     # Shell substitutions
92     if [ "$user" = "ftp" ]; then
93       verbose "Substituting /bin/false for ftp's shell"
94       shell="/bin/false"
95     fi
96     if [ "$user" = "gchharbra" ]; then
97       verbose "Substituting /bin/tcsh for $user's shell"
98     fi
99     echo "$user::$uid:$gid:$geos:$home:$shell" >> $tmpfile.2
100   else
101     warning "Skipping user $user because $home does not exist"
102   fi
103 done 
104
105 # Save last master password file
106 if [ -f $master_passwd ]; then
107   cp $master_passwd $master_passwd.save
108 fi
109
110 # Move in new master password file
111 mv $tmpfile.2 $master_passwd
112
113 # Save last master group file
114 if [ -f $master_group ]; then
115   cp $master_group $master_group.save
116 fi
117
118 # Make group file
119 verbose "Creating master group file"
120 /bin/mkgroup -d -o 0 > $master_group
121
122 # Cleanup files
123 rm $tmpfile