blob: c79c6b0357a9ed81d4a3a638154024bb151b9e36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Deminder <tremminder@gmail.com>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# shutdowntimerctl - This script can configure the shutdown and rtc wake alarm schedule.
#
# This file is part of the gnome-shell extension ShutdownTimer@Deminder.
SHUTDOWN_BIN=/usr/sbin/shutdown
RTCWAKE_BIN=/usr/sbin/rtcwake
SHUTDOWN_MODE="-P"
if [ ! -z "$2" ] && [ "$2" -gt 0 ];then
POSITIVE_VALUE="$2"
fi
function print_help() {
echo "[help] (show this help)" >&2
echo "[shutdown|reboot|shutdown-cancel] {MINUTES}" >&2
echo "[wake|wake-cancel] {MINUTES} (default: 0)" >&2
}
if [ "$#" -lt 1 ]; then
print_help
exit
fi
case "$1" in
shutdown|reboot)
if [[ "$1" = "reboot" ]]; then
SHUTDOWN_MODE="-r"
fi
$SHUTDOWN_BIN "$SHUTDOWN_MODE" "$POSITIVE_VALUE"
;;
shutdown-cancel)
$SHUTDOWN_BIN -c
;;
wake)
$RTCWAKE_BIN --date +${POSITIVE_VALUE:-0}min --mode no
;;
wake-cancel)
$RTCWAKE_BIN --mode disable
;;
--version)
echo 1
;;
-h|help)
print_help
;;
*)
echo "Invalid argument: $1" >&2
print_help
esac
|