-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild
executable file
·171 lines (144 loc) · 4.18 KB
/
build
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
#!/bin/bash -e
# Build script for Xor's Models resource pack
# Yeah, my pack is so cool it has a build script.
# Now with minifying json!
TOP_DIR=`pwd`
ZIPNAME="Xor's 1.8 Models.zip"
WORK_DIR='work'
COPY_DIR="$TOP_DIR"
ZIPDIR="$TOP_DIR"
BUILD_ARGS="$@"
while [[ $# > 0 ]]; do
key="$1"
case $key in
-b|--no-block-items)
NOBLOCKITEMS='yes'
;;
-o|--output)
ZIPNAME="$2"
if [[ "$ZIPNAME" != *.zip ]]; then
ZIPNAME="$ZIPNAME".zip
fi
if [[ `dirname "$ZIPNAME"` != '.' ]]; then
ZIPDIR=`dirname "$ZIPNAME"`
fi;
ZIPNAME=`basename "$ZIPNAME"`
;;
-m|--no-minify)
NOMINIFY='yes'
;;
-w|--preserve-work-dir)
PRESERVEWORKDIR='yes'
;;
-u|--collect-cruft)
COLLECTCRUFT='yes'
;;
-v|--verbose)
VERBOSITY='yes'
;;
-h|--help|help)
echo "Buildscript for Xor's 1.8 Models "
echo " at commit "`git --no-pager show -q --oneline`
echo "Compile settings:"
echo " -b --no-block-items : removes block item models"
echo " -m --no-minify : don't minify json"
echo " -o --output : set the output file"
echo " -w --preserve-work-dir : don't kill the work dir when we're done"
echo " -u --collect-cruft : run collectCruft in the workdir"
echo " -v --verbose : verbose out"
echo " -h --help : print this message"
exit 0
;;
*) ;;
esac
shift
done
echo 'Preparing workspace...'
rm -rf $WORK_DIR
mkdir $WORK_DIR
cp -r assets $WORK_DIR/assets
cp pack.png pack.mcmeta LICENSE.md $WORK_DIR
cd $WORK_DIR
if [[ -n "$COLLECTCRUFT" ]]; then
echo 'Collecting cruft...'
../collectCruft
fi
if [[ -n "$NOBLOCKITEMS" ]]
then
echo "Removing block items..."
cd assets/minecraft/models/item
for f in `cat "$TOP_DIR"/blockfiles.txt`; do
if [[ -n "$VERBOSITY" ]]; then
echo Removing: $f
fi
rm -f $f # 2> /dev/null
done
cd "$TOP_DIR"/"$WORK_DIR"
fi
if [[ -z "$NOMINIFY" ]]; then
echo 'Minifying json...'
for f in `find assets -name \*.json -print`
do
if [[ -n "$VERBOSITY" ]]; then
echo Minifying: $f
fi
sed -nf "$TOP_DIR"/comments $f > $f'.tmp'
cat $f'.tmp' > $f 2> /dev/null
sed /\"comment\":/d $f > $f'.tmp'
cat $f'.tmp' > $f 2> /dev/null
tr -d ' \n\t\r' < $f > $f'.tmp' 2> /dev/null
cat $f'.tmp' > $f 2> /dev/null
rm $f'.tmp' 2> /dev/null
done
for f in `find assets -name \*.mcmeta -print`
do
if [[ -n "$VERBOSITY" ]]; then
echo Minifying: $f
fi
sed -nf "$TOP_DIR"/comments $f > $f'.tmp'
cat $f'.tmp' > $f 2> /dev/null
tr -d ' \n\t\r' < $f > $f'.tmp' 2> /dev/null
cat $f'.tmp' > $f 2> /dev/null
rm $f'.tmp' 2> /dev/null
done
fi
cd ..
# # aux build info to pack into the zip
echo "Writting stuff..."
BUILDINFO="$WORK_DIR/buildinfo"
if [[ -e $BUILDINFO ]]; then
rm $BUILDINFO
fi
echo "-- This is a bunch of random information about the build, you probably don't care about it." > $BUILDINFO
# git info
git show -q >> $BUILDINFO
echo "" >> $BUILDINFO
# when
echo 'Built on '`date` >> $BUILDINFO
# build options
echo `if [[ -n "$NOBLOCKITEMS" ]]; then echo "Without"; else echo "With"; fi`' block items.' >> $BUILDINFO
if [[ -n "$NOMINIFY" ]]; then echo "Unminified." >> $BUILDINFO; fi
echo "Build command: $0 $BUILD_ARGS" >> $BUILDINFO
# jenkins
if [[ -n "$BUILD_TAG" ]]; then
echo "$BUILD_TAG" >> $BUILDINFO
echo "Triggered by commit $GIT_COMMIT" >> $BUILDINFO
fi
# final size of workspace
echo 'Workspace size: '`du -hs .` >> $BUILDINFO
# build os
echo 'Built on '`uname -rs` >> $BUILDINFO
echo "--" >> $BUILDINFO
# #
echo 'Buiding...'
cd $WORK_DIR
zip -qr "$ZIPNAME" *
cd ..
if [[ ! -d "$ZIPDIR" ]]; then
mkdir "$ZIPDIR"
fi
mv "$WORK_DIR"/"$ZIPNAME" "$ZIPDIR"
echo 'Cleaning up...'
if [[ -z $PRESERVEWORKDIR ]]; then
rm -rf "$WORK_DIR"
fi