improve bash completions and related delivery mechanism
[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. Please contact eric@estinc.com
9 # if you have problems. Also check out our backup products at
10 # http://www.estinc.com (grin). 
11 #
12 # usage: config_sgen_solaris.sh check|[un]install
13 #
14 # This configures sgen under Solaris (we hope! :-). Note that this
15 # *CAN* do a reboot of the system. Do NOT call this function unless
16 # you are willing to let it do a reboot of the system! Also note that
17 # this *must* be run as user 'root', since it does highly grokety things.
18
19
20 mode="$1"
21 cvs upd
22 SGEN="/kernel/drv/sgen"
23 SGEN_CONF="/kernel/drv/sgen.conf"
24
25 do_check() {
26     if test ! -f $SGEN_CONF; then
27         # sgen.conf not installed...
28         return 1
29     fi
30
31     changer_type_count=`grep "changer" $SGEN_CONF | grep -v "^#" | wc -l`
32     target_count=`grep "target=" $SGEN_CONF | grep -v "^#" | wc -l`
33
34     if test $changer_type_count = 0 -o $target_count = 0; then
35         # sgen.conf not configured
36         return 1
37     fi
38
39     # sgen.conf installed, and configured
40     return 0
41 }
42
43 do_install() {
44
45     # see if already installed
46     do_check
47     if test $? = 0; then
48         echo "sgen already configured, skipping"
49         return 0 # successfully installed (?)
50     fi
51
52     if test ! -f $SGEN; then
53         echo "sgen driver not installed, aborting"
54         return 1
55     fi
56
57     echo "configuring sgen driver..."
58     
59     echo 'device-type-config-list="changer"; # BRU-PRO' >>$SGEN_CONF
60     target=0
61     while test $target -le 15; do
62         echo "name=\"sgen\" class=\"scsi\" target=$target lun=0; # BRU-PRO" >>$SGEN_CONF
63         target=`expr $target + 1`
64     done
65
66     echo "Attempting to reload driver..."
67     rem_drv sgen >/dev/null 2>&1
68     add_drv sgen
69     if test "$?" != "0"; then
70         # failed
71         touch /reconfigure
72         echo "Driver was successfully configured, but could not be re-loaded."
73         echo "The system must be rebooted for the driver changes to take effect."
74
75         ans=""
76         while test "$ans" = ""; do
77             printf "Do you want to reboot now (shutdown -g 1 -y -i 6)? [Y/n] "
78             read ans
79
80             if test "$ans" = "Y"; then
81                 ans="y"
82             fi
83
84             if test "$ans" = "N"; then
85                 ans="n"
86             fi
87
88             if test "$ans" != "y" -a "$ans" != "n"; then
89                 echo "Please enter 'y' or 'n'"
90                 ans=""
91             fi
92         done
93
94         if test "$ans" = "y"; then
95             shutdown -g 1 -y -i 6
96             # will be killed by reboot...
97             while true; do
98                 echo "Waiting for reboot..."
99                 sleep 300
100             done
101         fi
102
103         # not rebooted, exit with error
104         return 2
105     fi
106
107     # successful
108     return 0
109 }
110
111 do_uninstall() {
112     do_check
113     if test $? = 1; then
114         echo "sgen not configured, skipping"
115         return 0 # successfully uninstalled (?)
116     fi
117
118     printf "removing BRU-PRO configuration from $SGEN_CONF..."
119     grep -v "# BRU-PRO" $SGEN_CONF > ${SGEN_CONF}.$$ || return 1
120     cat ${SGEN_CONF}.$$ >${SGEN_CONF} || return 1
121     rm -f ${SGEN_CONF}.$$ >/dev/null  || return 1
122     printf "done\n"
123
124     touch /reconfigure
125     printf "Devices will be reconfigured at next reboot.\n"
126     return 0
127 }
128
129 uname | grep SunOS >/dev/null 2>&1
130 if test $? != 0; then
131     echo "$0: not on Solaris, ABORT!"
132     exit 99
133 fi
134
135 case "$mode" in
136     check)
137         do_check
138         ;;
139     install)
140         do_install
141         ;;
142     uninstall)
143         do_uninstall
144         ;;
145     *)
146         echo "usage: $0 check|[un]install"
147         exit 1
148         ;;
149 esac
150
151 exit $?