]> git.pld-linux.org Git - packages/hdparm.git/blobdiff - hdparm.init
- optimize for empty config doing nothing
[packages/hdparm.git] / hdparm.init
index a7e2fe2e8109b24aaf4c29b3241ecc1cf4ed6aa2..1ceb4b66d8368678a681e3fabc084d81a58cb30a 100644 (file)
@@ -1,48 +1,29 @@
 #!/bin/sh
-#
-# hdpram        Sets up some hard drive parameters
-#
-#
-# chkconfig: 2345 5 95
-# description: hdparm is utility which can help tuning your hard drive\
-# parameters
 
-# Source function library.
-. /etc/rc.d/init.d/functions
-
-[ -x /sbin/hdparm ] || exit 0
 [ -f /etc/sysconfig/hdparm ] || exit 0
 
+blockdevs=$(awk -F= '!/^#/ && !/^$/ {if ($2) print $1}' /etc/sysconfig/hdparm)
+if [ -z "$blockdevs" ]; then
+       exit 0
+fi
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Source hdparm configureation.
 . /etc/sysconfig/hdparm
 
-# See how we were called.
-case "$1" in
-  start)
-       cd /dev
-       DRIVES=`cut -c 22- < /proc/partitions | egrep -v -e"md|name"`
-       for drive in $DRIVES ; do
-         eval PARAMS=\${HDPARM_${drive}}
-         if [ -n "${PARAMS}" ] ; then
-           show "Setting $drive parameters"
-           busy
-           /sbin/hdparm ${PARAMS} $drive
-           deltext
-           ok
-         fi
-       done  
-       touch /var/lock/subsys/hdparm
-       ;;
-    stop)      
-       rm -f /var/lock/subsys/hdparm
-       ;;
-  status)
-       for drive in /dev/hd? ; do
-         hdparm $drive
-       done
-       ;;
-  *)
-       echo "Usage: $0 {start|stop|status}"
-       exit 1
-esac
+for var in $blockdevs; do
+       drive=${var#HDPARM_}
+       if [ -L "/proc/ide/${drive}" ]; then
+               eval PARAMS=\$$var
+               if [ -n "${PARAMS}" ]; then
+                       show "Setting parameters for drive %s (%s)" "$drive" "$PARAMS"
+                       busy
+                       /sbin/hdparm ${PARAMS} /dev/${drive}
+                       ok
+               fi
+       fi
+done
 
 exit 0
This page took 0.045694 seconds and 4 git commands to generate.