From 04f18ac5a2bdfdd0e1499a213f646193e5a93581 Mon Sep 17 00:00:00 2001 From: gwlim Date: Mon, 22 Sep 2014 01:12:49 +0800 Subject: [PATCH] hd-idle: import from old package repository Signed-off-by: Lim Guo Wei Minor Makefile rework (licenses) Signed-off-by: Ted Hess --- utils/hd-idle/Makefile | 55 +++++++++++++++++++++ utils/hd-idle/files/hd-idle.config | 5 ++ utils/hd-idle/files/hd-idle.init | 79 ++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 utils/hd-idle/Makefile create mode 100644 utils/hd-idle/files/hd-idle.config create mode 100644 utils/hd-idle/files/hd-idle.init diff --git a/utils/hd-idle/Makefile b/utils/hd-idle/Makefile new file mode 100644 index 000000000..cf1493ab5 --- /dev/null +++ b/utils/hd-idle/Makefile @@ -0,0 +1,55 @@ +# +# Copyright (C) 2014 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=hd-idle +PKG_VERSION:=1.04 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Lim Guo Wei +PKG_LICENSE:=GPL-2.0 +PKG_LICENSE_FILE:= + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tgz +PKG_SOURCE_URL:=@SF/$(PKG_NAME) +PKG_MD5SUM:=41e52e669fc59fa82ee0c2bcce1336d3 + +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 + URL:=http://hd-idle.sourceforge.net/ +endef + +define Package/hd-idle/description + hd-idle is a utility program for spinning-down external disks after a period of idle time. +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/conffiles +/etc/config/hd-idle +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)) diff --git a/utils/hd-idle/files/hd-idle.config b/utils/hd-idle/files/hd-idle.config new file mode 100644 index 000000000..dbbd358b8 --- /dev/null +++ b/utils/hd-idle/files/hd-idle.config @@ -0,0 +1,5 @@ +config 'hd-idle' + option 'disk' 'sda' + option 'enabled' '0' + option 'idle_time_unit' 'minutes' + option 'idle_time_interval' '10' diff --git a/utils/hd-idle/files/hd-idle.init b/utils/hd-idle/files/hd-idle.init new file mode 100644 index 000000000..b8ce5cf07 --- /dev/null +++ b/utils/hd-idle/files/hd-idle.init @@ -0,0 +1,79 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2008-2011 OpenWrt.org + +START=50 + +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" "-a" + config_get_bool "enabled" "$section" "enabled" '1' + [ "$enabled" -gt 0 ] || return 1 + service_start /usr/bin/hd-idle $args -i "$(compute_seconds $interval $unit)" +} + +start() { + config_load "hd-idle" + config_foreach start_service "hd-idle" +} + +stop() { + service_stop /usr/bin/hd-idle +}