This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgenerate-index.sh
executable file
·48 lines (42 loc) · 1.94 KB
/
generate-index.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
#!/bin/bash
base_url="https://version-fox.github.io/version-fox-plugins"
echo "[" > index.json
generate_list() {
for dir in "$1"/*; do
if [ -d "$dir" ]; then
echo "{" >> index.json
echo "\"category\": \"$(basename "$dir")\"," >> index.json
count=$(find "$dir" -type f -name "*.lua" | wc -l)
echo "\"count\": \"$count\"," >> index.json
echo "\"files\": [" >> index.json
for file in "$dir"/*.lua; do
if [ -f "$file" ]; then
filename=$(basename "$file" .lua)
sha256=$(sha256sum "$file" | awk '{ print $1 }')
plugin_name=$(perl -ne 'if(/name\s*=\s*"([^"]*)"/){print $1;}' $file)
plugin_author=$(perl -ne 'if(/author\s*=\s*"([^"]*)"/){print $1;}' $file)
plugin_version=$(perl -ne 'if(/version\s*=\s*"([^"]*)"/){print $1;}' $file)
plugin_desc=$(perl -ne 'if(/description\s*=\s*"([^"]*)"/){print $1;}' $file)
url="$base_url/$(basename "$dir")/$filename.lua"
echo "{" >> index.json
echo "\"name\": \"$filename\"," >> index.json
echo "\"url\": \"$url\"," >> index.json
echo "\"sha256\": \"$sha256\"," >> index.json
echo "\"plugin_name\": \"$plugin_name\"," >> index.json
echo "\"plugin_author\": \"$plugin_author\"," >> index.json
echo "\"plugin_version\": \"$plugin_version\"," >> index.json
echo "\"plugin_desc\": \"$plugin_desc\"" >> index.json
echo "}," >> index.json
fi
done
# Remove the last comma
sed -i '$ s/,$//' index.json
echo "]" >> index.json
echo "}," >> index.json
fi
done
}
generate_list .
# Remove the last comma
sed -i '$ s/,$//' index.json
echo "]" >> index.json