-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-plugin-zip.sh
More file actions
executable file
·73 lines (58 loc) · 2.47 KB
/
create-plugin-zip.sh
File metadata and controls
executable file
·73 lines (58 loc) · 2.47 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
#!/usr/bin/env bash
# This script is designed to package typical nexuslua plugin files into a ZIP file. Initially, it collects the required
# files from a specified input directory using the "collect-plugin-files.sh" script. The resulting temporary directory
# is then packaged into a ZIP file. This process is particularly useful in automated build processes to create an nexuslua
# plugin installation package.
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <input_plugin_directory> <output_plugin_zip_path> <nexuslua_executable_path>"
exit 1
fi
convert_path() {
if ! command -v uname >/dev/null 2>&1; then
echo "Error: 'uname' is not available but is required to determine the operating environment." >&2
exit 1
fi
local os_type=$(uname -o)
local path="$1"
if [[ "$os_type" == "Msys" || "$os_type" == "Cygwin" ]]; then
if command -v cygpath >/dev/null 2>&1; then
# 'cygpath' is used because native Windows tools (like nexuslua) don't understand UNIX-style paths (e.g., /tmp/).
# The '--mixed' option generates a more universal Windows path using forward slashes, avoiding backslash parsing issues.
# Note: Some native Windows commands may misinterpret forward slashes, but they're preferable in this context.
path=$(cygpath -m "$path")
else
echo "Error: 'cygpath' is not available but is required when running under $os_type environment." >&2
exit 1
fi
fi
echo "$path"
}
SCRIPT_DIR=$(dirname "$0")
INPUT_DIR="$1"
PLUGIN_ZIP=$(convert_path "$(realpath "$2")")
NEXUSLUA="$(which "$3")"
if [ ! -f "$NEXUSLUA" ]; then
echo "Error: $NEXUSLUA does not exist."
exit 1
fi
if [ ! -d "$INPUT_DIR" ]; then
echo "Error: $INPUT_DIR does not exist or is not a directory."
exit 1
fi
TEMP_PLUGIN_DIR=$(convert_path "$("$SCRIPT_DIR/collect-plugin-files.sh" "$INPUT_DIR")")
# Check if the collect-plugin-files.sh script executed successfully and if the temporary directory exists.
if [ $? -ne 0 ] || [ ! -d "$TEMP_PLUGIN_DIR" ]; then
echo "Error: Failed to collect the plugin files into the temporary directory $TEMP_PLUGIN_DIR"
exit 1
fi
output=$("$NEXUSLUA" -e "print(zip(\"$TEMP_PLUGIN_DIR\", \"$PLUGIN_ZIP\"))")
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Error: Failed to create the plugin ZIP from $TEMP_PLUGIN_DIR with exit code $exit_code"
exit $exit_code
fi
if [ -n "$output" ]; then
echo "$output"
exit 1
fi
rm -rf "$TEMP_PLUGIN_DIR"