Commit 74ef64d6 by lucapegolotti

scripts: changed create_tarball.sh into create:tarball_and_zip.sh so that…

scripts: changed create_tarball.sh into create:tarball_and_zip.sh so that scripts create also zip file
parent 6dc01f7b
......@@ -25,7 +25,7 @@
#function for printing usage
usage() {
echo "Create a tarball of the project. Specify the project root with the";
echo "Create a tarball and a zip of the project. Specify the project root with the";
echo "-d parameter. Optionally, specify the -v switch to get verbose output";
echo "and/or the -q switch, for non-interactive (without user inputs)";
echo "processing.";
......@@ -103,12 +103,24 @@ VERSION_NUMBER="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
PROJECT_NAME=`cat $CMAKEFILE | grep project.*\(.*\) | sed "s/^[^(]*(\([^)]*\)).*$/\1/g" | tr '[:upper:]' '[:lower:]'`
n="${PROJECT_NAME}-${VERSION_NUMBER}"
TARBALL_NAME="${n}.tar.gz"
ZIP_NAME="${n}.zip"
#verify that tarball doesn't allow forbidden characters
#booleans for checking what has to be created
CREATE_TARBALL=true;
CREATE_ZIP=true;
#verify that tarball name doesn't contain forbidden characters
if ! [[ $TARBALL_NAME =~ ^[a-zA-Z0-9|\.|\_|-]+$ ]]; then
echo "--> Want to create tarball with name $TARBALL_NAME." >&2
echo '--> ! Filename not valid, only a-z, A-Z, .,- and _ characters are allowed' >&2 # write to stderr
exit 1
CREATE_TARBALL=false
fi
#verify that zip name doesn't contain forbidden characters
if ! [[ $ZIP_NAME =~ ^[a-zA-Z0-9|\.|\_|-]+$ ]]; then
echo "--> Want to create zip with name $TARBALL_NAME." >&2
echo '--> ! Filename not valid, only a-z, A-Z, .,- and _ characters are allowed' >&2 # write to stderr
CREATE_ZIP=false
fi
if [ -z "${q}" ]; then
......@@ -117,34 +129,80 @@ if [ -z "${q}" ]; then
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo Leaving tarball creation; exit 1;;
No ) echo "Leaving tarball creation"; CREATE_TARBALL=false; break;;
esac
done
else
echo "--> Tarball with name $TARBALL_NAME will be created."
fi
#check if file with the tarball_name already exists. In interactive mode, ask the user if this file shall be deleted. Otherwise just exit.
if [ -f "$TARBALL_NAME" ]; then
#check if file with the tarball_name already exists. In interactive mode, ask the user if this file shall be deleted. Otherwise do not create tarball.
if [ \( -f "$TARBALL_NAME" \) -a \( "$CREATE_TARBALL" = true \) ]; then
if [ -z "${q}" ]; then
echo "--> File $TARBALL_NAME exists. Delete file?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo Leaving tarball creation; exit 1;;
No ) echo "Leaving tarball creation"; CREATE_TARBALL=false; break;;
esac
done
if [ "$CREATE_TARBALL" = true ] ; then
rm $TARBALL_NAME
if [ -f "$TARBALL_NAME" ]; then
echo "Could not delete $TARBALL_NAME"
exit 1
CREATE_TARBALL=false
fi
fi
else
echo "--> ! File $TARBALL_NAME exists. Delete first. Exiting."
exit 1;
echo "--> ! File $TARBALL_NAME exists. Delete first. Exiting tarball creation."
CREATE_TARBALL=false;
fi
fi
if [ -z "${q}" ]; then
#in interactive mode, ask the user if the zip shall be created with this filename
echo "--> Do you wish to create a zip with the name $ZIP_NAME in the current directory?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo "Leaving zip creation"; CREATE_ZIP=false; break;;
esac
done
else
echo "--> Zip with name $ZIP_NAME will be created."
fi
#check if file with the zip_name already exists. In interactive mode, ask the user if this file shall be deleted. Otherwise do not create zip.
if [ \( -f "$ZIP_NAME" \) -a \( "$CREATE_ZIP" = true \) ]; then
if [ -z "${q}" ]; then
echo "--> File $ZIP_NAME exists. Delete file?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo "Leaving zip creation"; CREATE_ZIP=false; break;
esac
done
if [ "$CREATE_ZIP" = true ]; then
rm $ZIP_NAME
if [ -f "$ZIP_NAME" ]; then
echo "Could not delete $ZIP_NAME"
CREATE_ZIP=false
fi
fi
else
echo "--> ! File $ZIP_NAME exists. Delete first. Exiting zip creation."
CREATE_ZIP=false
fi
fi
#exit if tarball and zip must not / cannot be created
if [ \( "$CREATE_ZIP" = false \) -a \( "$CREATE_TARBALL" = false \) ] ; then
echo "Exiting, no files to generate";
exit 1;
fi
#temporary directory for doxygen
MYTMPDIR_DOXY_BUILD=`mktemp -d`
#temporary directory for building other things (e.g. Latex or integrating snippets into examples)
......@@ -356,8 +414,20 @@ if ! [ -f $MYTMPDIR/${n}/doc/reference/doxygen_html_generated/index.html ]; then
exit 1;
fi
#finally, build the tarball.
echo "--> Calling tar"
tar -czf $TARBALL_NAME -C $MYTMPDIR ${n}
#build the tarball, if CREATE_TARBALL is true.
if [ "$CREATE_TARBALL" = true ]; then
echo "--> Calling tar"
tar -czf $TARBALL_NAME -C $MYTMPDIR ${n}
echo "--> Done. Created $TARBALL_NAME."
fi
#build the zip, if CREATE_ZIP is true
if [ "$CREATE_ZIP" = true ]; then
echo "--> Calling zip"
cd $MYTMPDIR
zip -r -q $ZIP_NAME ./*
mv $ZIP_NAME $REMEMBER_CUR_DIR
echo "--> Done. Created $ZIP_NAME."
fi
echo "--> Done. Created $TARBALL_NAME."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment