python: Fixed dependencies for python sqlite3 module
[omd.git] / build_cached
blobe7602cd80dd72b6e66e0a1e497a057aa343eb2ae
1 #!/bin/bash
3 MAKE=$1
4 SRC=$2
5 CACHESUBDIR=$3
7 # skip caching if cache folder is not set or does not exist or omd version length is too small, which would be error prone
8 if [ "x$BUILD_CACHE" = "x" ] || ! test -d $BUILD_CACHE || [ ${#OMD_VERSION} -lt 5 ]; then
9 $MAKE -C "$SRC" build
10 exit $?
13 BUILD_CACHE=$BUILD_CACHE/$CACHESUBDIR
14 mkdir -p $BUILD_CACHE
16 $MAKE -C "$SRC" clean
17 MD5=$(cd "$SRC" && find . -type f -exec md5sum {} \; | sort | md5sum | awk '{ print $1 }')
18 CACHE_FILE="$BUILD_CACHE/${SRC}_${MD5}.tgz"
20 # cache hit - just unpack the already built package
21 if test -e "$CACHE_FILE"; then
22 echo "md5sum matched, using cache from $CACHE_FILE"
23 tar zxf "$CACHE_FILE"
24 find "$SRC/" -type f | \
25 while read file; do
26 if grep -Ic "###BUILD_OMD_VERSION###" "$file" >/dev/null 2>&1; then
27 cp -p "$file" "$file.tmp"
28 sed -e "s%###BUILD_OMD_VERSION###%$OMD_VERSION%g" -i "$file"
29 touch -r "$file.tmp" "$file"
30 rm -f "$file.tmp"
32 done
33 exit 0
35 EXCLUDES_FILE=$(mktemp)
36 find "$SRC" -type f > $EXCLUDES_FILE
38 # no cache hit - rebuild package and create cache tarball
39 set -e
40 $MAKE -C "$SRC" build
41 set +e
43 # create cache file
44 find "$SRC/" -type f | \
45 while read file; do
46 if grep -Ic "$OMD_VERSION" "$file" >/dev/null 2>&1; then
47 cp -p "$file" "$file.tmp"
48 sed -e "s%$OMD_VERSION%###BUILD_OMD_VERSION###%g" -i "$file"
49 touch -r "$file.tmp" "$file"
50 rm -f "$file.tmp"
52 done
53 TARBALL_TMP=$(mktemp)
54 tar cfz $TARBALL_TMP "$SRC" --exclude-from=$EXCLUDES_FILE
55 rm -f "$CACHE_FILE"
56 mv $TARBALL_TMP "$CACHE_FILE"
57 echo "cache file $CACHE_FILE created"
58 rm $EXCLUDES_FILE
59 find "$SRC/" -type f | \
60 while read file; do
61 if grep -Ic "###BUILD_OMD_VERSION###" "$file" >/dev/null 2>&1; then
62 cp -p "$file" "$file.tmp"
63 sed -e "s%###BUILD_OMD_VERSION###%$OMD_VERSION%g" -i "$file"
64 touch -r "$file.tmp" "$file"
65 rm -f "$file.tmp"
67 done
69 exit 0