Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
luci-app-autopoweroff for OpenWRT/Lede(中文)


Install to OpenWRT/LEDE

git clone https://github.com/sirpdboy/luci-app-autopoweroff
cp -r luci-app-autopoweroff LEDE_DIR/package/luci-app-autopoweroff

cd LEDE_DIR
./scripts/feeds update -a
./scripts/feeds install -a

make menuconfig
LuCI  --->
	1. Collections  --->
		<*> luci
	3. Applications  --->
		<*> luci-app-autopoweroff.........................LuCI support for Scheduled poweroff


make package/luci-app-autopoweroff/compile V=s
  • Loading branch information
sirpdboy authored Jun 29, 2020
1 parent 98da19f commit c7da4fb
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-2020 johnrosen1

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2019 sirpdboy <https://github.com/sirpdboy/luci-app-autopoweroff/>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#

include $(TOPDIR)/rules.mk

LUCI_TITLE:=LuCI support for Scheduled poweroff
LUCI_DEPENDS:=+luci
LUCI_PKGARCH:=all
PKG_VERSION:=1.0
PKG_RELEASE:=2

PKG_MAINTAINER:=sirpdboy <https://github.com/sirpdboy/luci-app-autopoweroff/>

include $(TOPDIR)/feeds/luci/luci.mk

# call BuildPackage - OpenWrt buildroot signature

4 changes: 4 additions & 0 deletions luasrc/controller/autopoweroff.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module("luci.controller.autopoweroff",package.seeall)
function index()
entry({"admin","system","autopoweroff"},cbi("autopoweroff"),_("Scheduled poweroff"),88)
end
38 changes: 38 additions & 0 deletions luasrc/model/cbi/autopoweroff.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require("luci.sys")

m=Map("autopoweroff",translate("Scheduled poweroff"),translate("Scheduled poweroff Setting"))

s=m:section(TypedSection,"login","")
s.addremove=false
s.anonymous=true

enable=s:option(Flag,"enable",translate("Enable"))
enable.rmempty = false
enable.default=0

week=s:option(ListValue,"week",translate("Week Day"))
week:value(7,translate("Everyday"))
week:value(1,translate("Monday"))
week:value(2,translate("Tuesday"))
week:value(3,translate("Wednesday"))
week:value(4,translate("Thursday"))
week:value(5,translate("Friday"))
week:value(6,translate("Saturday"))
week:value(0,translate("Sunday"))
week.default=0

hour=s:option(Value,"hour",translate("Hour"))
hour.datatype = "range(0,23)"
hour.rmempty = false

pass=s:option(Value,"minute",translate("Minute"))
pass.datatype = "range(0,59)"
pass.rmempty = false


local e=luci.http.formvalue("cbi.apply")
if e then
io.popen("/etc/init.d/autopoweroff restart")
end

return m
25 changes: 25 additions & 0 deletions po/zh-cn/autopoweroff.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
msgid "Scheduled poweroff"
msgstr "定时关机"

msgid "Scheduled poweroff Setting"
msgstr "定时关机设置"

msgid "Week Day"
msgstr "星期"

msgid "Everyday"
msgstr "每天"

msgid "Day"
msgstr "天"

msgid "Hour"
msgstr "小时"

msgid "Minute"
msgstr "分钟"





7 changes: 7 additions & 0 deletions root/etc/config/autopoweroff
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

config login
option minute '0'
option hour '5'
option week '3'
option enable '0'

41 changes: 41 additions & 0 deletions root/etc/init.d/autopoweroff
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh /etc/rc.common
START=50

run_poweroff()
{
local enable
config_get_bool enable $1 enable

if [ $enable = 1 ]; then
local minute
local hour
config_get week $1 week
config_get minute $1 minute
config_get hour $1 hour
if [ $minute = 0 ] ; then
minute="00"
fi
if [ $week = 7 ] ; then
week="*"
fi
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1
/etc/init.d/cron restart
echo "$minute $hour * * $week sleep 5 && touch /etc/banner && poweroff" >> /etc/crontabs/root
echo "Auto poweroff has started."
else
sed -i '/poweroff/d' /etc/crontabs/root >/dev/null 2>&1
/etc/init.d/cron restart
echo "Auto REBOOT has started."
fi
}

start()
{
config_load autopoweroff
config_foreach run_poweroff login
}

stop()
{
echo "Auto poweroff has stoped."
}

0 comments on commit c7da4fb

Please sign in to comment.