#!/bin/sh
VERSION=1.3.1
M3VERSION=1.4
BUILDTIME=`date "+%Y%m%d"`
MACHINE=Adventurer3-ROBO
PID=00F2
FILENAME="${MACHINE}-${VERSION}-${M3VERSION}-${BUILDTIME}.tgz"
VERFILE=version

sed -i "/^MACHINE=Adventurer3*/c MACHINE=${MACHINE}" ./auto_run.sh
sed -i "/^MACHINE=Adventurer3*/c MACHINE=${MACHINE}" ./flashforge_init.sh

sed -i "/^PID=*/c PID=${PID}" ./auto_run.sh
sed -i "/^PID=*/c PID=${PID}" ./flashforge_init.sh

sync

if [ ! -d ../image ];then
	mkdir -p ../image
fi

sed -i '40,48 s/^uci/#uci/g' ./flashforge_init.sh
sync

tar -czvf ${FILENAME} ./*

echo "version=${VERSION}" >> ${VERFILE}
echo "buildtime=${BUILDTIME}" >> ${VERFILE}
echo "file=${FILENAME}" >> ${VERFILE}
echo "md5=`md5sum ${FILENAME} | cut -d ' ' -f1`" >> ${VERFILE}

mv ${FILENAME} ../image
mv ${VERFILE}  ../image

sync

sed -i '40,48 s/^#uci/uci/g' ./flashforge_init.sh
touch screwflag
sync

FACTORY_FILENAME="${MACHINE}-${VERSION}-${M3VERSION}-${BUILDTIME}-Factory.tgz"
tar -czvf ${FACTORY_FILENAME} ./*
rm -rf ./screwflag
sync

mv ${FACTORY_FILENAME} ../image

