Browse Source

hd-idle: import from old package repository

Signed-off-by: Lim Guo Wei <limguowei@gmail.com>

Minor Makefile rework (licenses)
Signed-off-by: Ted Hess <thess@kitschensync.net>
gwlim 10 years ago
parent
commit
04f18ac5a2
3 changed files with 139 additions and 0 deletions
  1. 55
    0
      utils/hd-idle/Makefile
  2. 5
    0
      utils/hd-idle/files/hd-idle.config
  3. 79
    0
      utils/hd-idle/files/hd-idle.init

+ 55
- 0
utils/hd-idle/Makefile View File

@@ -0,0 +1,55 @@
1
+#
2
+# Copyright (C) 2014 OpenWrt.org
3
+#
4
+# This is free software, licensed under the GNU General Public License v2.
5
+# See /LICENSE for more information.
6
+#
7
+
8
+include $(TOPDIR)/rules.mk
9
+
10
+PKG_NAME:=hd-idle
11
+PKG_VERSION:=1.04
12
+PKG_RELEASE:=1
13
+
14
+PKG_MAINTAINER:=Lim Guo Wei <limguowei@gmail.com>
15
+PKG_LICENSE:=GPL-2.0
16
+PKG_LICENSE_FILE:=
17
+
18
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tgz
19
+PKG_SOURCE_URL:=@SF/$(PKG_NAME)
20
+PKG_MD5SUM:=41e52e669fc59fa82ee0c2bcce1336d3
21
+
22
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
23
+
24
+include $(INCLUDE_DIR)/package.mk
25
+
26
+define Package/hd-idle
27
+  SECTION:=utils
28
+  CATEGORY:=Utilities
29
+  TITLE:=Another idle-daemon for attached hard drives
30
+  SUBMENU:=disc
31
+  URL:=http://hd-idle.sourceforge.net/
32
+endef
33
+
34
+define Package/hd-idle/description
35
+       hd-idle is a utility program for spinning-down external disks after a period of idle time.
36
+endef
37
+
38
+define Build/Compile
39
+	$(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/$(PKG_NAME).c
40
+endef
41
+
42
+define Package/hd-idle/conffiles
43
+/etc/config/hd-idle
44
+endef
45
+
46
+define Package/hd-idle/install
47
+	$(INSTALL_DIR) $(1)/usr/bin
48
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/
49
+	$(INSTALL_DIR) $(1)/etc/config
50
+	$(INSTALL_DATA) ./files/$(PKG_NAME).config $(1)/etc/config/$(PKG_NAME)
51
+	$(INSTALL_DIR) $(1)/etc/init.d
52
+	$(INSTALL_BIN) ./files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
53
+endef
54
+
55
+$(eval $(call BuildPackage,hd-idle))

+ 5
- 0
utils/hd-idle/files/hd-idle.config View File

@@ -0,0 +1,5 @@
1
+config 'hd-idle'
2
+	option 'disk' 'sda'
3
+	option 'enabled' '0'
4
+	option 'idle_time_unit' 'minutes'
5
+	option 'idle_time_interval' '10'

+ 79
- 0
utils/hd-idle/files/hd-idle.init View File

@@ -0,0 +1,79 @@
1
+#!/bin/sh /etc/rc.common
2
+# Copyright (C) 2008-2011 OpenWrt.org
3
+
4
+START=50
5
+
6
+append_bool() {
7
+	local section="$1"
8
+	local option="$2"
9
+	local value="$3"
10
+	local _val
11
+	config_get_bool _val "$section" "$option" '0'
12
+	[ "$_val" -gt 0 ] && append args "$3"
13
+}
14
+
15
+append_string() {
16
+	local section="$1"
17
+	local option="$2"
18
+	local value="$3"
19
+	local _val
20
+	config_get _val "$section" "$option"
21
+	[ -n "$_val" ] && append args "$3 $_val"
22
+}
23
+
24
+compute_seconds() {
25
+	local interval="$1"
26
+	local unit="$2"
27
+
28
+	if [ -z "$interval" ]
29
+	then
30
+		interval=10
31
+	fi
32
+
33
+	if [ -z "$unit" ]
34
+	then
35
+		unit="minutes"
36
+	fi
37
+
38
+	# compute interval in seconds
39
+	case "$unit" in
40
+		"days" )
41
+			interval_seconds=$(($interval*60*60*24))
42
+			;;
43
+		"hours" )
44
+			interval_seconds=$(($interval*60*60))
45
+			;;
46
+		"minutes" )
47
+			interval_seconds=$(($interval*60))
48
+			;;
49
+		"seconds" )
50
+			interval_seconds=$interval
51
+			;;
52
+		* )
53
+			# default is minutes
54
+			interval_seconds=$(($interval*60))
55
+			;;
56
+	esac
57
+
58
+	echo $interval_seconds
59
+}
60
+
61
+start_service() {
62
+	local section="$1"
63
+	args=""
64
+	config_get "interval" "$section" "idle_time_interval"
65
+	config_get "unit" "$section" "idle_time_unit"
66
+	append_string "$section" "disk" "-a"
67
+	config_get_bool "enabled" "$section" "enabled" '1'
68
+	[ "$enabled" -gt 0 ] || return 1
69
+	service_start /usr/bin/hd-idle $args -i "$(compute_seconds $interval $unit)"
70
+}
71
+
72
+start() {
73
+	config_load "hd-idle"
74
+	config_foreach start_service "hd-idle"
75
+}
76
+
77
+stop() {
78
+	service_stop /usr/bin/hd-idle
79
+}