treewide: replace /sbin/sh hashbangs with /bin/sh
[unleashed.git] / usr / src / cmd / power / svc-power
blob5632cd83e27af68a696f06ae6db3eec64f0eadec
1 #!/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
26 #ident "%Z%%M% %I% %E% SMI"
28 # If the /etc/power.conf file does not have a "statefile" entry
29 # to specify the pathname of the cpr statefile, build one and
30 # add the line. We choose the largest of the standard Sun partitions.
32 init_statefile_entry() {
33 [ ! -f /etc/power.conf -o ! -w /etc/power.conf ] && return
35 # Whitespace regular expression below is [<TAB><SPACE>]
37 pattern="^[ ]*statefile[ ][ ]*/"
38 [ `/usr/bin/grep -c "$pattern" /etc/power.conf` -ge 1 ] && return
40 avail=0 # Free blocks in current filesystem
41 max_avail=0 # Most available free blocks encountered so far
42 statefile=.CPR # Default cpr statefile name
44 # Remove old statefile (if any) from root
45 [ -f /$statefile ] && /usr/bin/rm -f /$statefile
47 /usr/bin/df -k -F ufs |
49 read line # Skip past the header line of the df output
51 while read device kbytes used avail capacity filesys; do
52 case $filesys in
53 /|/usr|/var|/export/home)
54 if [ $avail -gt $max_avail ]; then
55 max_avail=$avail
56 winner=$filesys
59 esac
60 done
62 if [ $max_avail -gt 0 ]; then
63 echo "statefile ${winner}/${statefile}" \
64 >>/etc/power.conf
67 return
69 if [ $max_avail -eq 0 ]; then
70 if [ X`df -n / | awk '{print $3}'` != "Xzfs" ] ; then
71 return
73 rootpool=`zfs mount | grep ' \/$' | awk '{print $1 }' |\
74 sed 's/\/.*$//'`
75 if [ X$rootpool = "X" ] || \
76 [ ! -L /dev/zvol/dsk/$rootpool/dump ]; then
77 return
79 echo "statefile /dev/zvol/dsk/$rootpool/dump" \
80 >> /etc/power.conf
84 case "$1" in
85 'start')
86 /usr/sbin/uadmin 3 2 2>/dev/null
87 if [ $? -eq 0 ]; then
88 init_statefile_entry
91 if [ -x /usr/sbin/pmconfig -a -r /etc/power.conf ]; then
92 /usr/sbin/pmconfig >/dev/console 2>&1
96 'stop')
97 if [ -x /usr/sbin/pmconfig ]; then
98 /usr/sbin/pmconfig -r >/dev/null 2>/dev/null
103 echo "Usage: $0 { start | stop }"
104 exit 1
106 esac
107 exit 0