/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1
24 by Gustav Hartvigsson
Merge.
1
#!/usr/bin/env bash
2
27 by Gustav Hartvigsson
Added copyright information to all files.
3
####
4
# FILE NAME lock-and-suspend.sh
5
#
6
# Lock and suspend a LightDM Session.
7
#
8
# Authors:
9
#   Gustav Hartvigsson 2024
10
#   Distributed under the Cool Licence 1.1
11
####
12
13
24 by Gustav Hartvigsson
Merge.
14
__SYSTEM=""
15
#FIXME: Auto detect DM?
16
__DM_TOOL="dm-tool lock"
17
18
19
function __auto_system () {
20
  if [[ -n $(which systemctl) ]]; then
21
    __SYSTEM="systemd"
22
  elif [[ -n $(which dbus-send) ]]; then
23
    __SYSTEM="dbus"
24
  elif [[ $(which loginctl) ]]; then
25
    __SYSTEM="loginctl"
26
  elif [[ -n $(which pm-suspend) ]]; then
27
    __SYSTEM="pm"
28
  else
29
    echo "UNSUPORTED SYSTEM!?"
30
    exit 1
31
  fi
32
}
33
34
function __suspend() {
35
  echo "$__SYSTME"
36
  if [[ $__SYSTEM == "systemd" ]]; then
37
    ${__DM_TOOL}
38
    systemctl suspend-then-hibernate
39
  elif [[ $__SYSTEM == "dbus" ]]; then
40
    ${__DM_TOOL}
41
    bus-send --system --print-reply\
42
    --dest=org.freedesktop.login1 /org/freedesktop/login
43
    "org.freedesktop.login1.Manager.Suspend"\
44
    boolean:true
45
  elif [[ $__SYSTEM == "loginctl" ]]; then
46
    ${__DM_TOOL}
47
    lloginctl suspend 
48
  elif [[ $__SYSTEM == "pm" ]]; then
49
    ${__DM_TOOL}
50
    pm_suspend
51
  else
52
    echo "UNSUPORTED SYSTEM!?"
53
    exit 1
54
  fi
55
}
56
57
function __parse_args() {
58
  # FIXME:
59
  echo "Argurment parsing is not implemented yet!"
60
}
61
62
function __main() {
63
  if [[ $# !=  0 ]]; then
64
    __parse_args $@
65
  else
66
    __auto_system $@
67
  fi
68
  
69
  __suspend $@
70
71
}
72
73
__main $@