summaryrefslogtreecommitdiff
path: root/xibuild
blob: a78235efc3d151870b2a226669d2b4e266c45431 (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
#!/bin/bash

usage () {
 cat << EOF
usage: $0 XIBUILD 
EOF
}

BUILD_FILE=${@: -1}

[[ $# = 0 ]] && usage && exit 1
[ -f "$FILE" ] && echo "$BUILD_FILE not found" && exit 1

source $BUILD_FILE

PKG_NAME=$(basename $BUILD_FILE .xibuild)

XI_ROOT=$(pwd)
PKGS_OUTPUT=$XI_ROOT/xipackages

PKG_BUILD_DIR=$XI_ROOT/tmp/$PKG_NAME
PKG_DEST=$PKG_BUILD_DIR/package

# make the directories
mkdir -p $PKG_DEST
cd $PKG_BUILD_DIR

# fetch, build then package the package
fetch
build
package


# go back to root, make things easier
cd $XI_ROOT

# bundle the package to a targz in the output dir
mkdir -p $PKGS_OUTPUT

PKG_FILE=$PKGS_OUTPUT/$PKG_NAME.xipkg

tar -C $PKG_BUILD_DIR/package -czf $PKG_FILE ./

# create info file
PKG_INFO=$PKGS_OUTPUT/$PKG_NAME.xipkg.info

echo "" > $PKG_INFO
echo "NAME=$PKG_NAME" >> $PKG_INFO
echo "PKG_FILE=$PKG_NAME.xipkg" >> $PKG_INFO
echo "CHECKSUM=$(md5sum $PKG_FILE | awk '{ print $1 }')" >> $PKG_INFO
echo "DATE=$(date)" >> $PKG_INFO

# 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 echo "WARNING! no private key: unsigned packages!"
fi
# clean up
rm -rf $PKG_BUILD_DIR
rmdir $XI_ROOT/tmp