From 46af218046f44b9d874478a9353895b95c246add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 16 Feb 2022 12:00:42 +0100 Subject: [PATCH] add confirmation dialog before initializing template --- init.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index 0a20110..df51dda 100755 --- a/init.sh +++ b/init.sh @@ -4,12 +4,30 @@ if [[ $(pwd) == *template* ]] then echo "Don't run this in the template directory!" echo "Rename the current folder or edit init.sh to do this anyways" - exit + echo "The folder name must not contain the name 'template' or build will be aborted" + exit 1 +fi + +source config + +# More safety second +echo "--------------------------------------------------------" +echo "THIS SCRIPT WILL NOW IRREVOCABLY DESTROY THIS TEMPLATE " +echo "REPOSITORY AND REPLACE IT WITH A NEW ONE WITH YOUR GIVEN" +echo "PARAMETERS IN 'config'. " +echo "ALL PRIOR DATA, INCLUDING BUT NOT LIMITED TO THE GIT " +echo "HISTORY IN THIS DIRECTORY AND ALL ITS SUBDIRECTORIES " +echo "WILL BE LOST. " +echo " " + +read -p "ARE YOU SURE YOU WANT TO CONTINUE? (y/n) " -n 1 -r +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + exit 1 fi { ## DO NOT REMOVE THIS OR EVERYTHING BLOWS UP cat config -source config cd template find -type f | xargs sed -i "s/\$mainfile/$(printf '%s\n' "$mainfile" | sed -e 's/[\/&]/\\&/g')/g" find -type f | xargs sed -i "s/\$course/$(printf '%s\n' "$course" | sed -e 's/[\/&]/\\&/g')/g"