/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-10 14:25:13 UTC
  • Revision ID: git-v1:55fc68b13933a25315ad96a4c69e64d962d2c2d4
Fixed install script's --target flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env bash
2
 
 
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
 
 
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 $@