Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / makehome
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         makehome
5 # Description:  Makes a users home directory
6 # Author:       Andrew@DeFaria.com
7 # Created:      Thu Jun  3 17:21:24 PDT 1999
8 # Modified:
9 # Language:     Korn Shell
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 # Set adm_base
18 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
19
20 # Set adm_fpath
21 adm_fpath=${adm_fpath:-$adm_base/functions}
22
23 # Source functions
24 . $adm_fpath/common
25
26 function usage {
27   display "$me: Usage: makehome [ -v|erbose ] [ -d|ebug ] -username
28 <username>
29 \t\t\t  -uid <uid>"
30
31   exit 1
32 } # usage
33
34 function prompt_for_field {
35   fieldname="$1"
36   fieldvalue=
37
38   while [ ! -n "$fieldvalue" ]; do
39     display "Enter the value for $fieldname:\c"
40     read fieldvalue
41
42     if [ ! -n "$fieldvalue" ]; then
43       error "Must specify $fieldname!"
44     fi
45   done
46 } # prompt_for_field
47
48 function show_parms {
49   display "$me"
50   display "-------------------------------------"
51   display "username  = $username"
52   display "uid       = $uid"
53   display "homedrive = $homedrive"
54   display "devdrive  = $devdrive"
55   display "homepath  = $homepath"
56   display "devpath   = $devpath"
57   display
58   display "Command line equivalent:"
59   display
60   display "$me -username $username -uid $uid"
61   display
62   display "Are the parameters correct [Y|n]?\c"
63   read answer
64   case "$answer" in
65     Y|y)
66       : OK!
67       ;;
68     *)
69       exit
70       ;;
71   esac
72 } # show_parms
73
74 if is_not_root; then
75   error "You must be root to use this command" 1
76 fi
77
78 case "$(hostname)" in
79   dreamcicle|fudgecicle)
80     ;;
81
82   *)
83     error "Must be running on either dreamcicle or fudgecicle to execute
84 this command" 2
85   ;;
86
87 esac
88
89 # Get options
90 debug=
91 verbose=
92
93 while [ $# -ge 1 ]; do
94   case "$1" in
95     -u|usage)
96       usage
97       ;;
98
99     -v|-verbose)
100       verbose=yes
101       ;;
102
103     -d|-debug)
104       debug=yes
105       ;;
106
107     -username)
108       if [ $# -le 1 ]; then
109         error "Username not specified!" 0
110         usage
111       fi
112       shift
113       username="$1"
114       ;;
115
116     -uid)
117       if [ $# -le 1 ]; then
118         error "UID not specified!" 0
119         usage
120       fi
121       shift
122       uid="$1"
123       ;;
124
125     *)
126       error "Unknown option \"$1\" encountered" 0
127       usage
128       ;;
129
130   esac
131   shift
132 done
133
134 if [ "$username" = "" ]; then
135   prompt_for_field "Username"
136   username=$fieldvalue
137 fi
138
139 if [ "$uid" = "" ]; then
140   prompt_for_field "UID"
141   uid=$fieldvalue
142 fi
143
144 homedrive=home1
145 devdrive=dev1
146 homepath=/netapp/dvd/$homedrive/$username
147 devpath=/netapp/dvd/$devdrive/$username
148
149 show_parms
150
151 mkdir -p $homepath
152 chown $uid:cdseng $homepath
153 chmod 775 $homepath
154 mkdir -p $devpath
155 chown $uid:cdseng $devpath
156 chmod 775 $devpath
157
158 if [ ! -h $homepath/dev ]; then
159   ln -s /auto/dev/$username $homepath/dev
160 fi