-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·90 lines (80 loc) · 1.51 KB
/
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
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
set -o nounset
Logo () {
cat <<EOF
$name
$link
EOF
}
Usage () {
cat <<EOF
usage: ./install.sh
or: ./install.sh uninstall
EOF
}
Install () {
test -d "$target_dir" || mkdir -p "$target_dir" || return
install jg "$target_dir" || return
printf "Install complete.\n"
}
Uninstall () {
if test ! -d "$target_dir"
then
>&2 printf "error: not installed\n"
return 1
fi
rm -f "$target_dir/jg" || return
rmdir "$target_dir" 2>/dev/null
printf "Uninstall complete.\n"
}
ParseArgs () {
if test $# -eq 0
then
Install
return
elif test $# -eq 1
then
case $1 in
-h|--help)
Logo
Usage
exit 0
;;
0|uninstall|--uninstall)
Uninstall
return
;;
1|install|--install)
Install
return
;;
*)
>&2 printf "error: invalid argument \`%s'\n" "$1"
>&2 Usage
exit 1
;;
esac
else
>&2 printf "error: too many arguments\n"
>&2 Usage
exit 1
fi
}
GetTargetDir () {
local OS=${OS-}
if printf "%s" "$OS" | grep -qi "win"
then
target_dir="$HOME/bin"
else
target_dir="/usr/local/bin"
fi
}
main () {
local name="jg installation script"
local link="https://github.com/lxvs/jg"
local target_dir
cd "$(dirname "$0")" || return
GetTargetDir
ParseArgs "$@" || return
}
main "$@"