#!/bin/bash
# File: maat-builder
#
# Description: This file allows a Maat host to build source packages
# and optionally upload to the AniNIX/Foundation
#
# Package: Maat
# Copyright: WTFPL
#
# Author: DarkFeather
#
# Arch keys to look for
pkgExt=".pkg.tar.zst"
deprivuser="maat"
### Printing defaults
passCell="
PASS
";
failCell="
FAIL
";
warnCell="
N/A
";
tableHead="
\n
Package
Testing Status
Build Status
Latest Build
Time and Log of Run
";
### Add helptext.
function Usage() {
echo "Usage: $0"
echo " $0 [ -b basedir ] [ -c AUR.git.list ] [ -T ] [ -u https://base.url/ ]"
echo " $0 -h"
echo
echo 'Add -v to increase verbosity or -h for help. Add the -l LOGFILE flags to log to a file'
echo 'Add the -r REPOCMD, -C make-package-command, -p PKGBUILDName, -t test-command, and'
echo 'the -e package-extension flags for compatibility with non-ArchLinux repos.'
}
### Put the initial content in the webfile
function SeedWebFile() {
printf '\n\nAniNIX/Maat -- Build Results\n\n\n\n\n\n\n\n
AniNIX/Maat -- Build Status
\nWEBSTATSGOHERE\n
AnINIX Packages
\n
These are packages written by the AniNIX. Their source is in AniNIX/Foundation.
\n' > "$webfile"
printf "$tableHead" >> "$webfile"
}
### Update the webfile to close up table tags and add stats.
function UpdateWebFile() {
sed -i "s#WEBSTATSGOHERE#
These are the AniNIX testing results. We found $passcount passing and $failcount failing packages, with $warncount warnings. It took $runtime seconds to finish.
#" "$webfile"
printf '
\n\n\n' >> "$webfile"
mv "$webfile" "$webfilefinal"
}
### Build the package. Assumes a PKGBUILD is resent in the repo.
# param suffix: where to store the final package
function BuildPackage() {
suffix="$1"
[ `pgrep -afc pacman` -eq 0 ] && rm -Rf /var/lib/pacman/db.lck
nice -n 10 timeout --preserve-status 60m sudo -u "$deprivuser" /usr/sbin/makepkg -sfc --noconfirm --sign &>> "$pkgdir"/"$repodir".txt
if [ $? -ne 0 ]; then
# Build failed.
printf "$failCell""$warnCell" >> "$webfile"
else
# Build passed.
printf "$passCell""
" >> "$webfile"
# List passing versions
for pkg in `find . -type f | grep -E "${pkgExt}""\$"`; do
printf "$pkg " >> "$webfile"
pkgname="$(basename "$pkg" | cut -f 1 -d '.' | sed 's/-[[:digit:]]\+$//')"
find "${pkgdir}/${suffix}/" -name "${pkgname}-[0-9]*" -exec rm {} \;
mv "$pkg" "$pkgdir"/"$suffix";
mv "$pkg"".sig" "$pkgdir"/"$suffix";
done
printf "
" >> "$webfile"
fi
}
### Build the repo passed as argument
# param repo: the repo to build.
# param suffix: where to store the final package
function BuildRepo() {
repo="$1"
suffix="$2"
cd "$srcdir"
if [ -z "$repo" ]; then continue; fi
repodir="$(basename "$repo" | sed 's/\.git$//')"
#Set up the checkout
if [ ! -d "$repodir" ]; then
git clone "$repo"
fi
cd "$repodir"
git clean -fd
git clean -fx
output="$(git pull 2>&1)"
if [ -n "$incremental" ] && [ $( echo "$output" | grep -c 'Already up to date.' ) -eq 1 ]; then
return;
fi
chown -R "$deprivuser": .
echo "$output" > "$pkgdir"/"$repodir".txt
# Find the PKGBuilds in the repo
for pkgbuild in `find . -type f -name PKGBUILD`; do
cd "$(dirname "$pkgbuild")"
# Tell the status file about it.
printf '