Imported Upstream version 1.2.16rel
[debian/mtx] / contrib / config_sgen_solaris.sh
1 #!/bin/sh
2 # Copyright 2001 Enhanced Software Technologies Inc.
3 # All Rights Reserved
4 #
5 # This software is licensed under the terms of the Free Software Foundation's
6 # General Public License, version 2. See http://www.fsf.org for more
7 # inforation on the General Public License. It is released for public use in
8 # the hope that others will find it useful. [NOTE FROM ERIC: Note that
9 # this is now unmaintained, unless someone wishes to volunteer. In other
10 # words, if you have a problem with this script, please fix it and forward
11 # a new version of the script with your EMAIL address as the one to contact
12 # about it :-) ]
13 #
14 # usage: config_sgen_solaris.sh check|[un]install
15 #
16 # This configures sgen under Solaris (we hope! :-). Note that this
17 # *CAN* do a reboot of the system. Do NOT call this function unless
18 # you are willing to let it do a reboot of the system! Also note that
19 # this *must* be run as user 'root', since it does highly grokety things.
20
21
22 mode="$1"
23 cvs upd
24 SGEN="/kernel/drv/sgen"
25 SGEN_CONF="/kernel/drv/sgen.conf"
26
27 do_check() {
28     if test ! -f $SGEN_CONF; then
29         # sgen.conf not installed...
30         return 1
31     fi
32
33     changer_type_count=`grep "changer" $SGEN_CONF | grep -v "^#" | wc -l`
34     target_count=`grep "target=" $SGEN_CONF | grep -v "^#" | wc -l`
35
36     if test $changer_type_count = 0 -o $target_count = 0; then
37         # sgen.conf not configured
38         return 1
39     fi
40
41     # sgen.conf installed, and configured
42     return 0
43 }
44
45 do_install() {
46
47     # see if already installed
48     do_check
49     if test $? = 0; then
50         echo "sgen already configured, skipping"
51         return 0 # successfully installed (?)
52     fi
53
54     if test ! -f $SGEN; then
55         echo "sgen driver not installed, aborting"
56         return 1
57     fi
58
59     echo "configuring sgen driver..."
60     
61     echo 'device-type-config-list="changer"; # BRU-PRO' >>$SGEN_CONF
62     target=0
63     while test $target -le 15; do
64         echo "name=\"sgen\" class=\"scsi\" target=$target lun=0; # BRU-PRO" >>$SGEN_CONF
65         target=`expr $target + 1`
66     done
67
68     echo "Attempting to reload driver..."
69     rem_drv sgen >/dev/null 2>&1
70     add_drv sgen
71     if test "$?" != "0"; then
72         # failed
73         touch /reconfigure
74         echo "Driver was successfully configured, but could not be re-loaded."
75         echo "The system must be rebooted for the driver changes to take effect."
76
77         ans=""
78         while test "$ans" = ""; do
79             printf "Do you want to reboot now (shutdown -g 1 -y -i 6)? [Y/n] "
80             read ans
81
82             if test "$ans" = "Y"; then
83                 ans="y"
84             fi
85
86             if test "$ans" = "N"; then
87                 ans="n"
88             fi
89
90             if test "$ans" != "y" -a "$ans" != "n"; then
91                 echo "Please enter 'y' or 'n'"
92                 ans=""
93             fi
94         done
95
96         if test "$ans" = "y"; then
97             shutdown -g 1 -y -i 6
98             # will be killed by reboot...
99             while true; do
100                 echo "Waiting for reboot..."
101                 sleep 300
102             done
103         fi
104
105         # not rebooted, exit with error
106         return 2
107     fi
108
109     # successful
110     return 0
111 }
112
113 do_uninstall() {
114     do_check
115     if test $? = 1; then
116         echo "sgen not configured, skipping"
117         return 0 # successfully uninstalled (?)
118     fi
119
120     printf "removing BRU-PRO configuration from $SGEN_CONF..."
121     grep -v "# BRU-PRO" $SGEN_CONF > ${SGEN_CONF}.$$ || return 1
122     cat ${SGEN_CONF}.$$ >${SGEN_CONF} || return 1
123     rm -f ${SGEN_CONF}.$$ >/dev/null  || return 1
124     printf "done\n"
125
126     touch /reconfigure
127     printf "Devices will be reconfigured at next reboot.\n"
128     return 0
129 }
130
131 uname | grep SunOS >/dev/null 2>&1
132 if test $? != 0; then
133     echo "$0: not on Solaris, ABORT!"
134     exit 99
135 fi
136
137 case "$mode" in
138     check)
139         do_check
140         ;;
141     install)
142         do_install
143         ;;
144     uninstall)
145         do_uninstall
146         ;;
147     *)
148         echo "usage: $0 check|[un]install"
149         exit 1
150         ;;
151 esac
152
153 exit $?