/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash

####
# FILE NAME lock-and-suspend.sh
#
# Lock and suspend a LightDM Session.
#
# Authors:
#   Gustav Hartvigsson 2024
#   Distributed under the Cool Licence 1.1
####


__SYSTEM=""
#FIXME: Auto detect DM?
__DM_TOOL="dm-tool lock"


function __auto_system () {
  if [[ -n $(which systemctl) ]]; then
    __SYSTEM="systemd"
  elif [[ -n $(which dbus-send) ]]; then
    __SYSTEM="dbus"
  elif [[ $(which loginctl) ]]; then
    __SYSTEM="loginctl"
  elif [[ -n $(which pm-suspend) ]]; then
    __SYSTEM="pm"
  else
    echo "UNSUPORTED SYSTEM!?"
    exit 1
  fi
}

function __suspend() {
  echo "$__SYSTME"
  if [[ $__SYSTEM == "systemd" ]]; then
    ${__DM_TOOL}
    systemctl suspend-then-hibernate
  elif [[ $__SYSTEM == "dbus" ]]; then
    ${__DM_TOOL}
    bus-send --system --print-reply\
    --dest=org.freedesktop.login1 /org/freedesktop/login
    "org.freedesktop.login1.Manager.Suspend"\
    boolean:true
  elif [[ $__SYSTEM == "loginctl" ]]; then
    ${__DM_TOOL}
    lloginctl suspend 
  elif [[ $__SYSTEM == "pm" ]]; then
    ${__DM_TOOL}
    pm_suspend
  else
    echo "UNSUPORTED SYSTEM!?"
    exit 1
  fi
}

function __parse_args() {
  # FIXME:
  echo "Argurment parsing is not implemented yet!"
}

function __main() {
  if [[ $# !=  0 ]]; then
    __parse_args $@
  else
    __auto_system $@
  fi
  
  __suspend $@

}

__main $@