diff --git a/bin/ncp/SYSTEM/standby-auto.sh b/bin/ncp/SYSTEM/standby-auto.sh new file mode 100644 index 000000000..1b29dd11c --- /dev/null +++ b/bin/ncp/SYSTEM/standby-auto.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Periodically system standby and wakeup +# +# Copyleft 2020 by Alessandro Dolci +# 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 + diff --git a/etc/ncp-config.d/standby-auto.cfg b/etc/ncp-config.d/standby-auto.cfg new file mode 100644 index 000000000..06ccaadf6 --- /dev/null +++ b/etc/ncp-config.d/standby-auto.cfg @@ -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" + } + ] +}