17c478bd9Sstevel@tonic-gate#!/bin/sh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*7d09b022Sbick# Common Development and Distribution License (the "License"). 7*7d09b022Sbick# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23*7d09b022Sbick# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 26*7d09b022Sbick# ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate# The -c and -u options are used by system configruation. 297c478bd9Sstevel@tonic-gateUSAGE="$0 [-c|-u]" 307c478bd9Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD" 317c478bd9Sstevel@tonic-gateexport TEXTDOMAIN 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate# As of Oct. 1, 1995, any new system shipped will have root 347c478bd9Sstevel@tonic-gate# property "energystar-v2" defined in its prom. 357c478bd9Sstevel@tonic-gateESTAR_PROP="energystar-v2" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate# Power Management configuration file 387c478bd9Sstevel@tonic-gatePWR_CONF=/etc/power.conf 397c478bd9Sstevel@tonic-gateSHUTDOWN_PATTERN="autoshutdown[ ]" 407c478bd9Sstevel@tonic-gateTMP=/var/run/tmp1.$$ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate# If this flag is present, user will be asked the autoshutdown 437c478bd9Sstevel@tonic-gate# question again even when autoshutdown is already configured. 447c478bd9Sstevel@tonic-gateASK_AGAIN_FLAG=/etc/.PM_RECONFIGURE 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate# This is provided for auto-install. 477c478bd9Sstevel@tonic-gate# If either of the files is present, autoshutdown will be configured 487c478bd9Sstevel@tonic-gate# accordingly silently. 497c478bd9Sstevel@tonic-gateSHUTDOWN_ENABLE_FLAG=/autoshutdown 507c478bd9Sstevel@tonic-gateSHUTDOWN_DISABLE_FLAG=/noautoshutdown 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate# Autoshutdown is not supported on diskless systems. 537c478bd9Sstevel@tonic-gateIS_DISKLESS="" 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate# Default autoshutdown setup. 567c478bd9Sstevel@tonic-gateDEFAULT_IDLE_TIME="30" 577c478bd9Sstevel@tonic-gateDEFAULT_START_TIME="9:00" 587c478bd9Sstevel@tonic-gateDEFAULT_FINISH_TIME="9:00" 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate# Currently autoshutdown setup in the configuration file. 617c478bd9Sstevel@tonic-gateCURRENT_IDLE_TIME="" 627c478bd9Sstevel@tonic-gateCURRENT_START_TIME="" 637c478bd9Sstevel@tonic-gateCURRENT_FINISH_TIME="" 647c478bd9Sstevel@tonic-gateCURRENT_BEHAVIOR="" 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate# Autoshutdown confirmation message to be prompted in the question1. 677c478bd9Sstevel@tonic-gate# In the following message, each escape sequence requires three 687c478bd9Sstevel@tonic-gate# backslashes to prevent the interpretation by the shell and gettext 697c478bd9Sstevel@tonic-gate# before being passed to ckyorn. In the message catalog, each message 707c478bd9Sstevel@tonic-gate# will have two backslashes. 717c478bd9Sstevel@tonic-gateMSG1=`gettext '\\\tAfter 30 minutes of idle time on this system, your system \ 727c478bd9Sstevel@tonic-gatestate\\\n\\\twill automatically be saved to disk, and the system will \ 737c478bd9Sstevel@tonic-gatepower-off.\\\n\\\n\\\tLater, when you want to use the system again, and \ 747c478bd9Sstevel@tonic-gateyou turn the power\\\n\\\tback on, your system will be restored to its \ 757c478bd9Sstevel@tonic-gateprevious state,\\\n\\\tincluding all the programs that you were running.\ 767c478bd9Sstevel@tonic-gate\\\n\\\n\\\tDo you want this automatic power-saving shutdown?\\\n\ 777c478bd9Sstevel@tonic-gate\\\t(If this system is used as a server, answer n)'` 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate# Message to be prompted in question2. 807c478bd9Sstevel@tonic-gate# In the following message, each escape sequence requires three 817c478bd9Sstevel@tonic-gate# backslashes to prevent the interpretation by the shell and gettext 827c478bd9Sstevel@tonic-gate# before being passed to ckyorn. In the message catalog, each message 837c478bd9Sstevel@tonic-gate# will have two backslashes. 847c478bd9Sstevel@tonic-gateMSG2=`gettext '\\\tDo you want the system to ask about this again, when \ 857c478bd9Sstevel@tonic-gateyou next reboot?\\\n\\\t(This gives you the chance to try it before deciding \ 867c478bd9Sstevel@tonic-gatewhether\\\n\\\tto keep it.)'` 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate# The autoshutdown comment to be put into the power management config file. 897c478bd9Sstevel@tonic-gateSHUTDOWN_COMMENT="# Auto-Shutdown\t\tIdle(min)\tStart/Finish(hh:mm)\tBehavior" 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate# Set up path. 927c478bd9Sstevel@tonic-gatePATH="/usr/bin:/usr/sbin:${PATH}" 937c478bd9Sstevel@tonic-gateexport PATH 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate# 967c478bd9Sstevel@tonic-gate# Get current autoshutdown setup. 977c478bd9Sstevel@tonic-gate# 987c478bd9Sstevel@tonic-gateget_behavior() { 997c478bd9Sstevel@tonic-gate grep -s "$SHUTDOWN_PATTERN" $PWR_CONF > /dev/null 1007c478bd9Sstevel@tonic-gate if [ $? = 0 ]; then 1017c478bd9Sstevel@tonic-gate set - `grep "$SHUTDOWN_PATTERN" $PWR_CONF` 1027c478bd9Sstevel@tonic-gate CURRENT_IDLE_TIME=$2 1037c478bd9Sstevel@tonic-gate CURRENT_START_TIME=$3 1047c478bd9Sstevel@tonic-gate CURRENT_FINISH_TIME=$4 1057c478bd9Sstevel@tonic-gate CURRENT_BEHAVIOR=$5 1067c478bd9Sstevel@tonic-gate fi 1077c478bd9Sstevel@tonic-gate} 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate# 1107c478bd9Sstevel@tonic-gate# Set the autoshutdown behavior in the configuration file. 1117c478bd9Sstevel@tonic-gate# The autoshutdown token can be preceded by spaces. 1127c478bd9Sstevel@tonic-gate# The resulting configuration will be based on the first autoshutdown 1137c478bd9Sstevel@tonic-gate# line if there is more than one in the configuration file. 1147c478bd9Sstevel@tonic-gate# 1157c478bd9Sstevel@tonic-gateset_behavior() { 1167c478bd9Sstevel@tonic-gate BEHAVIOR="$1" 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate grep -s "$SHUTDOWN_PATTERN" $PWR_CONF > /dev/null 1197c478bd9Sstevel@tonic-gate if [ $? = 0 ]; then 1207c478bd9Sstevel@tonic-gate set - `grep "$SHUTDOWN_PATTERN" $PWR_CONF` 1217c478bd9Sstevel@tonic-gate CURRENT_IDLE_TIME=$2 1227c478bd9Sstevel@tonic-gate CURRENT_START_TIME=$3 1237c478bd9Sstevel@tonic-gate CURRENT_FINISH_TIME=$4 1247c478bd9Sstevel@tonic-gate CURRENT_BEHAVIOR=$5 1257c478bd9Sstevel@tonic-gate fi 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate if [ "$BEHAVIOR" = "unconfigured" ]; then 1287c478bd9Sstevel@tonic-gate IDLE=$DEFAULT_IDLE_TIME 1297c478bd9Sstevel@tonic-gate START=$DEFAULT_START_TIME 1307c478bd9Sstevel@tonic-gate FINISH=$DEFAULT_FINISH_TIME 1317c478bd9Sstevel@tonic-gate else { 1327c478bd9Sstevel@tonic-gate if [ "$CURRENT_IDLE_TIME" = "" ]; then 1337c478bd9Sstevel@tonic-gate IDLE="$DEFAULT_IDLE_TIME" 1347c478bd9Sstevel@tonic-gate else 1357c478bd9Sstevel@tonic-gate IDLE="$CURRENT_IDLE_TIME" 1367c478bd9Sstevel@tonic-gate fi 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate if [ "$CURRENT_START_TIME" = "" ]; then 1397c478bd9Sstevel@tonic-gate START="$DEFAULT_START_TIME" 1407c478bd9Sstevel@tonic-gate else 1417c478bd9Sstevel@tonic-gate START="$CURRENT_START_TIME" 1427c478bd9Sstevel@tonic-gate fi 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate if [ "$CURRENT_FINISH_TIME" = "" ]; then 1457c478bd9Sstevel@tonic-gate FINISH="$DEFAULT_FINISH_TIME" 1467c478bd9Sstevel@tonic-gate else 1477c478bd9Sstevel@tonic-gate FINISH="$CURRENT_FINISH_TIME" 1487c478bd9Sstevel@tonic-gate fi 1497c478bd9Sstevel@tonic-gate } fi 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate grep -v "# Auto-Shutdown[ ]" $PWR_CONF | grep -v "$SHUTDOWN_PATTERN" > $TMP 1527c478bd9Sstevel@tonic-gate echo $SHUTDOWN_COMMENT >> $TMP 1537c478bd9Sstevel@tonic-gate echo "autoshutdown\t\t${IDLE}\t\t${START} ${FINISH}\t\t${BEHAVIOR}" >> \ 1547c478bd9Sstevel@tonic-gate $TMP 1557c478bd9Sstevel@tonic-gate cp $TMP $PWR_CONF 1567c478bd9Sstevel@tonic-gate rm $TMP 1577c478bd9Sstevel@tonic-gate} 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate# 1607c478bd9Sstevel@tonic-gate# Print out the Energystar guidelines. 1617c478bd9Sstevel@tonic-gate# 1627c478bd9Sstevel@tonic-gateprint_estar_guidelines() { 1637c478bd9Sstevel@tonic-gate echo 1647c478bd9Sstevel@tonic-gate echo "`gettext '\t================================================================'`" 1657c478bd9Sstevel@tonic-gate echo "`gettext '\tThis system is configured to conserve energy.'`" 1667c478bd9Sstevel@tonic-gate echo "`gettext '\t================================================================'`" 1677c478bd9Sstevel@tonic-gate} 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate# 1707c478bd9Sstevel@tonic-gate# Ask user for autoshutdown confirmation. 1717c478bd9Sstevel@tonic-gate# 1727c478bd9Sstevel@tonic-gatequestion1() { 1737c478bd9Sstevel@tonic-gate ans=`ckyorn -Q -d y -p "$1"` 1747c478bd9Sstevel@tonic-gate case $ans in 1757c478bd9Sstevel@tonic-gate y|yes|Y|Yes|YES) 1767c478bd9Sstevel@tonic-gate set_behavior shutdown 1777c478bd9Sstevel@tonic-gate echo 1787c478bd9Sstevel@tonic-gate echo "`gettext '\tAutoshutdown remains enabled.'`" 1797c478bd9Sstevel@tonic-gate break 1807c478bd9Sstevel@tonic-gate ;; 1817c478bd9Sstevel@tonic-gate n|no|N|No|NO) 1827c478bd9Sstevel@tonic-gate set_behavior noshutdown 1837c478bd9Sstevel@tonic-gate echo 1847c478bd9Sstevel@tonic-gate echo "`gettext '\tAutoshutdown has been disabled.'`" 1857c478bd9Sstevel@tonic-gate break 1867c478bd9Sstevel@tonic-gate ;; 1877c478bd9Sstevel@tonic-gate esac 1887c478bd9Sstevel@tonic-gate} 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate# 1917c478bd9Sstevel@tonic-gate# Ask user whether they want to be asked about the question again during 1927c478bd9Sstevel@tonic-gate# next reboot. 1937c478bd9Sstevel@tonic-gate# 1947c478bd9Sstevel@tonic-gatequestion2() { 1957c478bd9Sstevel@tonic-gate ans=`ckyorn -Q -d n -p "$1"` 1967c478bd9Sstevel@tonic-gate case $ans in 1977c478bd9Sstevel@tonic-gate y|yes|Y|Yes|YES) 1987c478bd9Sstevel@tonic-gate touch $ASK_AGAIN_FLAG 1997c478bd9Sstevel@tonic-gate echo "`gettext '\n\tThe system will ask you about automatic shutdown at the next reboot.'`" 2007c478bd9Sstevel@tonic-gate break 2017c478bd9Sstevel@tonic-gate ;; 2027c478bd9Sstevel@tonic-gate n|no|N|No|NO) 2037c478bd9Sstevel@tonic-gate rm -f $ASK_AGAIN_FLAG 2047c478bd9Sstevel@tonic-gate echo "`gettext '\n\tThe system will not ask you again about automatic shutdown.'`" 2057c478bd9Sstevel@tonic-gate break 2067c478bd9Sstevel@tonic-gate ;; 2077c478bd9Sstevel@tonic-gate esac 2087c478bd9Sstevel@tonic-gate} 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate################ 2127c478bd9Sstevel@tonic-gate# Main # 2137c478bd9Sstevel@tonic-gate################ 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate# 2167c478bd9Sstevel@tonic-gate# Exit if /etc/power.conf does not exist or is not writable. 2177c478bd9Sstevel@tonic-gate# 2187c478bd9Sstevel@tonic-gateif [ ! -f $PWR_CONF -o ! -w $PWR_CONF ]; then 2197c478bd9Sstevel@tonic-gate exit 1 2207c478bd9Sstevel@tonic-gatefi 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate# 2247c478bd9Sstevel@tonic-gate# Usage: sysidpm [-c|-u] 2257c478bd9Sstevel@tonic-gate# 2267c478bd9Sstevel@tonic-gateif [ $# -gt 1 ]; then 2277c478bd9Sstevel@tonic-gate echo $USAGE 2287c478bd9Sstevel@tonic-gate exit 1 2297c478bd9Sstevel@tonic-gatefi 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate# 2337c478bd9Sstevel@tonic-gate# The postinstall script of some power management package should have 2347c478bd9Sstevel@tonic-gate# added this command into the application list in /etc/.sysidconfig.apps. 2357c478bd9Sstevel@tonic-gate# System configuration and unconfiguration will call those applications 2367c478bd9Sstevel@tonic-gate# with option -c and -u respectively. 2377c478bd9Sstevel@tonic-gate# 2387c478bd9Sstevel@tonic-gateif [ $# -eq 1 ]; then 2397c478bd9Sstevel@tonic-gate case $1 in 2407c478bd9Sstevel@tonic-gate -c) # Does not need to do anything. 2417c478bd9Sstevel@tonic-gate exit 0 ;; 2427c478bd9Sstevel@tonic-gate -u) 2437c478bd9Sstevel@tonic-gate # Reset the behavior back to unconfigured state. 2447c478bd9Sstevel@tonic-gate set_behavior unconfigured 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate # Remove the statefile line too. 2477c478bd9Sstevel@tonic-gate grep -v statefile $PWR_CONF > $TMP 2487c478bd9Sstevel@tonic-gate cp $TMP $PWR_CONF 2497c478bd9Sstevel@tonic-gate rm $TMP 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate exit 0 ;; 2527c478bd9Sstevel@tonic-gate *) 2537c478bd9Sstevel@tonic-gate echo $USAGE 2547c478bd9Sstevel@tonic-gate exit 1 ;; 2557c478bd9Sstevel@tonic-gate esac 2567c478bd9Sstevel@tonic-gatefi 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate# 2607c478bd9Sstevel@tonic-gate# Get current autoshutdown setup. 2617c478bd9Sstevel@tonic-gate# 2627c478bd9Sstevel@tonic-gateget_behavior 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate# 2657c478bd9Sstevel@tonic-gate# If this is a diskless system, silently disable autoshutdown and exit. 2667c478bd9Sstevel@tonic-gate# 2677c478bd9Sstevel@tonic-gateROOT_FSTYPE=`df -n / | (read w1 w2 w3; echo $w3)` 2687c478bd9Sstevel@tonic-gateif [ $ROOT_FSTYPE != "ufs" ]; then 2697c478bd9Sstevel@tonic-gate set_behavior noshutdown 2707c478bd9Sstevel@tonic-gate exit 0 2717c478bd9Sstevel@tonic-gatefi 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate# 2757c478bd9Sstevel@tonic-gate# If /autoshutdown is present, silently enable autoshutdown and exit. 2767c478bd9Sstevel@tonic-gate# 2777c478bd9Sstevel@tonic-gateif [ -f $SHUTDOWN_ENABLE_FLAG ]; then 2787c478bd9Sstevel@tonic-gate set_behavior shutdown 2797c478bd9Sstevel@tonic-gate rm $SHUTDOWN_ENABLE_FLAG 2807c478bd9Sstevel@tonic-gate exit 0 2817c478bd9Sstevel@tonic-gatefi 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate# 2847c478bd9Sstevel@tonic-gate# If /noautoshutdown is present, silently disable autoshutdown and 2857c478bd9Sstevel@tonic-gate# exit. 2867c478bd9Sstevel@tonic-gate# 2877c478bd9Sstevel@tonic-gateif [ -f $SHUTDOWN_DISABLE_FLAG ]; then 2887c478bd9Sstevel@tonic-gate set_behavior noshutdown 2897c478bd9Sstevel@tonic-gate rm $SHUTDOWN_DISABLE_FLAG 2907c478bd9Sstevel@tonic-gate exit 0 2917c478bd9Sstevel@tonic-gatefi 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate# 2957c478bd9Sstevel@tonic-gate# If this is an EnergyStar compliant system, the default should 2967c478bd9Sstevel@tonic-gate# have autoshutdown enabled. However we don't want to surprise 2977c478bd9Sstevel@tonic-gate# users, so let's confirm with the user. 2987c478bd9Sstevel@tonic-gate# 2997c478bd9Sstevel@tonic-gateprtconf -vp | grep -s -w ${ESTAR_PROP} > /dev/null 3007c478bd9Sstevel@tonic-gateif [ $? = 0 ]; then 3017c478bd9Sstevel@tonic-gate if [ "$CURRENT_BEHAVIOR" = "unconfigured" -o -f $ASK_AGAIN_FLAG ]; then 3027c478bd9Sstevel@tonic-gate print_estar_guidelines 3037c478bd9Sstevel@tonic-gate question1 "$MSG1" 3047c478bd9Sstevel@tonic-gate question2 "$MSG2" 305*7d09b022Sbick # Currently, we do not have documentation for changing and 306*7d09b022Sbick # setting workstation energy-saving features. When we do, 307*7d09b022Sbick # gettext messages should be emitting here. see CR6520924 308*7d09b022Sbick # 3097c478bd9Sstevel@tonic-gate echo 3107c478bd9Sstevel@tonic-gate fi 3117c478bd9Sstevel@tonic-gate exit 0 3127c478bd9Sstevel@tonic-gatefi 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate# 3157c478bd9Sstevel@tonic-gate# The rest of the cases will have 'default' autoshutdown behavior. 3167c478bd9Sstevel@tonic-gate# 3177c478bd9Sstevel@tonic-gateif [ "$CURRENT_BEHAVIOR" = "unconfigured" ]; then 3187c478bd9Sstevel@tonic-gate set_behavior default 3197c478bd9Sstevel@tonic-gate exit 0 3207c478bd9Sstevel@tonic-gatefi 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate# 3237c478bd9Sstevel@tonic-gate# We are here because either the autoshutdown line has been 3247c478bd9Sstevel@tonic-gate# removed or the behavior has been configured. It can be a result 3257c478bd9Sstevel@tonic-gate# of upgrade. In that case, the configuration file should not 3267c478bd9Sstevel@tonic-gate# be changed. Let's exit. 3277c478bd9Sstevel@tonic-gateexit 0 328