]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/exec/update
Transformed Plan 9 shell script into BASH,
[cran2deb.git] / trunk / exec / update
1 #!/bin/bash
2
3 ## DOC: cran2deb update
4 ## DOC:     update the cran2deb cache and database
5 ## DOC: cran2deb update full
6 ## DOC:     force a full update of the cran2deb cache and database
7 ## DOC:
8
9 set -e
10
11 umask 002
12 root=$1
13 if [ -z "$root" ]; then
14        echo "You need to specify the root of your installation, i.e. the folder in which to find the exec subdirectory."
15        exit 1
16 fi
17
18 shift
19 sys=$(cran2deb which_system)
20 mkdir -p /var/cache/cran2deb/results/$sys
21 #update_period=10800
22 update_period=108
23
24 if [ ! $1 = full -o !-e /var/cache/cran2deb/cache.rda ]; then
25     delta=$(($update_period+1))
26     echo Forcing cache update
27 else
28     delta=$(awk 'END{print '^`{date +%s}^-^`{stat -c '%Y' /var/cache/cran2deb/cache.rda}^'}' < /dev/null)
29     echo Cache is $delta seconds out of date, auto-update after $update_period seconds.
30 fi
31
32 if [ ! -e /var/cache/cran2deb/cache.rda ] || [ $delta -gt $update_period ]; then
33     mode=create
34     if [ -e /var/cache/pbuilder/base-cran2deb-$sys.tgz ]; then
35         mode=update
36     ]
37     echo C: sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc
38     echo "Executing sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc"
39     sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc
40     echo "Executing $root/exec/update_cache $root"
41     $root/exec/update_cache $root
42 }
43