Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Created May 2, 2016 09:13
Show Gist options
  • Save willmendesneto/4a036d5378b1f817bce462a8d741effa to your computer and use it in GitHub Desktop.
Save willmendesneto/4a036d5378b1f817bce462a8d741effa to your computer and use it in GitHub Desktop.
Copy the `configuration.js` file by environment
#
# Copy the `configuration.js` file by environment
#
# How to use
#
# $ cd <your-sunbets-project>
# $ copy-config (-p|--password) (--user) (-u--url) <(-au|--au)=true (-eu|--eu)=true (-uat|--uat)=true> (-d|--dir=www-sunbets-folder)
#
# Examples:
# copy-config --user="my-user" -p="my-password" -uat=true
# copy-config --user="my-user" -p="my-password" -au=true
# copy-config --user="my-user" -p="my-password" -eu=true
#
#
# Optional values
#
# --user HTTP Basic Auth user
# -p | --password HTTP Basic Auth password
# -u | --url External url for get configurations
# -au | --au Get `configuration.js` from AU environment
# -eu | --eu Get `configuration.js` from EU environment
# -uat | --uat Get `configuration.js` from UAT environment
# -d | --dir `www-sunbets` local directory
function copy-config() {
PROJECT_DIRECTORY="$HOME/Projects/www-sunbets"
CONFIGURATION_URL="uat.test.sunbets.co.uk"
HTTP_USERNAME=""
HTTP_PASSWORD=""
for i in "$@"
do
case $i in
--user=*)
HTTP_USERNAME="${i#*=}"
shift # past argument=value
;;
-p=*|--password=*)
HTTP_PASSWORD="${i#*=}"
shift # past argument=value
;;
-u=*|--url=*)
CONFIGURATION_URL="${i#*=}"
shift # past argument=value
;;
-au=*|--au=*)
CONFIGURATION_URL="redbook-au.beta.tab.com.au"
shift # past argument=value
;;
-eu=*|--eu=*)
CONFIGURATION_URL="redbook-eu.beta.tab.com.au"
shift # past argument=value
;;
-uat=*|--uat=*)
CONFIGURATION_URL="uat.test.sunbets.co.uk"
shift # past argument=value
;;
-d=*|--dir=*)
PROJECT_DIRECTORY="${i#*=}"
shift # past argument=value
;;
--default)
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
if [ -s "$PROJECT_DIRECTORY/app/scripts/configuration.js" ]; then
echo "Creating a cache with oldest `configuration.js` file ...";
cp -f "$PROJECT_DIRECTORY/app/scripts/configuration.js" "$PROJECT_DIRECTORY/app/scripts/configuration.old.js";
fi
echo "Copying configuration of 'https://$HTTP_USERNAME:$HTTP_PASSWORD@$CONFIGURATION_URL/scripts/configuration.js' ...";
curl --insecure -L "https://$HTTP_USERNAME:$HTTP_PASSWORD@$CONFIGURATION_URL/scripts/configuration.js" > "$PROJECT_DIRECTORY/app/scripts/configuration.js"
cd "$PROJECT_DIRECTORY";
echo "All done!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment