Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / config_disk_array
1 #!/usr/bin/ksh
2 ################################################################################
3 #
4 # File:         config_disk_array
5 # RCS:          $Header: config_disk_array,v 1.2 97/04/21 13:27:19 defaria Exp $
6 # Description:  A script to configure a NIKE Model 20 Disk Array
7 # Author:       Andrew DeFaria, California Language Labs
8 # Created:      Tue Jan 28 15:59:11 PST 1997
9 # Modified:
10 # Language:     Korn Shell
11 #
12 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
13 #
14 ################################################################################
15 me=$(basename $0)
16
17 if [ $(id -u) -ne 0 ]; then
18   print -u2 "$me: Error: Must be root to execute this command!"
19   exit 1
20 fi
21
22 # Get parametes
23 primary_disk=
24 mirror_disk=
25 while [ $# -ge 1 ]; do
26   case "$1" in
27     -p)
28       if [ $# -le 1 ]; then
29         print -u2 "$me: Error: Primary disk not specified"
30       fi
31       shift
32       primary_disk="$1"
33       ;;
34
35     -m)
36       if [ $# -le 1 ]; then
37         print -u2 "$me: Error: Mirror disk not specified"
38       fi
39       shift
40       mirror_disk="$1"
41       ;;
42
43     -d|-debug)
44       debug=yes
45       ;;
46
47     *)
48       print -u2 "$me: Error: Unknown parameter found ($1)"
49       exit 1
50       ;;
51   esac
52   shift
53 done
54
55 print "This script will configure the NIKE Model 20 Disk Array"
56
57 if [ "_$primary_disk" != "_" ]; then
58   print "The primary disk is at:        /dev/dsk/$primary_disk"
59 fi
60
61 if [ "_$mirror_disk" != "_" ]; then
62   print "The mirror disk is at: /dev/dsk/$mirror_disk"
63 fi
64
65 print
66
67 if [ "_$primary_disk" = "_" -a "_$mirror_disk" = "_" ]; then
68   print -u2 "Nothing to do!"
69   exit 1
70 fi
71
72 answer=y
73 print "Are these settings correct (Y/n)?\c"
74 read answer
75
76 if [ "$answer" != "y" -a "$answer" != "Y" ]; then
77   print -u2 "Nothing done"
78   exit 1
79 fi
80
81 # First create the mirror disk
82 if [ "_$mirror_disk" != "_" ]; then
83   print "Creating the mirror disk"
84   /sbin/pvcreate -f /dev/rdsk/$mirror_disk
85   status=$?
86
87   if [ $status -eq 0 ]; then
88     print "Mirror disk created"
89   else
90     print "Unable to create mirror disk (Status: $status)"
91     exit 1
92   fi
93 fi
94
95 # Create Physical Volume Groups
96 if [ "_$primary_disk" != "_" ]; then
97   print "Creating Physical Volume Groups"
98   /sbin/vgextend -g primary /dev/vgvobs /dev/dsk/$primary_disk
99   status=$?
100
101   # Ignore the warning about the volume already being created (Status: 2)
102   if [ $status -eq 0 -o $status -eq 2 ]; then
103     print "Physical Volume Group \"primary\" created"
104   else
105     print "Unable to create Physical Volume Group \"primary\" (Status: $status)"
106     exit 1
107   fi
108 fi
109
110 if [ "_$mirror_disk" != "_" ]; then
111   /sbin/vgextend -g mirror /dev/vgvobs /dev/dsk/$mirror_disk
112   status=$?
113
114   if [ $status -eq 0 ]; then
115     print "Physical Volume Group \"mirror\" created"
116   else
117     print "Unable to create Physical Volume Group \"mirror\" (Status: $status)"
118     exit 1
119   fi
120 fi
121
122 if [ "_$primary_disk" = "_" ]; then
123   exit
124 fi
125
126 # Create CLO logical volume
127 print "Creating CLO Logical Volume"
128
129 if [ "_$mirror_disk" = "_" ]; then
130   /sbin/lvcreate -l 3004 -n CLO -r y -C n -s y -p w -d p vgvobs
131 else
132   /sbin/lvcreate -l 3004 -n CLO -m 1 -r y -C n -M y -s g -p w -d p vgvobs
133 fi
134
135 status=$?
136
137 if [ $status -eq 0 ]; then
138   print "CLO Logical Volume created"
139 else
140   print "Unable to create CLO Logical Volume (Status: $status)"
141   exit 1
142 fi
143
144 # Create the file system
145 print "Creating file system on CLO Logical Volume"
146 /usr/sbin/newfs -F hfs -L -i 6144 -m 5 /dev/vgvobs/rCLO
147 status=$?
148
149 if [ $status -eq 0 ]; then
150   print "File system for CLO Logical Volume created"
151 else
152   print "Unable to create file system for CLO Logical Volume (Status: $status)"
153   exit 1
154 fi
155
156 # Mount the new CLO logical volume
157 print "Mounting CLO Logical Volume"
158 mkdir -p /CLO
159 /usr/sbin/mount -o rw,suid, -F hfs /dev/vgvobs/CLO /CLO
160 status=$?
161
162 if [ $status -eq 0 ]; then
163   print "CLO Logical Volume mounted"
164 else
165   print "Unable to mount CLO Logical Volume (Status: $status)"
166   exit 1
167 fi
168
169 # Add the /etc/fstab entry
170 print "/dev/vgvobs/CLO /CLO hfs rw,suid 0 2" >> /etc/fstab
171 print "Added CLO Logical Volume to /etc/fstab"
172
173 # Add the /etc/exports entry
174 print "/CLO -async" >> /etc/exports
175 print "Added CLO Logical Volume to /etc/exports as -async"
176
177 # Export /CLO
178 print "Exporting CLO Logical Volume"
179 /usr/sbin/exportfs -a
180 status=$?
181
182 if [ $status -eq 0 ]; then
183   print "CLO Logical Volume exported"
184 else
185   print "Unable to export CLO Logical Volume (Status: $status)"
186   exit 1
187 fi
188
189 print "Done"