-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_site.sh
executable file
·69 lines (56 loc) · 1.89 KB
/
build_site.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
#!/bin/bash
# AGPLv3.0
# https://github.com/stashapp/CommunityScripts/blob/main/LICENSE
# builds a repository of themes
# outputs to _site with the following structure:
# index.yml
# <theme_id>.zip
# Each zip file contains the theme.yml file and any other files in the same directory
outdir="$1"
if [ -z "$outdir" ]; then
outdir="_site"
fi
rm -rf "$outdir"
mkdir -p "$outdir"
buildTheme()
{
f=$1
# get the theme id from the directory
dir=$(dirname "$f")
theme_id=$(basename "$f" .yml)
echo "Processing $theme_id"
# create a directory for the version
version=$(git log -n 1 --pretty=format:%h -- "$dir"/*)
updated=$(TZ=UTC0 git log -n 1 --date="format-local:%F %T" --pretty=format:%ad -- "$dir"/*)
# create the zip file
# copy other files
zipfile=$(realpath "$outdir/$theme_id.zip")
pushd "$dir" > /dev/null
zip -r "$zipfile" . > /dev/null
popd > /dev/null
name=$(grep "^name:" "$f" | head -n 1 | cut -d' ' -f2- | sed -e 's/\r//' -e 's/^"\(.*\)"$/\1/')
description=$(grep "^description:" "$f" | head -n 1 | cut -d' ' -f2- | sed -e 's/\r//' -e 's/^"\(.*\)"$/\1/')
ymlVersion=$(grep "^version:" "$f" | head -n 1 | cut -d' ' -f2- | sed -e 's/\r//' -e 's/^"\(.*\)"$/\1/')
version="$ymlVersion-$version"
dep=$(grep "^# requires:" "$f" | cut -c 12- | sed -e 's/\r//')
# write to spec index
echo "- id: $theme_id
name: $name
metadata:
description: $description
version: $version
date: $updated
path: $theme_id.zip
sha256: $(sha256sum "$zipfile" | cut -d' ' -f1)" >> "$outdir"/index.yml
# handle dependencies
if [ ! -z "$dep" ]; then
echo " requires:" >> "$outdir"/index.yml
for d in ${dep//,/ }; do
echo " - $d" >> "$outdir"/index.yml
done
fi
echo "" >> "$outdir"/index.yml
}
find ./themes -mindepth 1 -name *.yml | while read file; do
buildTheme "$file"
done