Added client work scripts
[clearscm.git] / clients / HP / cygwin_setup
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         cygwin_setup
5 # Description:  This script will perform additional setup to configure the
6 #               local machine into the cygwin enviornment for Salira
7 # Author:       Andrew@DeFaria.com
8 # Created:      Fri Oct  5 15:30:16  2001
9 # Modified:
10 # Language:     Bash Shell
11 #
12 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
13 #
14 ################################################################################
15 # Set me to command name
16 me=$(basename $0)
17
18 # Global variables
19 commonserver=sonscentral
20 commonarea=common
21 adm=//$commonserver/$commonarea/adm
22 homeserver=sonscentral
23 homeshare=users
24 ccserver=sons-clearcase
25 anonymous_ftp_server=sons-clearcase
26 viewshare=views
27 printerserver=sons-mrp
28 printers="\
29   LJ4050PCL6\
30   LJ45500-Color\
31   LJ8150\
32 "
33 defaultprinter=LJ8150
34
35 # Current machine's OS.
36 OS=$(uname -s | cut -f2 -d-)
37
38 # Current machine's hostname
39 hostname=$(echo $(hostname) | tr [:upper:] [:lower:])
40
41 # Setup standard mounts
42 #
43 # Home directory
44 echo "Step 1 of 10: Setting up /home mount point"
45 mount -tsf //$homeserver/$homeshare /home
46
47 # Clearcase views
48 echo "Step 2 of 10: Setting up /view mount point"
49 if [ $hostname = $ccserver ]; then
50   mount -tsf C:/ClearCaseStorage/Views /view
51 else
52   mount -tsf //$ccserver/$viewshare /view
53 fi
54
55 # Set cygdrive prefix to /dev
56 echo "Step 3 of 10: Setting cygdrive-prefix to /dev"
57 mount -s --change-cygdrive-prefix /dev
58
59 # Remove user level cygdrive-prefix (Need to do this with regedit
60 regedit /s \\\\$commonserver\\$commonarea\\FixCygwin.reg 
61
62 # Link passwd file
63 echo "Step 4 of 10: Create common password file"
64 if [ ! -f /etc/passwd.local ]; then
65   if [ ! -L /etc/passwd ]; then
66     cp /etc/passwd /etc/passwd.local
67   fi
68 fi
69
70 if [ ! -L /etc/passwd ]; then
71   if [ "$OS" != "4.0" ]; then
72     rm /etc/passwd
73     ln -s //$commonserver/$commonarea/passwd /etc/passwd
74   else
75     cp //$commonserver/$commonarea/passwd /etc/passwd
76   fi
77 else
78   if [ "$OS" = "4.0" ]; then
79     # Fix up NT 4.0 machines (they don't like symlinked /etc/passwd files!)
80     rm /etc/passwd
81     cp //$commonserver/$commonarea/passwd /etc/passwd
82   fi
83 fi
84
85 # Link group file
86 echo "Step 5 of 10: Create common group file"
87 if [ ! -f /etc/group.local ]; then
88   if [ ! -L /etc/group ]; then
89     cp /etc/group /etc/group.local
90   fi
91 fi
92
93 if [ ! -L /etc/group ]; then
94   rm /etc/group
95   ln -s //$commonserver/$commonarea/group /etc/group
96 fi
97
98 # Link /etc/profile
99 echo "Step 6 of 10: Linking /etc/profile to common profile file"
100 if [ ! -f /etc/profile.orig ]; then
101   if [ ! -L /etc/profile ]; then
102     cp /etc/profile /etc/profile.orig
103   fi
104 fi
105
106 if [ ! -L /etc/profile ]; then
107   rm /etc/profile
108   ln -s //$commonserver/$commonarea/profile /etc/profile
109 fi
110
111 # Setup printer mount
112 echo "Step 7 of 10: Setting up printers"
113 for printer in $printers; do
114   mount -bsf //$printerserver/$printer /dev/$printer
115 done
116
117 # Mount default printer
118 mount -bsf //$printerserver/$defaultprinter /dev/lp
119
120 # Install internet services
121 echo "Step 8 of 10: Installing internet services"
122
123 # First save any pre-existing /etc/motd
124 if [ -f /etc/motd ]; then
125   cp /etc/motd /etc/motd.$$
126 fi
127
128 rm -f /etc/ftpusers /etc/ftpwelcome /etc/inetd.conf /etc/motd /etc/shells
129 iu-config > /dev/null
130
131 # In order to allow anonymous ftp access we need to clear /etc/ftpusers.
132 # Do this only for the $anonymous_ftp_server for now
133 if [ $hostname = $anonymous_ftp_server ]; then
134   cat /dev/null > /etc/ftpusers
135 fi
136
137 # Now replace that saved /etc/motd if it existed, otherwise remove the boring
138 # /etc/motd that iu-config creates. First check to see if the user has a 
139 # personalized /etc/motd in /etc/motd.save
140 if [ -f /etc/motd.save ]; then
141   # User had a personalized motd so move it into place and remove any prior
142   # copies
143   mv /etc/motd.save /etc/motd
144   rm -f /etc/motd.$$
145 elif [ -f /etc/motd.$$ ]; then
146   # Reinstall previous motd
147   # First update uname -a line
148   uname -a > /etc/motd
149
150   # Remove old uname -a line if present
151   grep -ve "^cygwin" /etc/motd.$$ >> /etc/motd.$$
152
153   # Cleanup
154   rm -f /etc/motd.$$
155 else
156   # No saved motd or previous motd. Remove /etc/motd which will cause us
157   # to prompt for the information later.
158   rm /etc/motd
159 fi
160
161 # Need to hardlink /usr/bin/cygwin1.dll & /usr/sbin/cygwin1.dll
162 # 12/17/2001: Stopped hardlinking cygwin1.dll. Enforcing having Windows system
163 # environment variables instead. For this we need Cygwin's bin in the path. 
164 # User should also set CYGWIN=ntsec in a Windows system environment variable.
165 if [ -f /usr/sbin/cygwin1.dll ]; then
166   rm -f /usr/sbin/cygwin1.dll
167   #ln /usr/bin/cygwin1.dll /usr/sbin/cygwin1.dll
168   echo "Warning: Please make sure that you have a Windows *SYSTEM* environment"
169   echo "         variable named CYGWIN set to the value of \"ntsec\" and that"
170   echo "         you have <Cygwin>\bin inserted into the Windows *SYSTEM*"
171   echo "         environment variable named PATH"
172 fi
173
174 # Set up anonymous ftp iff we are on the $anonymous_ftp_server
175 if [ $hostname = $anonymous_ftp_server ]; then
176   # Toggle on write access to ~ftp/bin
177   chmod +w ~ftp/bin
178
179   # Remove old copies of ls and cygwin1.dll
180   rm -f ~ftp/bin/ls.exe 
181   rm -f ~ftp/bin/cygwin1.dll
182
183   # Install new copies (Note hardlinks will not work here since ~ftp/bin is
184   # on another file system. Doing an ln simply does a copy anyway)
185   # 12/17/2001: Skipping copying of cygwin1.dll as noted above
186   cp /bin/cygwin1.dll ~ftp/bin/cygwin1.dll
187   cp /bin/ls.exe ~ftp/bin/ls.exe
188
189   # Set security
190   chmod 555 ~ftp/bin/cygwin1.dll
191   chmod 111 ~ftp/bin/ls.exe
192   chown Administrator ~ftp/bin/cygwin1.dll 
193   chown Administrator ~ftp/bin/ls.exe
194   chmod -w ~ftp/bin
195 fi
196
197 # Install inetd as a service
198 /usr/sbin/inetd --install-as-service
199
200 # Start inetd service
201 inetd_started=$(net start | grep -i inetd)
202
203 if [ -z "$inetd_started" ]; then
204   net start inetd
205 fi
206
207 # Setup SMTP
208 $adm/bin/setup_ssmtp
209
210 # Setup cron
211 $adm/bin/setup_cron
212
213 # Create /etc/motd
214 echo "Step 9 of 10: Gathering machine specific information"
215 if [ ! -f /etc/motd ]; then
216   $adm/bin/make_motd
217   made_motd=true
218 else
219   echo "Skipped: Machine info already gathered"
220 fi
221
222 # Fixup /etc/ftpwelcome
223 host=$(hostname | tr [:upper:] [:lower:])
224 echo "Welcome to $host's ftp service" > /etc/ftpwelcome
225
226 # Update machines file
227 echo "Step 10 of 10: Registering this machine (This takes a few seconds)"
228 if [ ! -z "$made_motd" ]; then
229   $adm/bin/update_machine_info
230 else
231   echo "Skipped: Machine already registered"
232 fi
233
234 # Sneaky other fixes...
235 # Link /bin/more.exe -> /bin/less.exe
236 if [ ! -L /bin/more.exe ]; then
237   ln -s /bin/less.exe /bin/more.exe
238 fi
239
240 # Finished
241 echo "Done"