#!/bin/sh

. config/options $1

$SCRIPTS/image_squashfs

get_version

RELEASE_DIR="target/$DISTRONAME-$TARGET_VERSION"

# cleanup
  rm -rf $RELEASE_DIR

# create release dir
  mkdir -p $RELEASE_DIR
    cp $ROOT/README $RELEASE_DIR
    cp $ROOT/CHANGELOG $RELEASE_DIR
  #  cp -R $CONFIG/image/* $RELEASE_DIR
    cp -R $CONFIG/release/* $RELEASE_DIR
    echo "$TARGET_VERSION" > $RELEASE_DIR/RELEASE

  mkdir -p $RELEASE_DIR/licenses
    cp $ROOT/licenses/* $RELEASE_DIR/licenses

  mkdir -p $RELEASE_DIR/target
    cp $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.system $RELEASE_DIR/target/SYSTEM
    cp $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.kernel $RELEASE_DIR/target/KERNEL

# create md5sum's
  ( cd $RELEASE_DIR;
    md5sum -t target/SYSTEM > target/SYSTEM.md5;
    md5sum -t target/KERNEL > target/KERNEL.md5;
  )

# create target directory
  mkdir -p $TARGET_IMG

# remove an previous created release tarball
  rm -rf $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.tar.bz2

# create release tarball
  tar cjf $TARGET_IMG/$DISTRONAME-$TARGET_VERSION.tar.bz2 -C target $DISTRONAME-$TARGET_VERSION

# cleanup release dir
  rm -rf $RELEASE_DIR
