You are not logged in.

#1 2011-02-23 01:08:53

rusma
Member
From: Ås, Norway
Registered: 2009-11-01
Posts: 110

A scriptnewbies AUR nightly build script

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

#2 2011-02-23 01:30:17

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,548

Re: A scriptnewbies AUR nightly build script

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

#3 2011-02-23 02:46:26

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: A scriptnewbies AUR nightly build script

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

#4 2011-02-23 20:50:47

rusma
Member
From: Ås, Norway
Registered: 2009-11-01
Posts: 110

Re: A scriptnewbies AUR nightly build script

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

#5 2011-02-23 21:12:14

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: A scriptnewbies AUR nightly build script

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

#6 2011-02-23 21:40:30

rusma
Member
From: Ås, Norway
Registered: 2009-11-01
Posts: 110

Re: A scriptnewbies AUR nightly build script

`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 ...

tomk wrote:

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

#7 2011-02-23 21:47:29

rusma
Member
From: Ås, Norway
Registered: 2009-11-01
Posts: 110

Re: A scriptnewbies AUR nightly build script

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

Board footer

Powered by FluxBB