confirming a bash script is in the right folder with wildcards?

my question is, can an if statement in a bash script confirm its current folder based on wildcards?

i am making a script to quickly place a drupal site in maintenance mode, ask if you want to keep the htaccess file, keep the sites folder and the htaccess file (if requested), update modules and the database then take the site out of maintenance mode. i have accomplished the above, but for ease of use, i would like to have one master script for all site folders, stored in a central location.

here is my script that works as designed:

#/bin/bash
CWD=$(pwd)
cd $CWD
echo $CWD
if [ $CWD = “/var/www/vhosts/specific.site.folder” ]; then
echo “Updating drupal core files”
read -r -p “do you need to keep the .htaccess file? [y/N]” response

if [ $response = y ]
then
/usr/local/bin/drush vset maintenance_mode 1
mv ./.htaccess ../.htaccess
mv ./sites ../sites
rm -rf *
cp -R /sources/drupal/* ./
mv ../sites ./sites
mv ../.htaccess ./.htaccess
chown -R httpd:httpd *
/usr/local/bin/drush up && /usr/local/bin/drush updb
/usr/local/bin/drush vset maintenance_mode 0

elif [ $response = n ]
then
/usr/local/bin/drush vset maintenance_mode 1
mv ./sites ../sites
rm -rf *
cp -R /sources/drupal/* ./
mv ../sites ./sites
chown -R httpd:httpd *
/usr/local/bin/drush up && /usr/local/bin/drush updb
/usr/local/bin/drush vset maintenance_mode 0
else
echo “Response must be either y or n”
fi
else
echo “not in a web directory, exiting”
fi

what i would like is for the same script, but something like:

if [ $CWD = “/var/www/vhosts/*” ]; then

this did not work however. i would like this to work so that the same script can run for any site, but keep other directories safe, including subdirectories on the site folder itself.

thank you in advance 🙂

if there are better ways to do anything i have there, please suggest them.

the servers that this is intended to run on are based on centos 6, but it may need to be used on a debian based machine at some point, if anything needs changing please also let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *