]> git.donarmstrong.com Git - cran2deb.git/blob - trunk/exec/update
start allowing for local user cache configuration
[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 cachedir="/var/cache/cran2deb/results/"
11 pbuildercache="/var/cache/pbuilder/"
12
13 if [ -e /etc/cran2deb/config ]; then
14     . /etc/cran2deb/config;
15 elif [ -r ~/.cran2deb_config ]; then
16     . ~/.cran2deb_config;
17 fi;
18
19 umask 002
20 root=$1
21 if [ -z "$root" ]; then
22        echo "You need to specify the root of your installation, i.e. the folder in which to find the exec subdirectory."
23        exit 1
24 fi
25
26 shift
27 sys=$(cran2deb which_system)
28 mkdir -p $(cachedir)/$sys
29 #update_period=10800
30 update_period=108
31
32 cache_rda="${cachedir}/cache.rda"
33 if [ ! $1 = full ] || [ ! -e "${cache_rda}" ]; then
34     delta=$(($update_period+1))
35     echo Forcing cache update
36 else
37     seconds_time=$(date +%s)
38     seconds_file=$(stat -c '%Y' "${cache_rda}")
39     delta=$(($seconds_time-$seconds_file))
40     echo Cache is $delta seconds out of date, auto-update after $update_period seconds.
41 fi
42
43 if [ ! -e "${cache_rda}" ] || [ $delta -gt $update_period ]; then
44     mode=create
45     if [ -e "${pbuilder_cache}"/base-cran2deb-$sys.tgz ]; then
46         mode=update
47     fi
48     echo C: sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc
49     echo "Executing sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc"
50     sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc
51     echo "Executing $root/exec/update_cache $root"
52     $root/exec/update_cache $root
53 fi
54