[packages]: Add utils/hd-idle package
git-svn-id: svn://svn.openwrt.org/openwrt/packages@12824 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
5dfb620460
commit
977e5c55a9
46
utils/hd-idle/Makefile
Normal file
46
utils/hd-idle/Makefile
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2008 OpenWrt.org
|
||||||
|
#
|
||||||
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
|
# See /LICENSE for more information.
|
||||||
|
#
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=hd-idle
|
||||||
|
PKG_REV:=HEAD
|
||||||
|
PKG_VERSION:=$(PKG_REV)
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
|
||||||
|
PKG_SOURCE_URL:=:pserver:anonymous@hd-idle.cvs.sourceforge.net:/cvsroot/hd-idle
|
||||||
|
PKG_SOURCE_SUBDIR:=$(PKG_NAME)
|
||||||
|
PKG_SOURCE_VERSION:=$(PKG_REV)
|
||||||
|
PKG_SOURCE_PROTO:=cvs
|
||||||
|
|
||||||
|
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
||||||
|
|
||||||
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
define Package/hd-idle
|
||||||
|
SECTION:=utils
|
||||||
|
CATEGORY:=Utilities
|
||||||
|
TITLE:=Another idle-daemon for attached hard drives
|
||||||
|
SUBMENU:=disc
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Compile
|
||||||
|
$(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/$(PKG_NAME).c
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/hd-idle/install
|
||||||
|
$(INSTALL_DIR) $(1)/usr/bin
|
||||||
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/
|
||||||
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
|
$(INSTALL_DATA) ./files/$(PKG_NAME).config $(1)/etc/config/$(PKG_NAME)
|
||||||
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
|
$(INSTALL_BIN) ./files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call BuildPackage,hd-idle))
|
6
utils/hd-idle/files/hd-idle.config
Normal file
6
utils/hd-idle/files/hd-idle.config
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
config 'hd-idle'
|
||||||
|
option 'disk' 'sda'
|
||||||
|
option 'enable_debug' '0'
|
||||||
|
option 'enabled' '0'
|
||||||
|
option 'idle_time_unit' 'minutes'
|
||||||
|
option 'idle_time_interval' '10'
|
87
utils/hd-idle/files/hd-idle.init
Normal file
87
utils/hd-idle/files/hd-idle.init
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#!/bin/sh /etc/rc.common
|
||||||
|
# Copyright (C) 2008 OpenWrt.org
|
||||||
|
START=50
|
||||||
|
|
||||||
|
SSD=start-stop-daemon
|
||||||
|
NAME=hd-idle
|
||||||
|
PROG=/usr/bin/$NAME
|
||||||
|
|
||||||
|
append_bool() {
|
||||||
|
local section="$1"
|
||||||
|
local option="$2"
|
||||||
|
local value="$3"
|
||||||
|
local _val
|
||||||
|
config_get_bool _val "$section" "$option" '0'
|
||||||
|
[ "$_val" -gt 0 ] && append args "$3"
|
||||||
|
}
|
||||||
|
|
||||||
|
append_string() {
|
||||||
|
local section="$1"
|
||||||
|
local option="$2"
|
||||||
|
local value="$3"
|
||||||
|
local _val
|
||||||
|
config_get _val "$section" "$option"
|
||||||
|
[ -n "$_val" ] && append args "$3 $_val"
|
||||||
|
}
|
||||||
|
|
||||||
|
compute_seconds() {
|
||||||
|
local interval="$1"
|
||||||
|
local unit="$2"
|
||||||
|
|
||||||
|
if [ -z "$interval" ]
|
||||||
|
then
|
||||||
|
interval=10
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$unit" ]
|
||||||
|
then
|
||||||
|
unit="minutes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# compute interval in seconds
|
||||||
|
case "$unit" in
|
||||||
|
"days" )
|
||||||
|
interval_seconds=$(($interval*60*60*24))
|
||||||
|
;;
|
||||||
|
"hours" )
|
||||||
|
interval_seconds=$(($interval*60*60))
|
||||||
|
;;
|
||||||
|
"minutes" )
|
||||||
|
interval_seconds=$(($interval*60))
|
||||||
|
;;
|
||||||
|
"seconds" )
|
||||||
|
interval_seconds=$interval
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
# default is minutes
|
||||||
|
interval_seconds=$(($interval*60))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo $interval_seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
local section="$1"
|
||||||
|
args=""
|
||||||
|
config_get "interval" "$section" "idle_time_interval"
|
||||||
|
config_get "unit" "$section" "idle_time_unit"
|
||||||
|
append_string "$section" "disk" "-t"
|
||||||
|
append_bool "$section" "enable_debug" "-d"
|
||||||
|
config_get_bool "enabled" "$section" "enabled" '1'
|
||||||
|
[ "$enabled" -gt 0 ] && $SSD -S -q -x $PROG -- "-i $(compute_seconds $interval $unit) $args"
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_service() {
|
||||||
|
$SSD -K -q -x $PROG
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
config_load "hd-idle"
|
||||||
|
config_foreach start_service "hd-idle"
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
config_load "hd-idle"
|
||||||
|
config_foreach stop_service "hd-idle"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user