/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1

« back to all changes in this revision

Viewing changes to scripts/lock-and-suspend.sh

  • Committer: Gustav Hartvigsson
  • Date: 2024-07-21 15:52:28 UTC
  • mfrom: (22.1.1)
  • Revision ID: git-v1:924d562846d864ade91a0ba932977a58e380ca6f
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
__SYSTEM=""
 
4
#FIXME: Auto detect DM?
 
5
__DM_TOOL="dm-tool lock"
 
6
 
 
7
 
 
8
function __auto_system () {
 
9
  if [[ -n $(which systemctl) ]]; then
 
10
    __SYSTEM="systemd"
 
11
  elif [[ -n $(which dbus-send) ]]; then
 
12
    __SYSTEM="dbus"
 
13
  elif [[ $(which loginctl) ]]; then
 
14
    __SYSTEM="loginctl"
 
15
  elif [[ -n $(which pm-suspend) ]]; then
 
16
    __SYSTEM="pm"
 
17
  else
 
18
    echo "UNSUPORTED SYSTEM!?"
 
19
    exit 1
 
20
  fi
 
21
}
 
22
 
 
23
function __suspend() {
 
24
  echo "$__SYSTME"
 
25
  if [[ $__SYSTEM == "systemd" ]]; then
 
26
    ${__DM_TOOL}
 
27
    systemctl suspend-then-hibernate
 
28
  elif [[ $__SYSTEM == "dbus" ]]; then
 
29
    ${__DM_TOOL}
 
30
    bus-send --system --print-reply\
 
31
    --dest=org.freedesktop.login1 /org/freedesktop/login
 
32
    "org.freedesktop.login1.Manager.Suspend"\
 
33
    boolean:true
 
34
  elif [[ $__SYSTEM == "loginctl" ]]; then
 
35
    ${__DM_TOOL}
 
36
    lloginctl suspend 
 
37
  elif [[ $__SYSTEM == "pm" ]]; then
 
38
    ${__DM_TOOL}
 
39
    pm_suspend
 
40
  else
 
41
    echo "UNSUPORTED SYSTEM!?"
 
42
    exit 1
 
43
  fi
 
44
}
 
45
 
 
46
function __parse_args() {
 
47
  # FIXME:
 
48
  echo "Argurment parsing is not implemented yet!"
 
49
}
 
50
 
 
51
function __main() {
 
52
  if [[ $# !=  0 ]]; then
 
53
    __parse_args $@
 
54
  else
 
55
    __auto_system $@
 
56
  fi
 
57
  
 
58
  __suspend $@
 
59
 
 
60
}
 
61
 
 
62
__main $@