generate.sh
author Dan
Tue, 23 Jun 2009 09:55:13 -0400
changeset 2 7dddb5fb1595
parent 1 dbce0b16b0c1
child 3 859eeb3579b2
permissions -rwxr-xr-x
Me and my obsession with getting files to exactly 2048 bytes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     1
#!/bin/bash
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     2
DATE=`date "+%Y%m%d"`
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     3
VERSION="hg-$DATE"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     4
REPO="./enano-hg"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     5
REVISION="tip"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     6
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     7
usage()
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     8
{
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
     9
  cat <<EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    10
Usage: $0 [flags]
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    11
Available command-line parameters:
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    12
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    13
  -h                This help
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    14
  -v version        Specify version of package (default: hg-$DATE)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    15
  -r revision       Mercurial revision to pull (default: tip)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    16
  -R repopath       Path to Mercurial repository (default: ./enano-hg)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    17
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    18
EOF
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    19
  exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    20
}
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    21
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    22
fail()
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    23
{
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    24
  echo $1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    25
  exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    26
}
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    27
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    28
while [ -n "$1" ]; do
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    29
  case "$1" in
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    30
    -v)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    31
      VERSION="$2"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    32
      shift
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    33
      ;;
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    34
    -r)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    35
      REVISION="$2"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    36
      shift
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    37
      ;;
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    38
    -R)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    39
      REPO="$2"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    40
      shift
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    41
      ;;
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    42
    *)
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    43
      usage
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    44
      ;;
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    45
  esac
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    46
  shift
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    47
done
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    48
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    49
if [ -z "$VERSION" -o -z "$REVISION" -o -z "$REPO" ]; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    50
  usage
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    51
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    52
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    53
if [ ! -d "$REPO/.hg" ]; then
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    54
  echo "ERROR: Could not find the Enano Mercurial repository at $REPO."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    55
  echo "Perhaps you need to obtain a copy?"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    56
  echo "  $ hg clone http://hg.enanocms.org/repos/enano-1.1 ./enano-hg"
2
7dddb5fb1595 Me and my obsession with getting files to exactly 2048 bytes.
Dan
parents: 1
diff changeset
    57
  echo "If you have a copy somewhere else, make a symlink:"
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    58
  echo "  $ ln -s /path/to/enano/hg ./enano-hg"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    59
  exit 1
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    60
fi
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    61
1
dbce0b16b0c1 Added shellscript compactor to reduce size of self-extract script
Dan
parents: 0
diff changeset
    62
printf "Compacting self-extraction script..."
dbce0b16b0c1 Added shellscript compactor to reduce size of self-extract script
Dan
parents: 0
diff changeset
    63
sed -f compact-shellscript.sed self-extract-src.sh > self-extract.sh || fail "Failed to generate compacted self-extract script"
dbce0b16b0c1 Added shellscript compactor to reduce size of self-extract script
Dan
parents: 0
diff changeset
    64
dbce0b16b0c1 Added shellscript compactor to reduce size of self-extract script
Dan
parents: 0
diff changeset
    65
printf "\nPulling latest code..."
0
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    66
hg -R $REPO archive -r $REVISION -t tgz enano-$VERSION.tar.gz || fail "Could not pull revision $REVISION from Mercurial repo"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    67
printf "\nExtracting..."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    68
tar xzCf `dirname $0`/stage enano-$VERSION.tar.gz || fail "Could not extract tarball"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    69
rm -f enano-$VERSION.tar.gz
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    70
printf "\nCreating payload..."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    71
cd stage
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    72
tar cjf ../enano-$VERSION-selfextract.tar.bz2 autorun.sh COPYING enano-$VERSION || fail "Could not create staging tarball"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    73
rm -rf enano-$VERSION
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    74
cd ..
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    75
printf "\nWriting output..."
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    76
cat self-extract.sh enano-$VERSION-selfextract.tar.bz2 > enano-$VERSION-bitnami-module.sh || fail "Could not write output"
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    77
chmod +x enano-$VERSION-bitnami-module.sh
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    78
rm -f enano-$VERSION-selfextract.tar.bz2
8e044e762a6c First revision, but working.
Dan
parents:
diff changeset
    79
echo -e "\nDone! Output written to enano-$VERSION-bitnami-module.sh"