@@ -15,12 +15,13 @@ DOCDIR="/usr/share/doc/$NAME"
1515CNFDIR=" /etc"
1616HCFDIR=" ${XDG_CONFIG_HOME:- $HOME / .config} "
1717AUTDIR=" $HCFDIR /autostart"
18+ SVCFLG=" $HOME /.$NAME -service"
1819
1920usage () {
2021 echo " Usage:"
2122 echo " As root: sudo $PROG install|uninstall"
22- echo " As user: $PROG start|stop|restart|autostart|autostop|status |"
23- echo " start-service| autostart-service "
23+ echo " As user: $PROG service|desktop |"
24+ echo " start|stop|restart| autostart|autostop|status "
2425 echo
2526 echo " -d <dir> (option sets DESTDIR for install/uninstall)"
2627 echo " -r (force allow root to perform user commands. PLEASE AVOID USING THIS!)"
@@ -114,53 +115,62 @@ user_action() {
114115 local svc_enabled=" $3 "
115116 local svc_running=" $4 "
116117
117- if [[ $cmd == start ]]; then
118- if [[ $svc_running == running ]]; then
119- echo " Already running as a service."
120- exit 1
121- fi
122- if [[ ! -f $APPDIR /$NAME .desktop ]]; then
123- echo " $NAME is not installed."
118+ if [[ $cmd == service ]]; then
119+ if [[ $has_sysd -eq 0 ]]; then
120+ echo " Systemd not available, can not run as service."
124121 exit 1
125122 fi
126- if de_start " $NAME " ; then
127- echo " $NAME started for desktop."
123+ touch $SVCFLG
124+ rm -fv $AUTDIR /$NAME .desktop
125+ elif [[ $cmd == desktop ]]; then
126+ rm -f $SVCFLG
127+ elif [[ $cmd == start ]]; then
128+ if [[ -f $SVCFLG ]]; then
129+ if [[ $has_sysd -eq 0 ]]; then
130+ echo " Systemd is not installed."
131+ exit 1
132+ fi
133+ if systemctl --user start $NAME .service; then
134+ echo " $NAME started as a user service."
135+ fi
136+ else
137+ if [[ ! -f $APPDIR /$NAME .desktop ]]; then
138+ echo " $NAME is not installed."
139+ exit 1
140+ fi
141+ if de_start " $NAME " ; then
142+ echo " $NAME started for desktop."
143+ fi
128144 fi
129145 elif [[ $cmd == stop ]]; then
130146 if [[ $svc_running == running ]]; then
131147 systemctl --user stop $NAME .service
132- echo " $NAME stopped as user service."
148+ echo " $NAME stopped as a user service."
133149 fi
134150
135151 for prog in libinput-debug-events $NAME ; do
136152 if pkill -u $USER -f " $prog \$ |$prog " & > /dev/null; then
137153 echo " $prog stopped for desktop."
138154 fi
139155 done
140- elif [[ $cmd == start-service ]]; then
141- if [[ $has_sysd -eq 0 ]]; then
142- echo " Systemd is not installed."
143- exit 1
144- fi
145- if systemctl --user start $NAME .service; then
146- echo " $NAME started as user service."
147- fi
148- elif [[ $cmd == autostart-service ]]; then
149- if [[ $has_sysd -eq 0 ]]; then
150- echo " Systemd is not installed."
151- exit 1
152- fi
153- if systemctl --user enable $NAME .service; then
154- echo " $NAME enabled as user service."
155- fi
156- rm -fv $AUTDIR /$NAME .desktop
157156 elif [[ $cmd == autostart ]]; then
158- if ! de_auto_start; then
159- echo " $NAME is not installed."
160- exit 1
161- fi
162- if [[ $has_sysd -eq 1 ]]; then
163- systemctl --user disable $NAME .service & > /dev/null
157+ if [[ -f $SVCFLG ]]; then
158+ if [[ $has_sysd -eq 0 ]]; then
159+ echo " Systemd is not installed."
160+ exit 1
161+ fi
162+ if systemctl --user enable $NAME .service; then
163+ echo " $NAME enabled as a user service."
164+ fi
165+ rm -fv $AUTDIR /$NAME .desktop
166+ else
167+ if ! de_auto_start; then
168+ echo " $NAME is not installed."
169+ exit 1
170+ fi
171+ if [[ $has_sysd -eq 1 ]]; then
172+ systemctl --user disable $NAME .service & > /dev/null
173+ fi
164174 fi
165175 elif [[ $cmd == autostop ]]; then
166176 if [[ $has_sysd -eq 1 ]]; then
@@ -174,37 +184,31 @@ user_action() {
174184 echo " $NAME is not installed."
175185 fi
176186
177- if [[ $svc_enabled == enabled ]]; then
178- echo " $NAME is set to autostart as user service."
187+ if [[ -f $SVCFLG ]]; then
188+ echo " $NAME is set up as a user service."
179189 else
180- echo " $NAME is not set to autostart as user service ."
190+ echo " $NAME is set up as a desktop application ."
181191 fi
182192
183- if [[ -f $AUTDIR /$NAME .desktop ]]; then
184- echo " $NAME is set to autostart as desktop application."
185- else
186- echo " $NAME is not set to autostart as desktop application."
187- fi
188-
189- local svc=0
190- local de=0
191193 if [[ $svc_running == running ]]; then
192- echo " $NAME is running as user service."
193- svc=1
194+ echo " $NAME is currently running as a user service."
194195 else
195- echo " $NAME is not running as user service."
196- svc=0
197- fi
198-
199- if [[ $svc -eq 0 ]]; then
200196 if pgrep -u $USER -f " $NAME \$ |$NAME " & > /dev/null; then
201- echo " $NAME is running as desktop application."
202- de=1
197+ echo " $NAME is currently running as a desktop application."
198+ else
199+ echo " $NAME is not currently running."
203200 fi
204201 fi
205202
206- if [[ $de -eq 0 ]]; then
207- echo " $NAME is not running as desktop application."
203+ if [[ $svc_enabled == enabled ]]; then
204+ echo " $NAME is set to autostart as a user service."
205+ rm -fv $AUTDIR /$NAME .desktop
206+ else
207+ if [[ -f $AUTDIR /$NAME .desktop ]]; then
208+ echo " $NAME is set to autostart as a desktop application."
209+ else
210+ echo " $NAME is not set to autostart."
211+ fi
208212 fi
209213
210214 if [[ -f $HCFDIR /$NAME .conf ]]; then
@@ -289,13 +293,8 @@ else
289293 fi
290294
291295 if [[ $cmd == restart ]]; then
292- if [[ $svc_enabled == enabled || $svc_running == running ]]; then
293- cmd=start-service
294- else
295- cmd=start
296- fi
297-
298296 user_action " stop" $has_sysd $svc_enabled $svc_running
297+ cmd=start
299298 fi
300299
301300 user_action $cmd $has_sysd $svc_enabled $svc_running
0 commit comments