Skip to content

Instantly share code, notes, and snippets.

@stecman
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stecman/df35cd478039f5034e8a to your computer and use it in GitHub Desktop.
Save stecman/df35cd478039f5034e8a to your computer and use it in GitHub Desktop.
Save yourself the expense of buying cupcakes for the dev team
#!/bin/bash
#
# Make sure all untracked _ss_environment.php files use SS_SEND_ALL_EMAILS_TO
# Save yourself the expense of buying cupcakes for the dev team
#
function is_tracked() {
local filename="$1"
cd "$(dirname "$filename")"
git ls-files "$(basename "$filename")" --error-unmatch >/dev/null 2>&1
}
function is_already_configured() {
local filename="$1"
grep -l SS_SEND_ALL_EMAILS_TO "$filename" >/dev/null 2>&1
return $?
}
function update_env_file() {
local filename="$1"
local display_path='~'$( echo $filename | sed s,$HOME,, )
if is_tracked "$filename"; then
echo ".. Skipping tracked: $display_path";
continue;
fi;
if is_already_configured "$filename"; then
echo "👍 Already configured: $display_path";
continue;
fi;
echo >> $filename
echo "define('SS_SEND_ALL_EMAILS_TO', '$email');" >> $filename
echo -e "\033[0;32m✔ Fixed: $display_path\033[0m"
}
email="`whoami`@heyday.co.nz"
echo -e "Am I right that your email is: \033[1m${email}\033[0m"
read -p "Enter to confirm or type an address: " response;
if [ -n "$response" ]; then
email="$response";
echo -e "Thanks buddy, I'll use \033[1m${email}\033[0m"
sleep 2
fi
# Update each all environment files
find ~/Sites -maxdepth 4 -type f -name _ss_environment.php -or -name _env.php | \
while read file; do update_env_file "$file" "$email"; done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment