summaryrefslogtreecommitdiffstats
path: root/testing/hdparm
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-02-24 09:49:06 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-02-24 09:49:06 +0000
commit312d842a9b7a744412b130444687c9de69fe8136 (patch)
tree34b282f38dc7f026b982ada9b5388ca643d973f4 /testing/hdparm
parent7ac7f410ad3def56b89fbe59bbcd32ed3b1e199b (diff)
downloadaports-312d842a9b7a744412b130444687c9de69fe8136.tar.bz2
aports-312d842a9b7a744412b130444687c9de69fe8136.tar.xz
testing/hdparm: added init.d script
Diffstat (limited to 'testing/hdparm')
-rw-r--r--testing/hdparm/APKBUILD12
-rw-r--r--testing/hdparm/hdparm.confd26
-rw-r--r--testing/hdparm/hdparm.initd142
3 files changed, 177 insertions, 3 deletions
diff --git a/testing/hdparm/APKBUILD b/testing/hdparm/APKBUILD
index 38ca77c6..f9fb4bf9 100644
--- a/testing/hdparm/APKBUILD
+++ b/testing/hdparm/APKBUILD
@@ -1,14 +1,16 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=hdparm
pkgver=9.27
-pkgrel=0
+pkgrel=1
pkgdesc="A shell utility for manipulating Linux IDE drive/driver parameters"
url="http://sourceforge.net/projects/hdparm/"
license="BSD"
depends=
makedepends=
subpackages="$pkgname-doc"
-source="http://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.gz"
+source="http://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.gz
+ hdparm.initd
+ hdparm.confd"
_builddir="$srcdir"/$pkgname-$pkgver
build() {
@@ -22,6 +24,10 @@ package() {
make DESTDIR="$pkgdir" install || return 1
install -m755 contrib/idectl "$pkgdir"/sbin || return 1
install -m755 contrib/ultrabayd "$pkgdir"/sbin || return 1
+ install -Dm755 "$srcdir"/hdparm.initd "$pkgdir"/etc/init.d/hdparm
+ install -Dm644 "$srcdir"/hdparm.confd "$pkgdir"/etc/conf.d/hdparm
install -D -m 644 LICENSE.TXT $pkgdir/usr/share/licenses/hdparm/LICENSE.TXT || return 1
}
-md5sums="e652dabb6c9233fb8a23ef60a17a1829 hdparm-9.27.tar.gz"
+md5sums="e652dabb6c9233fb8a23ef60a17a1829 hdparm-9.27.tar.gz
+d530139a31b3941b3b0fbb4d98391a85 hdparm.initd
+998430f701b1d54588cb02ef1505c3ed hdparm.confd"
diff --git a/testing/hdparm/hdparm.confd b/testing/hdparm/hdparm.confd
new file mode 100644
index 00000000..a1ae626b
--- /dev/null
+++ b/testing/hdparm/hdparm.confd
@@ -0,0 +1,26 @@
+# /etc/conf.d/hdparm: config file for /etc/init.d/hdparm
+
+#
+# Note that options such as -y which force *immediate* power saving options
+# should generally not be placed here. The hdparm init.d script may run at
+# anytime with respect to other init.d scripts that do system wide drive
+# scans (like the hald script), so they will merely get spun right back up.
+# If you wish to use these options, please use the local.start init.d script
+# instead so that you're guaranteed that it will run last.
+#
+
+# You can either set hdparm arguments for each drive using hdX_args,
+# discX_args, cdromX_args and genericX_args, e.g.
+#
+# hda_args="-d1 -X66"
+# disc1_args="-d1"
+# cdrom0_args="-d1"
+
+# or you can set options for all PATA drives
+pata_all_args="-d1"
+
+# or you can set options for all SATA drives
+sata_all_args=""
+
+# or, you can set hdparm options for all drives
+all_args=""
diff --git a/testing/hdparm/hdparm.initd b/testing/hdparm/hdparm.initd
new file mode 100644
index 00000000..89aa4f82
--- /dev/null
+++ b/testing/hdparm/hdparm.initd
@@ -0,0 +1,142 @@
+#!/sbin/runscript
+# METHOD
+# ------
+# if /dev/ide exists, find all block devices beneath it named disc, cd, or
+# generic.
+#
+# for the disc and cd ones, if there is a a matching /dev/hdX symlink and
+# hdX_args is set in the config file, use hdX_args. otherwise, if there is a
+# matching /dev/discs/discX or /dev/cdroms/cdromX symlink, and discX_args or
+# cdromX_args is set in the config file, use discX_args / cdromX_args. finally,
+# if all_args is set in the config file, use that.
+#
+# for the generic ones, sort them and look for genericX_args in the config file
+# or use all_args.
+#
+# if /dev/ide does not exist, check the /dev/hdX entries, and see which ones
+# correspond to real devices by opening them for reading. then check hdX_args
+# and all_args in the config file.
+#
+# for each device considered, if no args are found in the config file, do not
+# run hdparm.
+
+depend() {
+ before bootmisc
+}
+
+do_hdparm() {
+ local e=
+ eval e=\$${extra_args}
+ [ -z "${args}${all_args}${e}" ] && return 0
+
+ if [ -n "${args:=${all_args} ${e}}" ] ; then
+ local orgdevice=$(readlink -f "${device}")
+ if [ -b "${orgdevice}" ] ; then
+ ebegin "Running hdparm on ${device}"
+ hdparm ${args} "${device}" > /dev/null
+ eend $?
+ fi
+ fi
+}
+
+scan_devfs() {
+ local extra_args="pata_all_args" device= alias= args=
+
+ # devfs compatible systems
+ for device in $(find /dev/ide -name disc) ; do
+ args=''
+
+ for alias in /dev/hd? ; do
+ if [ "${alias}" -ef "${device}" ] ; then
+ device=${alias}
+ eval args=\$"$(basename "${alias}")"_args
+ break
+ fi
+ done
+
+ if [ -z "$args" ] ; then
+ for alias in /dev/discs/* ; do
+ if [ "${alias}"/disc -ef "${device}" ]; then
+ device="${alias}/disc"
+ eval args=\$"$(basename "${alias}")"_args
+ break
+ fi
+ done
+ fi
+
+ do_hdparm
+ done
+
+ for device in $(find /dev/ide -name cd) ; do
+ args=''
+
+ for alias in /dev/hd? ; do
+ if [ "${alias}" -ef "${device}" ] ; then
+ device=${alias}
+ eval args=\$"$(basename "${alias}")"_args
+ break
+ fi
+ done
+
+ if [ -z "$args" ] ; then
+ for alias in /dev/cdroms/* ; do
+ if [ "${alias}" -ef "${device}" ] ; then
+ device=${alias}
+ eval args=\$"$(basename "${alias}")"_args
+ break
+ fi
+ done
+ fi
+
+ do_hdparm
+ done
+
+ local count=0
+ # of course, the sort approach would fail here if any of the
+ # host/bus/target/lun numbers reached 2 digits..
+ for device in $(find /dev/ide -name generic | sort) ; do
+ eval args=\$generic${count}_args
+ do_hdparm
+ count=$((${count} + 1))
+ done
+}
+
+scan_nondevfs() {
+ # non-devfs compatible system
+ for device in /dev/hd* /dev/sd* ; do
+ [ -e "${device}" ] || continue
+ case "${device}" in
+ *[0-9]) continue ;;
+ /dev/hd*) extra_args="pata_all_args" ;;
+ /dev/sd*) extra_args="sata_all_args" ;;
+ *) extra_args="" ;;
+ esac
+
+ # check that the block device really exists by
+ # opening it for reading
+ local errmsg= status= nomed=1
+ errmsg=$(export LC_ALL=C ; : 2>&1 <"${device}")
+ status=$?
+ case ${errmsg} in
+ *": No medium found") nomed=0;;
+ esac
+ if [ -b "${device}" ] && [ "${status}" = "0" -o "${nomed}" = "0" ] ; then
+ local conf_var="${device##*/}_args"
+ eval args=\$${conf_var}
+ do_hdparm
+ fi
+ done
+}
+
+start() {
+ if get_bootparam "nohdparm" ; then
+ ewarn "Skipping hdparm init as requested in kernel cmdline"
+ return 0
+ fi
+
+ if [ -e /dev/.devfsd -a -d /dev/ide ] ; then
+ scan_devfs
+ else
+ scan_nondevfs
+ fi
+}