[packages] restorefactory: add package (closes: #6464)
authorNuno Goncalves <nunojpg@gmail.com>
Thu, 22 Apr 2010 15:55:55 +0000 (15:55 +0000)
committerNuno Goncalves <nunojpg@gmail.com>
Thu, 22 Apr 2010 15:55:55 +0000 (15:55 +0000)
SVN-Revision: 21090

utils/restorefactory/Makefile [new file with mode: 0644]
utils/restorefactory/files/etc/hotplug.d/button/50-restorefactory [new file with mode: 0755]
utils/restorefactory/files/etc/uci-defaults/50-restorefactory [new file with mode: 0755]

diff --git a/utils/restorefactory/Makefile b/utils/restorefactory/Makefile
new file mode 100644 (file)
index 0000000..a359a66
--- /dev/null
@@ -0,0 +1,35 @@
+# 
+# Copyright (C) 2010 segal.di.ubi.pt 
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=restorefactory
+PKG_VERSION:=1
+PKG_RELEASE:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/restorefactory
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE:=Mimic original functionality of the reset button
+  MAINTAINER:=Nuno Goncalves <nunojpg@gmail.com>
+endef
+
+define Package/restoreyfactory/description
+RestoreFactory handles the reset button event and issues a "firstboot" command.
+Button and wait time can be configured with a UCI file.
+endef
+
+define Build/Compile
+endef
+
+define Package/restorefactory/install
+       $(CP) ./files/* $(1)
+endef
+
+$(eval $(call BuildPackage,restorefactory))
diff --git a/utils/restorefactory/files/etc/hotplug.d/button/50-restorefactory b/utils/restorefactory/files/etc/hotplug.d/button/50-restorefactory
new file mode 100755 (executable)
index 0000000..2331bb2
--- /dev/null
@@ -0,0 +1,31 @@
+# /bin/sh
+
+system_config() {
+        config_get button "$1" button "reset"
+       config_get action "$1" action "pressed"
+       config_get timeout "$1" timeout "5"   
+}
+
+config_load system
+config_foreach system_config restorefactory
+
+[ "$BUTTON" = "$button" ] && {
+
+       [ -f /tmp/run/restorefactory.pid ] && read PID < /tmp/run/restorefactory.pid && kill $PID && rm /tmp/run/restorefactory.pid && logger -p user.info -t "restorefactory" "restore to factory defaults aborted"
+
+        [ "$ACTION" = "$action" ] && {
+
+               if [ "$timeout" -gt 0 ]
+               then
+                       sleep "$timeout" && firstboot && reboot &
+                       echo $! > /tmp/run/restorefactory.pid
+                       logger -p user.info -t "restorefactory" "restoring to factory defaults in $timeout seconds"
+               elif [ "$timeout" -eq 0 ]
+               then            
+                       firstboot && reboot &
+               else
+                       logger -p user.info -t "restorefactory" "invalid timeout value ($timeout)"
+               fi
+        }
+} 
+
diff --git a/utils/restorefactory/files/etc/uci-defaults/50-restorefactory b/utils/restorefactory/files/etc/uci-defaults/50-restorefactory
new file mode 100755 (executable)
index 0000000..9b73f33
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+uci add system restorefactory
+uci set system.@restorefactory[0].button=reset 
+uci set system.@restorefactory[0].action=pressed
+uci set system.@restorefactory[0].timeout=5     
+uci commit
+