Skip to content

Commit 115dd64

Browse files
committed
Not all systems have systemctl "-P" option
Change to use "-p" and parse the result.
1 parent 5a7a219 commit 115dd64

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

libinput-gestures-setup

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ user_action() {
144144
fi
145145
fi
146146
elif [[ $cmd == stop ]]; then
147-
if [[ $svc_running == running ]]; then
147+
if [[ $svc_running -eq 1 ]]; then
148148
systemctl --user stop $NAME.service
149149
echo "$NAME stopped as a user service."
150150
fi
@@ -191,7 +191,7 @@ user_action() {
191191
echo "$NAME is set up as a desktop application."
192192
fi
193193

194-
if [[ $svc_running == running ]]; then
194+
if [[ $svc_running -eq 1 ]]; then
195195
echo "$NAME is currently running as a user service."
196196
else
197197
if pgrep -u $USER -f "$NAME\$|$NAME " &>/dev/null; then
@@ -201,7 +201,7 @@ user_action() {
201201
fi
202202
fi
203203

204-
if [[ $svc_enabled == enabled ]]; then
204+
if [[ $svc_enabled -eq 1 ]]; then
205205
echo "$NAME is set to autostart as a user service."
206206
rm -fv $AUTDIR/$NAME.desktop
207207
else
@@ -222,6 +222,15 @@ user_action() {
222222
fi
223223
}
224224

225+
# Test if given systemd property is set for service
226+
sysd_prop() {
227+
if systemctl --user show -p $1 $NAME.service | grep -q "=$2$"; then
228+
echo 1
229+
else
230+
echo 0
231+
fi
232+
}
233+
225234
if [[ $cmd == install || $cmd == uninstall ]]; then
226235
DESTDIR="${DESTDIR%%+(/)}"
227236
if [[ -z $DESTDIR && $(id -un) != root ]]; then
@@ -285,12 +294,12 @@ else
285294
# Test if systemd is installed
286295
if type systemctl &>/dev/null; then
287296
has_sysd=1
288-
svc_enabled=$(systemctl --user show -P UnitFileState $NAME.service)
289-
svc_running=$(systemctl --user show -P SubState $NAME.service)
297+
svc_enabled=$(sysd_prop UnitFileState enabled)
298+
svc_running=$(sysd_prop SubState running)
290299
else
291300
has_sysd=0
292-
svc_enabled="no"
293-
svc_running="no"
301+
svc_enabled=0
302+
svc_running=0
294303
fi
295304

296305
if [[ $cmd == restart ]]; then

0 commit comments

Comments
 (0)