-
Notifications
You must be signed in to change notification settings - Fork 1
/
installer
executable file
·120 lines (99 loc) · 2.66 KB
/
installer
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# qubes-terminal-hotkeys installer
#
# Copyright (C) 2020 David Hobach GPLv3
# version: 0.3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#name & directory of this script (hopefully...)
SCRIPT_NAME="${BASH_SOURCE[0]##*/}"
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
#where to install binaries/symbolic links to
INSTALL_BIN="/usr/bin"
function usage {
echo "Usage: $SCRIPT_NAME [install|uninstall|reinstall]
Installer for qubes-terminal-hotkeys.
Make sure you copied all qubes-terminal-hotkeys file to their installation directory before executing an install."
exit 1
}
function errorOut {
>&2 echo "ERROR: $1"
>&2 echo "Aborting..."
exit 1
}
#get config
CONF="/etc/qubes-terminal-hotkeys.conf"
[ -f "/etc/qubes-terminal-hotkeys.conf" ] || CONF="$SCRIPT_DIR/qubes-terminal-hotkeys.conf"
source "$CONF" || errorOut "Failed to read the configuration $CONF."
#qubes-terminal-hotkeys script
QHK="$SCRIPT_DIR/qubes-terminal-hotkeys"
[ -f "$QHK" ] || errorOut "Didn't find the main script at $QHK."
#installR
function installR {
local hotkey=
for hotkey in "${!HOTKEYS[@]}" ; do
local toInstall="$INSTALL_BIN/$hotkey"
if [ -e "$toInstall" ] ; then
echo "$toInstall appears to exist. Skipping."
else
echo "Installing to $toInstall ..."
ln -s "$QHK" "$toInstall" || errorOut "Failed to create a symbolic link from $toInstall to $QHK."
fi
done
return 0
}
#uninstallR
function uninstallR {
local bin=
local target=
for bin in "$INSTALL_BIN/"* ; do
if [ -L "$bin" ] ; then
target="$(readlink -f "$bin")" || errorOut "Failed to execute readlink on $bin."
if [[ "$target" == "$QHK" ]] ; then
echo "Removing $bin ..."
rm -f "$bin" || errorOut "Failed to remove $bin."
fi
fi
done
return 0
}
function reinstallR {
uninstallR || errorOut "Failed to uninstall."
installR
}
function main {
[ $# -ne 1 ] && usage
[ "$(whoami)" != "root" ] && errorOut "This script must be run as root."
#parse commands
local cmd="$1"
case "$cmd" in
install)
installR
;;
uninstall)
uninstallR
;;
reinstall)
reinstallR
;;
*)
usage
;;
esac
echo "All done."
exit 0
}
main "$@"