You are not logged in.
Hi all.
I have made this nightly AUR build script which is going to build my favorite AUR packages in the night through cron, and I am seeking some advice on how it can become a better script. I have note really made much scripts prevously, so this is a little new to me.
I have searched Google alot for advice on variables and funcitons and quatations and such, so the syntax may seem a little strange to the trained eye, I think. But, things works. I've thought about making my own git repository also, so i can see the progress, or something like that.
Here it is:
#!/bin/sh
#
#################################################
#### AUR package build script START
#################################################
#
# Periodic buildscript to update packages in AUR
# Task sequence: download and unpack AUR tarball, makepkg, copy to local repository
#
# Put in crontab file:
# 00 3 * * * /path/to/this/script >> /dev/null 2>&1
# Crontab will run this script three o'clock every night
#
#### Global variables
BASEDIR="${HOME}/aur" # This is the working dir
REPODIR="${HOME}/repo" # Packages will be saved here
AURBASEADDRESS="http://aur.archlinux.org/packages/"
AURTARBALLFORMAT="tar.gz"
#
#### Functions
buildpkg() {
echo -e "==> Start package package $1" # Announce start of build
cd ${BASEDIR} >> /dev/null 2>&1 # Enter base directory
mkdir -p ${BASEDIR}/$1 >> /dev/null 2>&1 # Make a working directory
wget $AURBASEADDRESS$1/$1.$AURTARBALLFORMAT >> /dev/null 2>&1 # Download tarball to ${HOME}/aur
tar zxvf $1.tar.gz >> /dev/null 2>&1 # Untar tarball to working directory
rm *.* >> /dev/null 2>&1 # Delete old archives so nothing will be floating around and cause double build packages
cd ${BASEDIR}/$1 >> /dev/null 2>&1 # Enter working directory
makepkg -s >> /dev/null 2>&1 # Make AUR package
cp *.pkg.tar.xz ${REPODIR} >> /dev/null 2>&1 # Copy all packages to the repository
# rm -rf ${BASEDIR}/$1 >> /dev/null 2>&1 # Delete working directory
echo -e "==> Finished building package $1" # Announce end of build
}
#
#### Ensure repository directory is present
mkdir -p $BASEDIR
mkdir -p $REPODIR
#
#### Build the packages in question
for n in \
awesome-git \
vicious-git \
broadcom-wl \
dolphin-emu-svn;\
do (buildpkg $n) ; done
#
#### Trim directory for files older than $DAYS days
DAYS='3'
find $REPODIR/* -mtime +$DAYS -exec rm {} \;
#
#################################################
#### AUR package build script END
#################################################
Edit: made CODE-box, looks nicer, better formatting
Last edited by rusma (2011-02-23 20:13:13)
Offline
Instead of hardcoding the list of packages to build, you could use
pacman -Qqm
to get the list of all packages you have installed from AUR.
Also, you may run into problems using
makepkg -s
while being run by cron if pacman needs a sudo password
Last edited by skunktrader (2011-02-23 01:43:40)
Offline
You can avoid needing to redirect everything to /dev/null in a couple of ways. Via indirect FDs:
foo() {
echo "to stdout (not seen)"
echo "to stderr (not seen)" >&2
echo "to FD 3 (seen)" >&3
} 3>&1 >/dev/null 2>&1
Or in this case it might just be easier to pull out the single line from the function...
somefunc() {
# stuff happens
}
for x in foo bar baz; do
echo "starting $x"
somefunc $x >/dev/null 2>&1
echo "done with $x"
done
The general convention on variable names is that only environment vars are upper cased. Variables local to your script should be lower case.
And from a cron perspective, you have no guarantees as to what your path might be. Either declare your program names' full paths up front with variables and reference the variables, or declare a PATH in the script itself.
Offline
Thank you, that was indeed some good tips. I've changed the script, and think it looks alot better now.
To make this directory a real "nightly builds" directory which is updatable by pacman, I think I would have to have a *.db file of some kind, do I not (I think it would have to be named repo.db since the directory where the packages reside has this name)? How can this database/hash-thing be generated?
Eh, I also need to modify the makepkg command as skunktrader pointed out, or else I think the script will hang at sudo prompt ...
Lastly, If I had some other ArchLinux machine with x86_64 architecture, I could rsync these files over to some location where they could be hosted by a http server (nginx, or maybe OpenBSD's hardened legacy Apache from my Soekris box). How does that sound?
Last edited by rusma (2011-02-23 21:11:58)
Offline
repo-add/repo-remove are what you're looking for - they're already on your system, provided by the pacman package. Very simple to use, read the man page for details.
And yes, once you have all the files, you can host them any way you want.
<edit>And you don't need to edit makepkg - just set up your sudo so that pacman commands don't need a password. Also, pacman -Qm shows all packages that are not in one of pacman's active repos, as defined in pacman.conf. This may not be the same as all packages from the AUR.
Offline
`repo-add ....db *.tar.gz.xz ....'-stuff will be added at the end of the script ... got to read sudos man page for info on specific applications ...
Also, pacman -Qm shows all packages that are not in one of pacman's active repos, as defined in pacman.conf. This may not be the same as all packages from the AUR.
thats a good point, tomk, but I think hardcoding gives me more control, as I am not interested in building all kinds of packages, but only the most important ones (which at the moment probably is Awesome Window Manager-related stuff, as Awesome is currently not in the extra repositories because of some fundamental changes that has been going on for quite some time now -- that is because vicious is also important, it reports battery status from acpid and some other things, but gradients seems not to work in the new Awesome).
I may add another function which builds specific PKGBUILD-files, maybe some that are ``timeless'' so-to-speak (simple packages without much dependencies).
Offline
It could also be interesting to add a if else that announces package build failure e.g. tarball is not present anymore, and then send root an email with the output that was not logged by syslogd.
Offline