forked from MarkHedleyJones/dmenu-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemd-install.sh
executable file
·77 lines (65 loc) · 1.86 KB
/
systemd-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Installs dmenu_extended_cache_build as a systemd service to be executed every 20 minutes
# Process command line arguments
for i in "$@"
do
case $i in
-u|--user)
PER_USER_INSTALL=YES
shift # past argument=value
;;
-d|--uninstall)
UNINSTALL=YES
esac
done
DECB_NONDEFAULT=false;
if [ "$PER_USER_INSTALL" == "YES" ] ; then
SCRIPT_PATH=$HOME/.local/share/systemd/user
DECB_DEFAULT=~/.local/bin/dmenu_extended_cache_build
if [ ! -f $DECB_DEFAULT ]; then
DECB_NONDEFAULT=true
fi
else
SCRIPT_PATH=/usr/lib/systemd/user
DECB_DEFAULT=/usr/bin/dmenu_extended_cache_build
if [ ! -f DECB_DEFAULT ]; then
DECB_NONDEFAULT=true
fi
fi
if [ "$UNINSTALL" == "YES" ]; then
echo "Uninstalling systemd service in $SCRIPT_PATH..."
rm -v $SCRIPT_PATH/{update-dmenu-extended-db.service,update-dmenu-extended-db.timer}
exit
fi
if [ ! -d "$SCRIPT_PATH" ]; then
echo "Creating directory $SCRIPT_PATH..."
mkdir -p $SCRIPT_PATH
fi
echo "Installing systemd service in $SCRIPT_PATH..."
if [ $DECB_NONDEFAULT ]; then
echo "dmenu_extended_cache_build not found at the default location."
echo "Please enter the full path to dmenu_extended_cache_build:"
read DECB_PATH
else
DECB_PATH = $DECB_DEFAULT
fi;
# If per-user install, we need systemd to call dmenu_extended_cache build with /bin/sh -c
if [ "$PER_USER_INSTALL" == "YES" ]; then
SYSTEMD_EXEC='/bin/sh -c "$DECB_PATH"'
else
SYSTEMD_EXEC=$DECB_PATH
fi
# Clear old file (if exists) then (re)write
if [ -f $SCRIPT_PATH/update-dmenu-extended-db.service ]; then
rm $SCRIPT_PATH/update-dmenu-extended-db.service
fi
cat <<EOT >> $SCRIPT_PATH/update-dmenu-extended-db.service
[Unit]
Description=Updates the database file used by dmenu_extended_run
[Service]
Type=oneshot
User=%i
ExecStart=$SYSTEMD_EXEC
EOT
echo "$SCRIPT_PATH/update-dmenu-extended-db.service created."
cp -v systemd/update-dmenu-extended-db.timer $SCRIPT_PATH