blob: a9b236a7c6df62a7d7d84ce6436e6e7901656364 (
plain)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#!/bin/bash
XI_ROOT=$(pwd)
ERROR="\033[0;31m"
INFO="\033[0;34m"
PASS="\033[0;32m"
NEUTRAL="\033[0;33m"
RESET="\033[0m"
MAKEFLAGS="-j11"
alias make="make $MAKEFLAGS"
usage () {
cat << EOF
usage: $0 XIBUILD
EOF
}
extract () {
FILE=$1
echo extracting $FILE
case "${FILE#*.}" in
"tar.gz" )
tar -zxf $FILE
;;
"tar.lz" )
tar --lzip -xf "$FILE"
;;
"zip" )
unzip $FILE
;;
* )
tar -xf $FILE
;;
esac
}
xibuild () {
BUILD_FILE=${@: -1}
cd $XI_ROOT
[[ $# = 0 ]] && usage && return 1
[ ! -f "$BUILD_FILE" ] && echo "$BUILD_FILE not found" && return 1
clean () {
# clean up
rm -rf $PKG_BUILD_DIR
rmdir $XI_ROOT/tmp > /dev/null 2>&1
}
build () {
printf "\tpassing missing build stage..."
}
package () {
echo "Passing missing package stage"
}
source $BUILD_FILE
PKG_NAME=$(basename $BUILD_FILE .xibuild)
LOGFILE=$XI_ROOT/logs/$PKG_NAME.log
PKGS_OUTPUT=$XI_ROOT/xipkgs
PKG_FILE=$PKGS_OUTPUT/$PKG_NAME.xipkg
PKG_BUILD_DIR=$XI_ROOT/tmp/$PKG_NAME
PKG_DEST=$PKG_XI_ROOT/tmp/$PKG_NAME.package
# make sure build dir is clean before starting
rm -rf $PKG_BUILD_DIR
# make the directories
mkdir -p $PKG_BUILD_DIR
mkdir -p $PKG_DEST
mkdir -p $PKGS_OUTPUT
mkdir -p $XI_ROOT/logs
date > $LOGFILE
echo "Build log for $PKG_NAME from $BUILD_FILE\n" >> $LOGFILE
printf "\033[0;36m====> $PKG_NAME.xipkg$RESET\n" | tee -a $LOGFILE
cd $PKG_BUILD_DIR
# fetch, build then package the package
############
# try get the commit hash for the package
if git ls-remote -q $SOURCE &> /dev/null; then
VER_HASH=$(git ls-remote $SOURCE HEAD )
else
VER_HASH=$(curl -Ls $SOURCE | md5sum)
fi
VER_HASH=$(echo $VER_HASH | awk '{ print $1 }')
# If we already have this package, don't waste our time
if [ -f "$PKG_FILE.info" ] && [ -f "$PKG_FILE" ]; then
EXISTING_HASH=$(grep -a "VER_HASH" $PKG_FILE.info | sed "s/VER_HASH=//")
echo "Comparing $EXISTING_HASH to $VER_HASH" >> $LOGFILE
printf "$INFO\tvalidating commit hash...";
if echo "$EXISTING_HASH" | grep -q "$VER_HASH"; then
printf "$NEUTRAL package exists$RESET\n"
return;
else
printf "$NEUTRAL package outdated\n"
fi
fi
printf "$INFO\tfetching package...";
if git ls-remote -q $SOURCE &> /dev/null; then
git clone $SOURCE . >> $LOGFILE 2>&1 && printf "$PASS fetched $(du -sh $PKG_BUILD_DIR | awk '{ print $1 }') source\n" || return 1;
else
DOWNLOADED=$(basename $SOURCE)
curl -Ls $SOURCE > $DOWNLOADED
extract $DOWNLOADED >> $LOGFILE 2>&1 && printf "$PASS fetched $(du -sh $PKG_BUILD_DIR | awk '{ print $1 }') source\n" || return 1;
cd $(ls -d */)
fi
printf "$INFO\tbuilding package...";
build >> $LOGFILE 2>&1 && printf "$PASS built\n" || return 1;
printf "\033[0;34m\tpackaging package...\033[0m";
package >> $LOGFILE 2>&1 && printf "$PASS packaged\n" || return 1;
# go back to root, make things easier
cd $XI_ROOT
printf "$INFO\tarchiving package...";
tar -C $PKG_DEST -czf $PKG_FILE ./ >> $LOGFILE 2>&1 && printf "$PASS archived to $(du -sh $PKG_FILE | awk '{ print $1 }')\n" || return 1;
# create info file
printf "$INFO\tcreating xipkg.info...";
PKG_INFO=$PKGS_OUTPUT/$PKG_NAME.xipkg.info
echo "" > $PKG_INFO
echo "NAME=$PKG_NAME" >> $PKG_INFO
echo "DESCRIPTION=$DESC" >> $PKG_INFO
echo "PKG_FILE=$PKG_NAME.xipkg" >> $PKG_INFO
echo "CHECKSUM=$(md5sum $PKG_FILE | awk '{ print $1 }')" >> $PKG_INFO
echo "VER_HASH=$VER_HASH" >> $PKG_INFO
echo "SOURCE=$SOURCE" >> $PKG_INFO
echo "DATE=$(date)" >> $PKG_INFO
echo "DEPS=(${DEPS[*]})" >> $PKG_INFO
printf "$INFOsigning...";
# sign the package
PRIV_KEY=$XI_ROOT/keychain/xi.pem
PUB_KEY=$XI_ROOT/keychain/xi.pub
if [ -f "$PRIV_KEY" ]; then
echo "SIGNATURE=" >> $PKG_INFO
openssl dgst -sign $PRIV_KEY $PKG_FILE >> $PKG_INFO
else
echo "SIGNATURE=">> $PKG_INFO
echo "unsigned">> $PKG_INFO
>&2 printf "$ERROR WARNING! No private key: unsigned packages!\n"
fi
printf "$PASS signed\n";
printf "$PASS successfully built $PKG_NAME to $(basename $PKG_FILE)$RESET\n"
clean
return 0
}
build-all () {
FILES=$@
for BUILD_FILE in $FILES; do
xibuild $BUILD_FILE && printf "$RESET" || printf "$ERROR error! See log$RESET\n"
cd $XI_ROOT
done
}
if [ $# -gt 0 ]; then
build-all $@ | tee -a xibuild.log
fi
|