Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app "standby-auto" #1145 #1146

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions bin/ncp/SYSTEM/standby-auto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Periodically system standby and wakeup
#
# Copyleft 2020 by Alessandro Dolci <dolci _d_o_t_ alessandro94 _a_t_ gmail _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#

configure()
{
local cronfile=/etc/cron.d/standby-auto

if [[ "$ACTIVE" != "yes" ]]; then
# Disable cron job
rm -f $cronfile
service cron restart

echo "Automatic standby disabled"
else
# Prevent spaces
local min=$(echo "$MIN" | awk '{print $1;}')
local hour=$(echo "$HOUR"| awk '{print $1;}')

# Create cron job
echo "${min} ${hour} * * * root /usr/sbin/rtcwake -m '${MODE}' -s '$(( DURATION * 60 ))'" > $cronfile
chmod 644 $cronfile
service cron restart

echo "Automatic standby enabled"
fi
}

install() { :; }

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA

40 changes: 40 additions & 0 deletions etc/ncp-config.d/standby-auto.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "standby-auto",
"name": "standby-auto",
"title": "standby-auto",
"description": "Periodically system standby and wakeup",
"info": "Configure system auto standby and wakeup. The system will suspend every day at specified time and will be wakeup after specified minutes. \n\nThis may not work for all hardwares. \n\nYou should not use it for virtual or containerized installations.",
"infotitle": "Optional: for modes available for your installation run this command on your shell: rtcwake --list-modes \ndocs: https://linux.die.net/man/8/rtcwake",
"params": [
{
"id": "ACTIVE",
"name": "Active",
"value": "no",
"type": "bool"
},
{
"id": "MODE",
"name": "Mode",
"value": "off",
"suggest": "off"
},
{
"id": "MIN",
"name": "Start at minute (use crontab syntax)",
"value": "0",
"suggest": "0"
},
{
"id": "HOUR",
"name": "Start at hours (use crontab syntax)",
"value": "22",
"suggest": "22"
},
{
"id": "DURATION",
"name": "Duration (minutes)",
"value": "660",
"suggest": "660"
}
]
}