2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 # stefan.k.berg@ericsson.com
5 # jonas.bjurel@ericsson.com
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 CACHETRANSPORT=${CACHETRANSPORT:-"curl --silent"}
13 CACHEBASE=${CACHEBASE:-"file://${HOME}/cache"}
14 CACHEMAXAGE=${CACHEMAXAGE:-$[14*24*3600]}
15 CACHEDEBUG=${CACHEDEBUG:-1}
18 if [ "$CACHEDEBUG" -eq 1 ]; then
27 # Get a SHA1 based on what's piped into the cache command
29 debugmsg "Generating sha1sum"
30 sha1sum | sed 's/ .*//'
37 debugmsg "SHA1 $1 already in cache, skipping storage"
39 debugmsg "Storing SHA1 $1 in cache"
40 ${CACHETRANSPORT} -T - ${CACHEBASE}/$1.blob
41 echo "Expires: $[`date +"%s"` + $CACHEMAXAGE]" | ${CACHETRANSPORT} -T - ${CACHEBASE}/$1.meta
50 ${CACHETRANSPORT} -o - ${CACHEBASE}/$1.blob 2>/dev/null
53 if [ $rc -eq 0 ]; then
54 echo "Got SHA1 $1 from cache" 2>/dev/null
56 echo "Tried to get SHA1 $1 from cache but failed" 2>/dev/null
66 ${CACHETRANSPORT} ${CACHEBASE}/$1.meta &>/dev/null
69 if [ $rc -eq 0 ]; then
70 debugmsg "Checking for SHA1 $1 in cache and found it, rc = $rc"
72 debugmsg "Checking for SHA1 $1 in cache and failed, rc = $rc"
78 # Verify that SHA1 seems to be a SHA1...
80 if [ $(echo $1 | wc -c) -ne 41 ]; then
90 errormsg "No arguments can be given to getid!"
97 errormsg "Only one argument, the SHA1 sum, can be given to getid!"
100 if ! validSHA1 $2; then
101 errormsg "Invalid SHA1 format!"
110 errormsg "I only know about getid, check, get and put!"