]> git.donarmstrong.com Git - cran2deb.git/blobdiff - trunk/exec/update
start allowing for local user cache configuration
[cran2deb.git] / trunk / exec / update
index 7d466b91fd49290b05f40d29ca296b447ae1186b..ee1bd7bc8e3745d52b2e104b29639f1e2a79544e 100755 (executable)
@@ -1,30 +1,54 @@
-#!/usr/bin/rc
+#!/bin/bash
+
 ## DOC: cran2deb update
 ## DOC:     update the cran2deb cache and database
 ## DOC: cran2deb update full
 ## DOC:     force a full update of the cran2deb cache and database
 ## DOC:
 
+set -e
+cachedir="/var/cache/cran2deb/results/"
+pbuildercache="/var/cache/pbuilder/"
+
+if [ -e /etc/cran2deb/config ]; then
+    . /etc/cran2deb/config;
+elif [ -r ~/.cran2deb_config ]; then
+    . ~/.cran2deb_config;
+fi;
+
 umask 002
 root=$1
+if [ -z "$root" ]; then
+       echo "You need to specify the root of your installation, i.e. the folder in which to find the exec subdirectory."
+       exit 1
+fi
+
 shift
-sys=`{cran2deb which_system}
-mkdir -p /var/cache/cran2deb/results/$sys || exit 1
-mini-dinstall --batch -c /etc/cran2deb/sys/$sys/mini-dinstall.conf || exit 1
-update_period=10800
-if (~ $1 full || ![ -e /var/cache/cran2deb/cache.rda ] ) {
-    delta=`{awk 'END{print '^$update_period^'+1}' </dev/null}
+sys=$(cran2deb which_system)
+mkdir -p $(cachedir)/$sys
+#update_period=10800
+update_period=108
+
+cache_rda="${cachedir}/cache.rda"
+if [ ! $1 = full ] || [ ! -e "${cache_rda}" ]; then
+    delta=$(($update_period+1))
     echo Forcing cache update
-} else {
-    delta=`{awk 'END{print '^`{date +%s}^-^`{stat -c '%Y' /var/cache/cran2deb/cache.rda}^'}' </dev/null}
-    echo Cache is $delta seconds out of date.
-}
-if (![ -e /var/cache/cran2deb/cache.rda ] || [ $delta -gt $update_period ]) {
+else
+    seconds_time=$(date +%s)
+    seconds_file=$(stat -c '%Y' "${cache_rda}")
+    delta=$(($seconds_time-$seconds_file))
+    echo Cache is $delta seconds out of date, auto-update after $update_period seconds.
+fi
+
+if [ ! -e "${cache_rda}" ] || [ $delta -gt $update_period ]; then
     mode=create
-    if ([ -e /var/cache/pbuilder/base-cran2deb-$sys.tgz ]) {
+    if [ -e "${pbuilder_cache}"/base-cran2deb-$sys.tgz ]; then
         mode=update
-    }
+    fi
+    echo C: sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc
+    echo "Executing sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc"
     sudo pbuilder $mode --override-config --configfile /etc/cran2deb/sys/$sys/pbuilderrc
+    echo "Executing $root/exec/update_cache $root"
     $root/exec/update_cache $root
-}
+fi