Gentoo Archives: gentoo-commits

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: kde-plasma/kscreenlocker/files/
Date: Wed, 21 Feb 2018 10:38:45
Message-Id: 1519209507.652b50692630aa0f5e9963d66c11ea9d40edb573.asturm@gentoo
1 commit: 652b50692630aa0f5e9963d66c11ea9d40edb573
2 Author: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 21 10:38:13 2018 +0000
4 Commit: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 21 10:38:27 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=652b5069
7
8 kde-plasma/kscreenlocker: Add missing ck-unlock-session
9
10 Closes: https://bugs.gentoo.org/648352
11 Package-Manager: Portage-2.3.19, Repoman-2.3.6
12
13 kde-plasma/kscreenlocker/files/ck-unlock-session | 220 +++++++++++++++++++++++
14 1 file changed, 220 insertions(+)
15
16 diff --git a/kde-plasma/kscreenlocker/files/ck-unlock-session b/kde-plasma/kscreenlocker/files/ck-unlock-session
17 new file mode 100644
18 index 00000000000..6ce6935b067
19 --- /dev/null
20 +++ b/kde-plasma/kscreenlocker/files/ck-unlock-session
21 @@ -0,0 +1,220 @@
22 +#!/bin/sh
23 +
24 +# This script is to make unlocking using OpenRC/Consolekit easier when the KDE Screenlocker breaks.
25 +#
26 +# Version: 0.2
27 +# Date written: February 2, 2018
28 +# Last modification: February 17, 2018
29 +#
30 +# Copyright (C) 2018 Daniel Frey
31 +# Copyright (C) 2018 Lars Wendler
32 +#
33 +# This script is free software; you can redistribute it and/or
34 +# modify it under the terms of the GNU General Public License
35 +# as published by the Free Software Foundation; either version 2
36 +# of the License, or (at your option) any later version.
37 +#
38 +# This script is distributed in the hope that it will be useful,
39 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
40 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 +# GNU General Public License for more details.
42 +#
43 +#
44 +# Some notes:
45 +# -The switch processing/argument handling is very basic.
46 +# -This script assumes session names start with "Session" when listing
47 +# sessions. This is settable via a variable.
48 +#
49 +# Possible actions:
50 +# -h : Show help screen
51 +# -l : List current consolekit sessions
52 +# -u : Unlock specified session (one parameter required - the session name)
53 +# -a : Attempt to unlock all sessions
54 +
55 +# Return code documentation
56 +#
57 +# 0: Script executed normally
58 +# 1: Root access is not present for script
59 +# 2: No arguments passed
60 +# 3: Multiple actions requested, can only do one at a time
61 +# 4: Argument passed was not recognized
62 +# 5: Multiple arguments passed for unlock single session, only one needed
63 +# 6: The argument required for unlocksession() is missing (internal error)
64 +
65 +SCRIPTNAME="$(basename $0)"
66 +
67 +# Return code constants
68 +readonly ERR_NORMAL_OPERATION=0
69 +readonly ERR_NO_ROOT=1
70 +readonly ERR_NO_ARGS=2
71 +readonly ERR_TOO_MANY_ACTIONS=3
72 +readonly ERR_INVALID_ARGUMENTS=4
73 +readonly ERR_TOO_MANY_ARGS=5
74 +readonly ERR_INTERNAL_ARG_MISSING=6
75 +
76 +# Action parameter constants
77 +readonly ACTION_NONE=0
78 +readonly ACTION_HELP=1
79 +readonly ACTION_LIST=2
80 +readonly ACTION_UNLOCKALL=3
81 +readonly ACTION_UNLOCK=4
82 +
83 +# This is what's used to look for a session via consolekit.
84 +# By default, assume it is prefixed with "Session".
85 +SESSION_SEARCH_PREFIX="Session"
86 +
87 +# Check to make sure script has root access, if not... abort now!
88 +if [ "$(id -u)" -ne 0 ]; then
89 + echo "This script must be run as root."
90 + exit ${ERR_NO_ROOT}
91 +fi
92 +
93 +showhelp() {
94 + cat <<EOF
95 +${SCRIPTNAME}: a script that helps unlock consolekit sessions
96 +
97 +Usage: ${SCRIPTNAME} [action] [parameters]
98 +
99 +Actions:
100 + -l : list current sessions available for unlocking
101 + -u : unlock session specified as a parameter
102 + -a : attempt to unlock all current sessions
103 + -h : this screen
104 +
105 +Parameters:
106 + The -u parameter requires a session name to unlock, use -l to
107 + list sessions.
108 +
109 +Example:
110 + To unlock a single session, use:
111 + ${SCRIPTNAME} -u Session1
112 +
113 +No arguments will show this screen.
114 +EOF
115 +}
116 +
117 +listsessions() {
118 + # Get a list of all sessions, and remove the full colon from the session name
119 + ALLSESSIONS=$(ck-list-sessions | grep "^${SESSION_SEARCH_PREFIX}" | awk -F : '{print $1}')
120 +
121 + echo
122 + echo "Sessions present on this machine, space-delineated:"
123 + echo
124 + echo ${ALLSESSIONS}
125 + echo
126 + echo
127 + echo "Session detail (to help locate a specific session:"
128 + ck-list-sessions | grep -A 2 "^${SESSION_SEARCH_PREFIX}"
129 +}
130 +
131 +unlocksession() {
132 + # This function expects one parameter set (the session to unlock).
133 + # Make sure the parameter exists before continuing.
134 + if [ -z "${1}" ]; then
135 + showhelp
136 + exit ${ERR_INTERNAL_ARG_MISSING}
137 + fi
138 +
139 + echo "Attempting to unlock session $1; messages from dbus are not suppressed."
140 +
141 + # Finally, request the unlock.
142 + dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/$1 org.freedesktop.ConsoleKit.Session.Unlock
143 +}
144 +
145 +unlockallsessions() {
146 + # Get a list of all sessions, and remove the full colon from the session name
147 + ALLSESSIONS=$(ck-list-sessions | grep "^${SESSION_SEARCH_PREFIX}" | awk -F : '{print $1}')
148 +
149 + echo "Attempting to unlock all sessions. Messages from dbus are not suppressed."
150 + echo
151 + # Loop through results, attempt to unlock all sessions.
152 + # Count them and report at the end.
153 + COUNT=0
154 + for i in ${ALLSESSIONS}; do
155 + dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/$i org.freedesktop.ConsoleKit.Session.Unlock
156 + let "COUNT+=1"
157 + done
158 +
159 + echo
160 + echo "Attempted to unlock ${COUNT} session(s)."
161 +}
162 +
163 +check_actions() {
164 + # Make sure multiple actions are not chosen.
165 + if [ ${ACTION} -ne ${ACTION_NONE} ]; then
166 + echo "You can only declare one action at a time!"
167 + echo ""
168 + showhelp
169 + exit ${ERR_TOO_MANY_ACTIONS}
170 + fi
171 +}
172 +
173 +# Start of "main" routine
174 +
175 +# Initialize variables:
176 +# ACTION=default 0; used to make sure more than one action are not
177 +# specified at the same time. If an invalid argument was passed
178 +# (e.g. one without the hyphen prefix) it will be caught as well.
179 +ACTION="${ACTION_NONE}"
180 +
181 +# Show help if no arguments provided at all
182 +if [ $# -eq 0 ]; then
183 + showhelp
184 + exit ${ERR_NO_ARGS}
185 +fi
186 +
187 +# Process arguments passed, setting environment appropriately.
188 +# During this check, ensure only one action was requested. This
189 +# script will not do multiple things at a time.
190 +while getopts “hlau:” OPTION; do
191 + case ${OPTION} in
192 + h) # Help action
193 + check_actions
194 + ACTION=${ACTION_HELP}
195 + ;;
196 + l) # List action
197 + check_actions
198 + ACTION="${ACTION_LIST}"
199 + ;;
200 + a) # Enable all USB hubs/devices action
201 + check_actions
202 + ACTION="${ACTION_UNLOCKALL}"
203 + ;;
204 + u) # Enable specific hub/device via find command action
205 + check_actions
206 + ACTION="${ACTION_UNLOCK}"
207 +
208 + # Save session name passed for later
209 + UNLOCKSESSION="${OPTARG}"
210 + ;;
211 + ?) # Unknown parameter
212 + showhelp
213 + exit ${ERR_INVALID_ARGUMENTS}
214 + ;;
215 + esac
216 +done
217 +
218 +# If script reaches this point, only one action was specified, so it is safe
219 +# to continue processing.
220 +case ${ACTION} in
221 + ${ACTION_HELP}) # help action
222 + showhelp
223 + ;;
224 + ${ACTION_LIST}) # list action
225 + listsessions
226 + ;;
227 + ${ACTION_UNLOCKALL}) # unlock all sessions
228 + unlockallsessions
229 + ;;
230 + ${ACTION_UNLOCK}) # unlock single session
231 + unlocksession ${UNLOCKSESSION}
232 + ;;
233 + *)
234 + echo "Unrecognized action."
235 + echo
236 + showhelp
237 + exit ${ERR_INVALID_ARGUMENTS}
238 + ;;
239 +esac
240 +
241 +exit ${ERR_NORMAL_OPERATION}