-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·155 lines (137 loc) · 3.62 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/sh
info=$(cat << EOF
install.sh install-data|install-script|uninstall-data|uninstall-script
EOF
)
local_home="${XDG_LOCAL_HOME:-$HOME/.local}"
data_home="${XDG_DATA_HOME:-$local_home/share}"
bin_home="${XDG_BIN_HOME:-$local_home/bin}"
clnv_install_data() {
project_home="$(dirname "$0")"
if [ ! -d "$data_home" ]; then
mkdir -p "$data_home"
fi
clnv_home="$data_home/clnv"
if [ ! -d "$clnv_home" ]; then
mkdir -p "$clnv_home"
fi
clnv_script_home="$clnv_home/scripts"
if [ -d "$clnv_script_home" ]; then
rm -rf "$clnv_script_home"
fi
if [ ! -d "$clnv_script_home" ]; then
mkdir -p "$clnv_script_home"
fi
if ! cp -f "$project_home/clnv" "$clnv_home"; then
echo "error: installing clnv script" >&2
exit 1
fi
if
! find "$project_home/scripts" \
-type f \
-exec cp -f "{}" "$clnv_script_home" \; >/dev/null
then
echo "error: installing scripts" >&2
exit 1
fi
echo "clnv data successfully installed"
}
clnv_install_script() {
if [ -z "$CLN_BIN" ]; then
echo "error: set CLN_BIN" >&2
exit 1
fi
# shellcheck disable=SC2086
if ! command -v $CLN_BIN >/dev/null 2>&1; then
echo "error: $CLN_BIN is not a command" >&2
exit 1
fi
if [ -z "$CLNV_NAME" ]; then
echo "error: set CLNV_NAME" >&2
exit 1
fi
if printf "%s\n" "$CLNV_NAME" | grep "[[:space:]]" >/dev/null 2>&1; then
echo "error: $CLNV_NAME should not contain spaces" >&2
exit 1
fi
if [ ! -d "$bin_home" ]; then
mkdir -p "$bin_home"
fi
clnv_install_file="$bin_home/$CLNV_NAME"
if ! touch "$clnv_install_file"; then
echo "error: creating $clnv_install_file" >&2
exit 1
fi
if ! chmod u+x "$clnv_install_file"; then
echo "error: setting permission on $clnv_install_file" >&2
exit 1
fi
clnv_install_file_content=$(cat << EOF
#!/bin/sh
export CLN_BIN="$CLN_BIN"
"\${XDG_DATA_HOME:-\${XDG_LOCAL_HOME:-\$HOME/.local}/share}/clnv/clnv" "\$@"
EOF
)
printf "%s\n" "$clnv_install_file_content" > "$clnv_install_file"
echo "clnv script $CLNV_NAME successfully installed"
}
clnv_uninstall_data() {
clnv_home="$data_home/clnv"
if [ -e "$clnv_home" ]; then
if ! rm -rf "$clnv_home"; then
echo "error: removing $clnv_home" >&2
exit 1
fi
echo "clnv data successfully uninstalled"
else
echo "clnv data was not installed"
fi
}
clnv_uninstall_script() {
if [ -z "$CLNV_NAME" ]; then
echo "error: set CLNV_NAME" >&2
exit 1
fi
if printf "%s\n" "$CLNV_NAME" | grep "[[:space:]]" >/dev/null 2>&1; then
echo "error: $CLNV_NAME should not contain spaces" >&2
exit 1
fi
clnv_install_file="$bin_home/$CLNV_NAME"
if [ -f "$clnv_install_file" ]; then
if ! rm -f "$clnv_install_file"; then
echo "error: removing $clnv_install_file" >&2
exit 1
fi
echo "$CLNV_NAME successfully uninstalled"
else
echo "$CLNV_NAME was not installed"
fi
}
if [ "$#" -lt 1 ]; then
echo "error: insert action" >&2
exit 1
fi
action="$1"
shift 1
case "$action" in
-h|--help)
echo "$info"
exit 0
;;
install-data)
clnv_install_data "$@"
;;
install-script)
clnv_install_script "$@"
;;
uninstall-data)
clnv_uninstall_data "$@"
;;
uninstall-script)
clnv_uninstall_script "$@"
;;
*)
echo "error: action $action not recognized" >&2
exit 1
;;
esac