-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregen.sh
executable file
·84 lines (69 loc) · 2.06 KB
/
regen.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
#!/bin/sh
# This script generates a manifest file for a ComputerCraft
# computer to read, so it knows what to download.
if [ -z "$MANIFEST" ] ; then
MANIFEST=manifest
fi
if [ -n "$(git status --porcelain)" ] ; then
if [ -z "$ALLOW_DIRTY" ] ; then
echo "Working tree dirty. Exiting."
exit 1
fi
fi
# List of path patterns we want to include.
INCLUDE_PATHS=""
TMP_INCLUDE_PATHS="$(mktemp)"
cat - <<EOF >> "$TMP_INCLUDE_PATHS"
./startup.lua
./etc/*
./bin/*
EOF
FIRST="1"
while read line ; do
if [ -n "$FIRST" ] ; then
INCLUDE_PATHS="-path '$line'"
FIRST=""
else
INCLUDE_PATHS="$INCLUDE_PATHS -or -path '$line'"
fi
done < "$TMP_INCLUDE_PATHS"
rm "$TMP_INCLUDE_PATHS"
IGNORE_PATHS=""
while read line ; do
IGNORE_PATHS="$IGNORE_PATHS -not -path '$line'"
done < .gitignore
CMD="find . -type f $INCLUDE_PATHS $IGNORE_PATHS"
CMD_TMP="$(mktemp)"
eval $CMD | while read line ; do
sha1sum "$line" >> "$CMD_TMP"
done
echo "{" > "$MANIFEST"
# We include this in the manifest so we can, in theory, obtain a manifest file by whatever means,
# and use it to get a perfect copy of the repository as it was when the file hashes it lists were correct.
COMMIT="$(git rev-parse HEAD)"
echo " \"COMMIT\": \"$COMMIT\"" >> "$MANIFEST"
# The `HTTP_ROOT` key is allowed to be any HTTP server that can serve the files in the repository
# per `/$COMMIT/path/from/root/of/repository`
echo " ,\"HTTP_ROOT\": \"https://raw.githubusercontent.com/Monadic-Cat/mc-cc/\"" >> "$MANIFEST"
echo " ,\"files\": [" >> "$MANIFEST"
SEP=""
while read line ; do
FIRST=""
SECOND=""
for word in $line ; do
if [ -z "$FIRST" ] ; then
FIRST="$word"
elif [ -z "$SECOND" ] ; then
SECOND="$word"
else
echo "wtf sha1sum said more than 2 words for a line"
echo "Line: $line"
exit 1
fi
done
echo " $SEP{\"name\": \"$SECOND\", \"hash\": \"$FIRST\" }" >> "$MANIFEST"
SEP=","
done < "$CMD_TMP"
echo " ]" >> "$MANIFEST"
echo "}" >> "$MANIFEST"
rm "$CMD_TMP"