Today I jotted down some fresh code for tarball automation. The needs of such automation are so simple it made sense to write it in bash. I thought I’d share it here. Suggestions are always welcome.
#!/bin/sh
### PART 1: UPDATE SEED
# Get text file describing latest stage3 tarball.
# -O option circumvents wget creating a new file on every run and gives us a fixed filename to use.
# The wget -S option is --server-response, which can be grepped.
# ssmtp.conf has been configured.
url="https://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3-amd64-desktop-systemd.txt"
email="webmaster@gentoostudio.org"
if [[ `wget -S --spider $url 2>&1 | grep 'HTTP/1.1 200 OK'` ]];
then wget -O latest.txt $url;
else
ssmtp -v $email < wget_textfile_failmsg
echo "Remote file does not exist. Mail sent to $email."
exit 1;
fi
# Parse text file for URL
# Use tail cmd to read last line of file, which is all we need,
# then use sed to chop off everything after the space in that line
# When wget is done, move the file to where its needed
# (The mv destination is a symlink)
# Not sure we need an ifelse here. If the above check passes, this wget should work.
latest=$(tail -n 1 latest.txt | sed 's#[[:space:]].*##')
wget -O stage3seed.tar.xz https://distfiles.gentoo.org/releases/amd64/autobuilds/$latest
mv stage3seed.tar.xz catalyst-tarballs
### PART 2: SYNC
eix-sync
catalyst -s latest
### PART 3: STAGE1 BUILD
catalyst -af stage1.spec
# TODO: Error detection and mail notification
### PART 4: STAGE2 BUILD
catalyst -af stage2.spec
# TODO: Error detection and mail notification
### PART 5: STAGE3 BUILD
catalyst -af stage3.spec
# TODO: Error detection and mail notification
### PART 6: STAGE4 BUILD
catalysst -af stage4.spec
# TODO: Error detection and mail notification
### fscript is automatically executed by stage4.