aboutsummaryrefslogtreecommitdiff
path: root/bin/archive
blob: d79d411c8d21cea3c56f6089eac034777999f92b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
#
# Archiver
#

# Parameters
BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`"
DIRNAME="`dirname $0`"
BASEDIR="$DIRNAME/.."
#ARCHIVE="$BASEDIR/archive"
ARCHIVE="archive"
ASSETS="build"
#REVISION="`git describe --tags 2> /dev/null || git log -1 --format=oneline | cut -d ' ' -f 1`"
METADATA=".metadata"
LATEST="$METADATA/latest.txt"

# Determine the revision file
if [ -e "$ASSETS/revision" ]; then
  #REVFILE="$BASEDIR/$ASSETS/revision"
  REVFILE="$ASSETS/revision"
else
  REVFILE="$ASSETS/book/revision"
fi

# Make sure the archive folder exist
mkdir -p $ARCHIVE

# Make sure the archive has some basic links
# This allows preservation of symbolic links for each archive version.
(
  cd $ARCHIVE &> /dev/null

  rm -f archive && ln -s . archive
  for item in slides vendor images LICENSE; do
    ln -sf ../$item
  done
)

# Check for previous build
if [ ! -e "$REVFILE" ]; then
  echo "# $BASENAME: skipping: revision file not found"
  exit
else
  REVISION="`cat $REVFILE`"
fi

# Check for non-null revision
if [ -z "$REVISION" ]; then
  echo "# $BASENAME: skipping: old revision is null"
  exit
fi

# Check if the revision is a tag
if git tag | grep -q "^${REVISION}$"; then
  # Check if archive does not exists
  if [ ! -d "$ARCHIVE/$REVISION" ]; then
    echo "# $BASENAME: archiving $REVISION..."
    cp -alf $ASSETS $ARCHIVE/$REVISION
  else
    echo "# $BASENAME: revision $REVISION already archived"
  fi
else
  echo "# $BASENAME: not archiving: revision $REVISION is not a tag"
fi