#!/bin/bash
XIBUILD=./xibuild
fetch () {
git clone https://git.davidovski.xyz/xilinux/buildfiles
mkdir dist
}
build () {
REPOS_INDEX=dist/repo/index.html
rm $REPOS_INDEX
echo-head "repo" >> $REPOS_INDEX
echo "
repo
" >> $REPOS_INDEX
for REPO in $(du -h buildfiles/repo/* | awk '{print $2}' | sort -r ); do
REPO_NAME=$(echo $REPO | cut -d"/" -f2-)
REPO_INDEX=dist/$REPO_NAME/index.html
REPO_LIST_OLD=dist/$REPO_NAME/packages.txt
REPO_LIST=dist/$REPO_NAME/packages.list
touch $REPO_INDEX
touch $REPO_LIST_OLD
touch $REPO_LIST
start-index $REPO_NAME $REPO_INDEX
printf "" > xibuild.report.log
for BUILD_FILE in $REPO/*.xibuild; do
if [ ${#ONLY[@]} == 0 ] || ( echo ${ONLY[*]} | grep -q $(basename -s .xibuild $BUILD_FILE)); then
DEST=dist/$REPO_NAME
$XIBUILD -o $DEST $BUILD_FILE
extend-index $BUILD_FILE $REPO_INDEX
fi
done;
rm xibuild.report.log
conclude-index $REPO_INDEX
generate-package-list
add-additional
echo "$REPO_NAME
" >> $REPOS_INDEX
echo "package count: $(ls dist/$REPO_NAME/*.xipkg | wc -l)
" >> $REPOS_INDEX
done;
echo ""
}
echo-head () {
echo "
$1
"
}
start-index() {
echo-head "packages for $1" > $2
echo "
Packages in $1
name |
xibuild |
build log |
description |
file |
info file |
" >> $2
}
extend-index () {
PKG_NAME=$(basename $1 .xibuild)
DESC=$(grep $PKG_NAME xibuild.report.log | cut -d" " -f3-)
COLOR="none"
if grep $PKG_NAME xibuild.report.log | grep -q new; then
COLOR="pass"
fi
if grep $PKG_NAME xibuild.report.log | grep -q fail; then
if [ -f dist/$REPO_NAME/$PKG_NAME.xipkg ]; then
COLOR="warning"
else
COLOR="fail"
fi
fi
echo "
$PKG_NAME |
src |
log |
$DESC |
$PKG_NAME.xipkg |
.info |
" >> $2
}
conclude-index () {
echo "
Latest builds: $(date)
Legend:
- build skipped; no updates
- build failed; no previous version
- build failed; previous version exists
- build passed: new update
" >> $1
}
generate-package-list () {
cd dist/$REPO_NAME
ls -1 *.xipkg.info > packages.txt
echo "" > packages.list
for file in $(ls -1 *.xipkg); do
echo "$file $(md5sum $file | awk '{print $1}') $(du -s $file | awk '{print $1}') $(gzip -cd $file | tar -tvv | grep -c ^-)" >> packages.list
done;
cd -
}
add-additional () {
# move logs and sources
mkdir -pv dist/$REPO_NAME/logs
mv logs/* dist/$REPO_NAME/logs
mkdir -p dist/$REPO_NAME/src
mv $REPO/* dist/$REPO_NAME/src/
# add key for whole repo
mkdir dist/keychain
cp keychain/keys.list dist/keychain/
cp keychain/*.pub dist/keychain/
}
clean () {
rm -rf buildfiles
rm -rf logs
rm -rf tmp
rm -rf xibuild.log
}
sync () {
for i in $@; do
[[ $# = 0 ]] || rsync -Lta --no-perms --no-owner --no-group --delete -z -e ssh ./dist/ $i
done;
}
index () {
INDEX=dist/index.html
rm $INDEX
echo-head "xilinux" >> $INDEX
cat index.html >> $INDEX
}
# update the repository
clean
fetch
build
index
clean