engine/templates/linux/create_deb.sh
PACKAGE_NAME=$1
VERSION=$2
SOURCE_BINARY_PATH=$3
SOURCE_BINARY_SERVER_PATH=$4
DESTINATION_BINARY_NAME=$5
DESTINATION_BINARY_SERVER_NAME=$6
DATA_FOLDER_NAME=$7
CONFIGURATION_FILE_NAME=$8
ARCH=$9

mkdir -p $PACKAGE_NAME/DEBIAN

mkdir -p $PACKAGE_NAME/usr/bin
cp $SOURCE_BINARY_PATH $PACKAGE_NAME/usr/bin/$DESTINATION_BINARY_NAME
cp $SOURCE_BINARY_SERVER_PATH $PACKAGE_NAME/usr/bin/$DESTINATION_BINARY_SERVER_NAME

export DESTINATION_BINARY_NAME

cp postinst $PACKAGE_NAME/DEBIAN/postinst
sed -i "2s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" $PACKAGE_NAME/DEBIAN/postinst

cp prerm $PACKAGE_NAME/DEBIAN/prerm
sed -i "3s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" $PACKAGE_NAME/DEBIAN/prerm

export DATA_FOLDER_NAME CONFIGURATION_FILE_NAME

cp postrm $PACKAGE_NAME/DEBIAN/postrm
sed -i "3s/.*/DATA_FOLDER_NAME=$DATA_FOLDER_NAME/" $PACKAGE_NAME/DEBIAN/postrm
sed -i "4s/.*/CONFIGURATION_FILE_NAME=$CONFIGURATION_FILE_NAME/" $PACKAGE_NAME/DEBIAN/postrm

chmod 755 $PACKAGE_NAME/DEBIAN/postinst
chmod 755 $PACKAGE_NAME/DEBIAN/postrm
chmod 755 $PACKAGE_NAME/DEBIAN/prerm

export PACKAGE_NAME VERSION ARCH

envsubst < control > $PACKAGE_NAME/DEBIAN/control
sed -i "s/ARCH/$ARCH/" $PACKAGE_NAME/DEBIAN/control

dpkg-deb --build $PACKAGE_NAME $PACKAGE_NAME.deb
