-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins
More file actions
executable file
·262 lines (227 loc) · 6.29 KB
/
plugins
File metadata and controls
executable file
·262 lines (227 loc) · 6.29 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
set -e
PLUGINS_DIR="/app/fuseki/builtin-plugins"
RUN_PLUGINS_DIR="/app/fuseki/run/plugins"
EXTRA_DIR="/app/fuseki/run/extra"
# Ensure directories exist
mkdir -p "$PLUGINS_DIR" "$RUN_PLUGINS_DIR" "$EXTRA_DIR"
# Get all available plugin filenames
get_available_plugins() {
local files=()
if [[ -d "$PLUGINS_DIR" ]]; then
for f in "$PLUGINS_DIR"/*.jar; do
[[ -e "$f" ]] && files+=("$(basename "$f")")
done
fi
if [[ -d "$RUN_PLUGINS_DIR" ]]; then
for f in "$RUN_PLUGINS_DIR"/*.jar; do
[[ -e "$f" ]] && files+=("$(basename "$f")")
done
fi
printf '%s\n' "${files[@]}" | sort -u
}
# Check if plugin is installed (exists in EXTRA_DIR)
is_installed() {
local plugin="$1"
[[ -f "$EXTRA_DIR/$plugin" ]]
}
# Check if plugin exists in either plugins directory
plugin_exists() {
local plugin="$1"
[[ -f "$PLUGINS_DIR/$plugin" ]] || [[ -f "$RUN_PLUGINS_DIR/$plugin" ]]
}
# List available plugins (filenames only)
cmd_list() {
get_available_plugins
}
# Show status of all plugins
cmd_status() {
local plugins
plugins=$(get_available_plugins)
if [[ -z "$plugins" ]]; then
echo "No plugins available."
return 0
fi
echo "$plugins" | while read -r plugin; do
if is_installed "$plugin"; then
echo "$plugin (installed)"
else
echo "$plugin"
fi
done
}
# Add plugin from URL
cmd_add() {
local url="$1"
if [[ -z "$url" ]]; then
echo "Error: URL required" >&2
echo "Usage: plugins add <url>" >&2
exit 1
fi
# Validate URL ends with .jar
if [[ ! "$url" =~ \.jar$ ]]; then
echo "Error: URL must end with .jar" >&2
exit 1
fi
# Extract filename from URL
local filename
filename=$(basename "$url")
# Check if file already exists
if [[ -f "$RUN_PLUGINS_DIR/$filename" ]]; then
echo "Error: Plugin already exists: $filename" >&2
exit 1
fi
echo "Downloading $filename..."
if ! curl -L --proto =https,http,file -o "$RUN_PLUGINS_DIR/$filename" "$url"; then
echo "Error: Download failed for $url" >&2
rm -f "$RUN_PLUGINS_DIR/$filename"
exit 1
fi
if [ ! -s "$RUN_PLUGINS_DIR/$filename" ]; then
echo "Error: Downloaded file is empty" >&2
rm -f "$RUN_PLUGINS_DIR/$filename"
exit 1
fi
echo "Added: $filename"
}
# Remove plugin
cmd_remove() {
local plugins=("$@")
if [[ ${#plugins[@]} -eq 0 ]]; then
echo "Error: At least one plugin name required" >&2
echo "Usage: plugins remove <filename> [filename...]" >&2
exit 1
fi
# Validate all plugins exist first
for plugin in "${plugins[@]}"; do
if ! plugin_exists "$plugin"; then
echo "Error: Plugin not found: $plugin" >&2
exit 1
fi
done
# Remove from both locations
for plugin in "${plugins[@]}"; do
local removed=0
if [[ -f "$RUN_PLUGINS_DIR/$plugin" ]]; then
rm "$RUN_PLUGINS_DIR/$plugin"
removed=1
fi
if [[ -f "$EXTRA_DIR/$plugin" ]]; then
rm "$EXTRA_DIR/$plugin"
removed=1
fi
if [[ $removed -eq 1 ]]; then
echo "Removed: $plugin"
fi
done
}
# Enable plugins
cmd_enable() {
local plugins=("$@")
if [[ ${#plugins[@]} -eq 0 ]]; then
echo "Error: At least one plugin name required" >&2
echo "Usage: plugins enable <filename> [filename...]" >&2
exit 1
fi
# Validate all plugins exist first
for plugin in "${plugins[@]}"; do
if ! plugin_exists "$plugin"; then
echo "Error: Plugin not found: $plugin" >&2
exit 1
fi
done
# Copy to extra directory
for plugin in "${plugins[@]}"; do
local source
if [[ -f "$RUN_PLUGINS_DIR/$plugin" ]]; then
source="$RUN_PLUGINS_DIR/$plugin"
else
source="$PLUGINS_DIR/$plugin"
fi
cp "$source" "$EXTRA_DIR/$plugin"
echo "Enabled: $plugin"
done
}
# Disable plugins
cmd_disable() {
local plugins=("$@")
if [[ ${#plugins[@]} -eq 0 ]]; then
echo "Error: At least one plugin name required" >&2
echo "Usage: plugins disable <filename> [filename...]" >&2
exit 1
fi
# Validate all plugins are installed first
for plugin in "${plugins[@]}"; do
if ! is_installed "$plugin"; then
echo "Error: Plugin not installed: $plugin" >&2
exit 1
fi
done
# Remove from extra directory
for plugin in "${plugins[@]}"; do
rm "$EXTRA_DIR/$plugin"
echo "Disabled: $plugin"
done
}
# Show usage
usage() {
cat <<EOF
Usage: plugins <command> [options]
Commands:
list List available plugins
status List all plugins with installation status
add <url> Download plugin from URL to /app/fuseki/run/plugins/
remove <name> Remove plugin from /app/fuseki/run/plugins/ and /app/fuseki/run/extra/
enable <names> Copy plugin(s) to /app/fuseki/run/extra/ (activate)
disable <names> Remove plugin(s) from /app/fuseki/run/extra/ (deactivate)
Examples:
plugins list
plugins status
plugins add https://example.com/plugin-1.0.0.jar
plugins enable exectracker.jar
plugins disable exectracker.jar graphql.jar
plugins remove exectracker.jar
EOF
}
# Main command dispatcher
main() {
local cmd="$1"
shift || true
case "$cmd" in
list)
cmd_list
;;
status)
cmd_status
;;
add)
cmd_add "$@"
;;
remove)
cmd_remove "$@"
;;
enable)
cmd_enable "$@"
;;
disable)
cmd_disable "$@"
;;
help|--help|-h)
usage
;;
"")
echo "Error: No command specified" >&2
usage >&2
exit 1
;;
*)
echo "Error: Unknown command: $cmd" >&2
usage >&2
exit 1
;;
esac
}
# Run main only if script is executed directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi