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 installDir = ${pkgdir}/usr/local/bin
INSTALLLIST = ./maat-builder list = ./maat-builder
OWNER=root systemdList = ./maat-builder.timer ./maat-builder.service
PERMS=0755 serverRoot = /srv/maat/
owner=root
perms=0755
compile: /bin/bash compile: /bin/bash
@echo Nothing to compile. @echo Nothing to compile.
install: ${INSTALLLIST} install: ${list}
mkdir -p ${INSTALLDIR} mkdir -p ${installDir}
mkdir -p /srv/maat/src mkdir -p ${pkgdir}${serverRoot}/src
mkdir -p /srv/maat/pkg mkdir -p ${pkgdir}${serverRoot}/pkg
mkdir -p /srv/maat/web for i in ${list}; do install -m ${perms} -o ${owner} $$i ${installDir}; done
for i in ${INSTALLLIST}; 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: clean:
cat .gitignore | xargs rm -Rf cat .gitignore | xargs rm -Rf
uninstall: 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: test:
./maat-builder -T ./maat-builder -T -U $$USER
test-run:
bash ./maat -v -d ./repo -b ./build -w ./web -c /dev/null
diff: 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: 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: checkperm:
for i in ${list}; do chown ${OWNER}: "${INSTALLDIR}/$$i"; chmod ${PERMS} "${INSTALLDIR}/$$i"; done chown -R ${owner}: ${pkgdir}${serverRoot}/src
chmod 0644 ${SUPPORTDIR}/maat.html chown -R ${owner}: ${pkgdir}${serverRoot}/pkg
chown ${OWNER}: ${SUPPORTDIR}/maat.html for i in ${list}; do chown -R ${owner}: "${installDir}/$$i"; chmod ${perms} "${installDir}/$$i"; done
chmod 0644 ${pkgdir}/etc/lighttpd/conf.d/maat.conf
chown http: ${pkgdir}/etc/lighttpd/conf.d/maat.conf

View File

@ -12,17 +12,19 @@
# #
### Printing defaults ### Printing defaults
passCell="<td style='color:green;'>PASS<td>"; passCell="<td style='color:green;'>PASS</td>";
failCell="<td style='color:red;'>FAIL<td>"; failCell="<td style='color:red;'>FAIL</td>";
warnCell="<td style='color:yellow;'>N/A<td>"; warnCell="<td style='color:yellow;'>N/A</td>";
### Add helptext. ### Add helptext.
function Usage() { function Usage() {
echo "Usage: $0" 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 " $0 -h"
echo echo
echo 'Add -v to increase verbosity or -h for help. Add the -l LOGFILE flags to log to a file' 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 ### Put the initial content in the webfile
@ -32,14 +34,14 @@ function SeedWebFile() {
### Update the webfile to close up table tags and add stats. ### Update the webfile to close up table tags and add stats.
function UpdateWebFile() { 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" echo '</table></body></html>' >> "$webfile"
} }
### Build the package. Assumes a PKGBUILD is resent in the repo. ### Build the package. Assumes a PKGBUILD is resent in the repo.
function BuildPackage() { function BuildPackage() {
makepkg &>/dev/null timeout --preserve-status 30s sudo -u "$user" makepkg -s --noconfirm &>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# Build failed. # Build failed.
printf "$failCell""$warnCell" >> "$webfile" printf "$failCell""$warnCell" >> "$webfile"
@ -59,21 +61,25 @@ function BuildRepo() {
repo="$1" repo="$1"
cd "$srcdir" cd "$srcdir"
if [ -z "$repo" ]; then continue; fi 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 #Set up the checkout
if [ ! -d "$repodir" ]; then if [ ! -d "$repodir" ]; then
git clone "$repo" git clone "$repo"
fi fi
chown -R "$user": "$repodir"
cd "$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 # Find the PKGBuilds in the repo
for pkgbuild in `find . -type f -name PKGBUILD`; do for pkgbuild in `find . -type f -name PKGBUILD`; do
cd "$(dirname "$pkgbuild")" cd "$(dirname "$pkgbuild")"
# Tell the status file about it. # 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 if [ -f Makefile ] && [ `egrep -c '^test:' Makefile` -ge 1 ]; then
# Check test status. # 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 if [ $? -ne 0 ]; then
# Testing failed. # Testing failed.
printf "$failCell""$warnCell""$warnCell" >> "$webfile" printf "$failCell""$warnCell""$warnCell" >> "$webfile"
@ -88,7 +94,7 @@ function BuildRepo() {
BuildPackage BuildPackage
fi fi
# Timestamp # Timestamp
printf "<td>$(date +%F-%R)</td>\n" >> "$webfile" printf "<td>$(date +%F-%R)</td></tr>\n" >> "$webfile"
cd "$cwd" cd "$cwd"
if [ ! -z "$testing" ]; then break; fi if [ ! -z "$testing" ]; then break; fi
done done
@ -108,19 +114,23 @@ aurconf='/usr/local/etc/Maat/aur.list'
homedir=/srv/maat/ homedir=/srv/maat/
unset upload unset upload
unset testing unset testing
unset incremental
user="depriv"
# Stat tracking # Stat tracking
starttime=`date +%s` starttime=`date +%s`
# Parse arguments # Parse arguments
while getopts 'b:c:hl:Tu:Uv' OPTION; do while getopts 'b:c:hil:Tu:U:v' OPTION; do
case "${OPTION}" in case "${OPTION}" in
b) homedir="${OPTARG}" ;; b) homedir="${OPTARG}" ;;
c) aurconf="${OPTARG}" ;; c) aurconf="${OPTARG}" ;;
h) Usage; exit 0 ;; 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}\"" ;; 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 ;; T) homedir='.'; testing=1 ;;
u) baseurl="${OPTARG}" ;; u) baseurl="${OPTARG}" ;;
U) user="${OPTARG}" ;;
v) set -x ;; v) set -x ;;
*) usage; exit 1 ;; *) usage; exit 1 ;;
esac esac
@ -132,8 +142,8 @@ if [ $( echo "$homedir" | egrep -c '^/') -ne 1 ]; then
fi fi
srcdir="${homedir}/src" && mkdir -p "${srcdir}" srcdir="${homedir}/src" && mkdir -p "${srcdir}"
pkgdir="${homedir}/pkg" && mkdir -p "${pkgdir}" pkgdir="${homedir}/pkg" && mkdir -p "${pkgdir}"
webdir="${homedir}/web" && mkdir -p "${webdir}" webdir="$pkgdir"
webfile="$webdir"/index.php webfile="$webdir"/index.html
# For each repo listed at the CGIT URL and conf file # For each repo listed at the CGIT URL and conf file
cwd="$(pwd)" 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 if [ ! -z "$testing" ]; then break; fi
done done
for repo in `cat "$aurconf"`; do for repo in `cat "$aurconf"`; do
BuildRepo repo; BuildRepo "$repo";
if [ ! -z "$testing" ]; then break; fi if [ ! -z "$testing" ]; then break; fi
done 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