#!/bin/sh

PKG_NAME="libmcrypt"
PKG_MAKE_HOME=`cat ../.PKG_HOME`
PKG_META="./+MANIFEST"

## base script
BASE_PATH="$PKG_MAKE_HOME/basescript"
COPY_OUTPUT="$BASE_PATH/copy2output.sh"
USE_OUTCOPY="$BASE_PATH/copy2scp.sh"
WORK_OUTPKG="../.OUTPUT"

## input vlaue
if [ $# -lt 1 ]
then
    echo "$0 [TARGET]"
    exit 1
fi

TARGET=$1

KEY_PATH=`grep "${TARGET}-KEY-PATH=" ../.DEPLOYMENT_INFO |  sed -e "s/$(echo $TARGET)-KEY-PATH=//" `
OUTPUT_PATH="${WORK_OUTPKG}/${KEY_PATH}"

## tar zxvf *.txz 

## edit +MANIFEST => origin

## create pkg
rm -f ./OUTPUT/*.txz
pkg create -M $PKG_META -r ./ -o ./OUTPUT

## copy .OUTPUT
cp -f ./OUTPUT/*.txz $OUTPUT_PATH

## register repo 
pkg repo $OUTPUT_PATH/.

## copy output server
$COPY_OUTPUT "$USE_OUTCOPY" "$WORK_OUTPKG" "$PKG_NAME" "$TARGET"

