Syncing with current state

This commit is contained in:
DarkFeather 2019-04-08 05:05:08 -05:00
parent a5b28c39ac
commit 21448e5c01
4 changed files with 70 additions and 39 deletions

View File

@ -1,40 +1,39 @@
INSTALLDIR = ${pkgdir}/usr/local/bin
INSTALLLIST = ./maat-builder
OWNER=root
PERMS=0755
installDir = ${pkgdir}/usr/local/bin
list = ./maat-builder
systemdList = ./maat-builder.timer ./maat-builder.service
serverRoot = /srv/maat/
owner=root
perms=0755
compile: /bin/bash
@echo Nothing to compile.
install: ${INSTALLLIST}
mkdir -p ${INSTALLDIR}
mkdir -p /srv/maat/src
mkdir -p /srv/maat/pkg
mkdir -p /srv/maat/web
for i in ${INSTALLLIST}; do install -m ${PERMS} -o ${OWNER} $$i ${INSTALLDIR}; done
install: ${list}
mkdir -p ${installDir}
mkdir -p ${pkgdir}${serverRoot}/src
mkdir -p ${pkgdir}${serverRoot}/pkg
for i in ${list}; do install -m ${perms} -o ${owner} $$i ${installDir}; done
for i in ${systemdList}; do install -m 0644 -o root $$i ${pkgdir}/usr/lib/systemd/system; done
clean:
cat .gitignore | xargs rm -Rf
uninstall:
for i in ${INSTALLLIST}; do rm -Rf ${INSTALLDIR}/$$i; done
for i in ${list}; do rm -Rf ${installDir}/$$i; done
for i in ${systemdList}; do rm /usr/lib/systemd/system/$$i; done
rmdir -p ${pkgdir}${serverRoot}/src
rmdir -p ${pkgdir}${serverRoot}/pkg
test:
./maat-builder -T
test-run:
bash ./maat -v -d ./repo -b ./build -w ./web -c /dev/null
./maat-builder -T -U $$USER
diff:
for i in ${list}; do if [ -f ${INSTALLDIR}/$$i ]; then diff "$$i" "${INSTALLDIR}/$$i"; fi done
for i in ${list}; do if [ -f ${installDir}/$$i ]; then diff "$$i" "${installDir}/$$i"; fi done
reverse:
for i in ${list}; do if [ -f ${INSTALLDIR}/$$i ]; then cp "${INSTALLDIR}/$$i" "$$i"; fi done
for i in ${list}; do if [ -f ${installDir}/$$i ]; then cp "${installDir}/$$i" "$$i"; fi done
checkperm:
for i in ${list}; do chown ${OWNER}: "${INSTALLDIR}/$$i"; chmod ${PERMS} "${INSTALLDIR}/$$i"; done
chmod 0644 ${SUPPORTDIR}/maat.html
chown ${OWNER}: ${SUPPORTDIR}/maat.html
chmod 0644 ${pkgdir}/etc/lighttpd/conf.d/maat.conf
chown http: ${pkgdir}/etc/lighttpd/conf.d/maat.conf
chown -R ${owner}: ${pkgdir}${serverRoot}/src
chown -R ${owner}: ${pkgdir}${serverRoot}/pkg
for i in ${list}; do chown -R ${owner}: "${installDir}/$$i"; chmod ${perms} "${installDir}/$$i"; done

View File

@ -12,17 +12,19 @@
#
### Printing defaults
passCell="<td style='color:green;'>PASS<td>";
failCell="<td style='color:red;'>FAIL<td>";
warnCell="<td style='color:yellow;'>N/A<td>";
passCell="<td style='color:green;'>PASS</td>";
failCell="<td style='color:red;'>FAIL</td>";
warnCell="<td style='color:yellow;'>N/A</td>";
### Add helptext.
function Usage() {
echo "Usage: $0"
echo " $0 [ -b basedir ] [ -c AUR.git.list ] [ -T ] [ -u https://base.url/ ]"
echo " $0 [ -b basedir ] [ -c AUR.git.list ] [ -u https://base.url/ ]"
echo " $0 [ -T ]"
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 "By default, $0 uses the depriv user to build packages. Override with -U"
}
### Put the initial content in the webfile
@ -32,17 +34,17 @@ function SeedWebFile() {
### Update the webfile to close up table tags and add stats.
function UpdateWebFile() {
sed -i "s#WEBSTATSGOHERE#<p>These are the AniNIX testing results. We found $passcount passing and $failcount failing packages, with $warncount warnings. It took $runtime seconds to finish.</p><table><tr><th>Package</th><th>Testing Status</th><th>Build Status</th><th>Latest Build</th><th>Time of Run</th></tr>#" "$webfile"
sed -i "s#WEBSTATSGOHERE#<p>These are the AniNIX testing results. We found $passcount passing and $failcount failing packages, with $warncount warnings. It took $runtime seconds to finish.</p><table style='text-align: left;'><tr><th>Package</th><th>Testing Status</th><th>Build Status</th><th>Latest Build</th><th>Time of Run</th></tr>#" "$webfile"
echo '</table></body></html>' >> "$webfile"
}
### Build the package. Assumes a PKGBUILD is resent in the repo.
function BuildPackage() {
makepkg &>/dev/null
timeout --preserve-status 30s sudo -u "$user" makepkg -s --noconfirm &>/dev/null
if [ $? -ne 0 ]; then
# Build failed.
printf "$failCell""$warnCell" >> "$webfile"
printf "$failCell""$warnCell" >> "$webfile"
else
# Build passed.
printf "$passCell""<td>" >> "$webfile"
@ -59,21 +61,25 @@ function BuildRepo() {
repo="$1"
cd "$srcdir"
if [ -z "$repo" ]; then continue; fi
repodir="$(echo $repo | rev | cut -f 1 -d '/' | rev | sed 's/\.git$//')"
repodir="$(basename "$repo" | sed 's/\.git$//')"
#Set up the checkout
if [ ! -d "$repodir" ]; then
git clone "$repo"
fi
chown -R "$user": "$repodir"
cd "$repodir"
git pull
output="$(git pull 2>&1)"
if [ $? -eq 0 ] && [ -n "$incremental" ] && [[ "$output" =~ Already\ up\ to\ date. ]] && [ -f *.tar.xz ]; then
return;
fi
# 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 '<tr><td>'"<a href='$repo'>$repodir</a> -- $pkgbuild"'</td>' >> "$webfile"
printf '<tr style="border: 1px solid #FFF;"><td>'"<a href='$repo'>$repodir</a> -- $pkgbuild"'</td>' >> "$webfile"
if [ -f Makefile ] && [ `egrep -c '^test:' Makefile` -ge 1 ]; then
# Check test status.
timeout --preserve-status 30s /bin/bash -c 'make test' &>/dev/null
timeout --preserve-status 30s /bin/bash -c "sudo -u \'$user\' make test" &>/dev/null
if [ $? -ne 0 ]; then
# Testing failed.
printf "$failCell""$warnCell""$warnCell" >> "$webfile"
@ -88,7 +94,7 @@ function BuildRepo() {
BuildPackage
fi
# Timestamp
printf "<td>$(date +%F-%R)</td>\n" >> "$webfile"
printf "<td>$(date +%F-%R)</td></tr>\n" >> "$webfile"
cd "$cwd"
if [ ! -z "$testing" ]; then break; fi
done
@ -108,19 +114,23 @@ aurconf='/usr/local/etc/Maat/aur.list'
homedir=/srv/maat/
unset upload
unset testing
unset incremental
user="depriv"
# Stat tracking
starttime=`date +%s`
# Parse arguments
while getopts 'b:c:hl:Tu:Uv' OPTION; do
while getopts 'b:c:hil:Tu:U:v' OPTION; do
case "${OPTION}" in
b) homedir="${OPTARG}" ;;
c) aurconf="${OPTARG}" ;;
h) Usage; exit 0 ;;
i) incremental=1 ;;
l) cmdstring="$0"; for arg in $@; do if [ "$arg" != "-l" ] && [ "$arg" != "${OPTARG}" ]; then cmdstring="$cmdstring \"${arg}\""; fi; done; exec /bin/bash -c "$0 $cmdstring | tee -a \"${OPTARG}\"" ;;
T) homedir='.'; testing=1 ;;
u) baseurl="${OPTARG}" ;;
U) user="${OPTARG}" ;;
v) set -x ;;
*) usage; exit 1 ;;
esac
@ -132,8 +142,8 @@ if [ $( echo "$homedir" | egrep -c '^/') -ne 1 ]; then
fi
srcdir="${homedir}/src" && mkdir -p "${srcdir}"
pkgdir="${homedir}/pkg" && mkdir -p "${pkgdir}"
webdir="${homedir}/web" && mkdir -p "${webdir}"
webfile="$webdir"/index.php
webdir="$pkgdir"
webfile="$webdir"/index.html
# For each repo listed at the CGIT URL and conf file
cwd="$(pwd)"
@ -143,7 +153,7 @@ for aninixrepo in `wget -q -O - "$baseurl" | grep toplevel-repo | cut -f 4 -d \'
if [ ! -z "$testing" ]; then break; fi
done
for repo in `cat "$aurconf"`; do
BuildRepo repo;
BuildRepo "$repo";
if [ ! -z "$testing" ]; then break; fi
done

12
maat-builder.service Normal file
View File

@ -0,0 +1,12 @@
[Unit]
Description=AniNIX::Maat \\ Builder Service
ConditionPathExists=|!/srv/maat/pkg/.lock
[Service]
ExecStartPre=/usr/sbin/mkdir /srv/maat/pkg/.lock
ExecStart=/usr/local/bin/maat-builder
ExecStopPost=/usr/sbin/rmdir /srv/maat/pkg/.lock
Type=oneshot
RemainAfterExit=no
User=root
Group=root

10
maat-builder.timer Normal file
View File

@ -0,0 +1,10 @@
[Unit]
Description=AniNIX::Maat \\ Builder Timer
[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true
[Install]
WantedBy=timers.target