-
Notifications
You must be signed in to change notification settings - Fork 6
/
install
executable file
·80 lines (71 loc) · 1.86 KB
/
install
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
#!/usr/bin/env bash
usage() {
cat <<EOF
Usage: $0
This script will install fzf-help to /usr/share/fzf-help. If you
want to install without root privileges, use the --user option to install to
~/.local/share/fzf-help.
Options:
--root Install to /usr/share/fzf-help (default)
--user Install to ~/.local/share/fzf-help
-h, --help Show this help message
EOF
}
#######################################
# Parse command line arguments
#######################################
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--root)
shift
;;
--user)
plugin_dir="$HOME/.local/share/fzf-help"
root=false
shift
;;
-h | --help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
done
}
abort() {
echo 'installation aborted'
exit 1
}
#######################################
# Install fzf-help with, or without root privileges, depending on the value of
# the $root variable.
#######################################
install() {
echo "Installing fzf-help at: $plugin_dir"
makedir="mkdir -p $plugin_dir || abort"
copy="cp $this_dir/src/* $plugin_dir || abort"
copy_uninstall="cp $this_dir/uninstall $plugin_dir || abort"
if $root; then
echo "Installing as root"
eval "sudo $makedir"
eval "sudo $copy"
eval "sudo $copy_uninstall"
else
echo "Installing as user"
eval "$makedir"
eval "$copy"
eval "$copy_uninstall"
fi
echo 'Installation complete.'
}
this_dir=$(dirname $(realpath ${BASH_SOURCE:-$0}))
$this_dir/uninstall $@
root=true
plugin_dir=/usr/share/fzf-help
parse_args $@
install