From ca94a87e93f466e2abf583e901d6dfc346fea972 Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Tue, 17 Feb 2009 19:01:15 +0100 Subject: Initial commit --- tp_smapi.init | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 tp_smapi.init (limited to 'tp_smapi.init') diff --git a/tp_smapi.init b/tp_smapi.init new file mode 100644 index 0000000..d0fce10 --- /dev/null +++ b/tp_smapi.init @@ -0,0 +1,132 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/tp_smapi +# +# Load tp_smapi kernel driver and apply settings +# +# chkconfig: 345 10 90 +# description: Load tp_smapi kernel driver and apply settings +# processname: + +### BEGIN INIT INFO +# Provides: tp_smapi +# Required-Start: $syslog $local_fs +# Required-Stop: $syslog $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: load and set up tp_smapi +# Description: Load tp_smapi kernel driver and apply settings +### END INIT INFO + +# TODO: Make sure this script's startup runs after akmod's startup + +# Source function library. +. /etc/rc.d/init.d/functions + +RETVAL=0 +CONFIG=/etc/sysconfig/tp_smapi + +# Source function library. +. /etc/rc.d/init.d/functions + +load_modules() { + echo -n "Loading tp_smapi driver module" + if modprobe tp_smapi; then + success "Loading tp_smapi driver module" + else + failure "Loading tp_smapi driver module" + RETVAL=2 + fi + echo +} + +unload_modules() { + mdoules="tp_smapi thinkpad_ec" + echo -n "Unloading driver modules ${modules}" + if modprobe -r tp_smapi && modprobe -r thinkpad_ec; then + success "Unloading driver modules ${modules}" + else + failure "Unloading driver modules ${modules}" + RETVAL=2 + fi + echo +} + +smapi_config() { + if [ -s "$CONFIG" ]; then + . "$CONFIG" + dirty=false + cd /sys/devices/platform/smapi + echo -n "Configuring tp_smapi battery settings" + for bat in BAT*; do + if test -d "$bat"; then + if [ "x$START_CHARGE_THRESH" != x ]; then + echo "$START_CHARGE_THRESH" > "$bat/start_charge_thresh" + fi + if [ "x$STOP_CHARGE_THRESH" != x ]; then + echo "$STOP_CHARGE_THRESH" > "$bat/stop_charge_thresh" + fi + else + dirty=true + break + fi + done + if "$dirty"; then + passed "No tp_smapi battery settings" + else + success "Configured tp_smapi battery settings" + fi + echo + fi +} + +is_loaded() { + if /sbin/lsmod | grep '^tp_smapi ' > /dev/null; then + echo -n "tp_smapi settings:" + cd /sys/devices/platform/smapi + for bat in BAT*; do + if [ -d "$bat" ] && [ "$(<$bat/installed)" -eq 1 ]; then + echo -n " $bat($(<$bat/remaining_percent)%, $(<$bat/start_charge_thresh)%..$(<$bat/stop_charge_thresh)%)" + fi + done + echo + else + echo "tp_smapi driver is not loaded" + return 2 + fi +} + +case "$1" in +force-reload) + echo "$0: Unimplemented feature." + RETVAL=3 + ;; +start) + load_modules + smapi_config + ;; +reload|restart|force-reload) + unload_modules + load_modules + smapi_config + ;; +condrestart) + if is_loaded; then + unload_modules + load_modules + smapi_config + fi + ;; +stop) + unload_modules + ;; +status) + is_loaded + RETVAL=$? + ;; +*) + echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}" + RETVAL=2 +esac + +exit $RETVAL -- cgit