I am trying to automate the deployment of a webapp under development that is frequently updated. The webapp comes in the form of a zip file with unknown name, and this directory structure:
unknown_name.zip
└── unknown_folder_name
└──all_the_application_files
I need a bash script to:
- remove all the contents of /var/www/ [done]
- uncompress the unknown_name.zip archive, in a given tmp path [done]
- cd inside that known tmp path [done]
- cd inside the unknown_folder_name extracted from the unknown_name.zip
- move all_the_application_files to /var/www [easy if we solve previous bullet]
Important: inside the tmp directory there will be only one directory, the one I want to go inside. My current bash script:
rm -r /var/www/*
unzip ./\*.zip \* -d /home/lese/tmp-deploy
cd /home/lese/tmp-deploy
# HERE I WOULD cd unknown_folder_name
mv * /var/www/
rm -r /var/www/*
Gah!!! What if one of the commands fails for some stupid reason beyond your control? Then you're left without /var/www. Better tomv /var/www /var/www_$(date +"%F_%T") && mkdir /var/www
.