-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbye
More file actions
executable file
·43 lines (36 loc) · 1.49 KB
/
bye
File metadata and controls
executable file
·43 lines (36 loc) · 1.49 KB
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
#!/usr/bin/env bash
#
# _
# | |__ _ _ ___
# | '_ \| | | |/ _ \
# | |_) | |_| | __/
# |_.__/ \__, |\___|
# |___/
#
# Script : bye
# Location : /usr/local/bin/bye
# Author : Jens Ochmann
# Date : 2025‑04‑20
# License : MIT
# Description : Graceful system shutdown with optional message
# Requires root : Will elevate via sudo if needed
#
set -euo pipefail
#––– Helper ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
err() { printf 'bye: %s\n' "$*" >&2; exit 1; }
# Optional Benutzernachricht (wird an shutdown übergeben)
MSG=${1:-"System wird heruntergefahren – bis bald!"}
#––– Privilege handling ––––––––––––––––––––––––––––––––––––––––––––––––––––––––
if (( EUID != 0 )); then
# Script wurde nicht als root gestartet → sudo versuchen
exec sudo --preserve-env=MSG "$0" "$MSG"
fi
#––– Shut down ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
logger -t bye "$MSG"
if command -v systemctl >/dev/null 2>&1; then
# systemd‑Way
systemctl poweroff
else
# Fallback (SysV / BusyBox u. a.)
/sbin/shutdown -P now "$MSG"
fi