Skip to content

Instantly share code, notes, and snippets.

@Pindar
Last active August 29, 2015 14:16
Show Gist options
  • Save Pindar/300d3424f05410ad7c04 to your computer and use it in GitHub Desktop.
Save Pindar/300d3424f05410ad7c04 to your computer and use it in GitHub Desktop.
set-env.sh
#!/bin/bash
FILE=${1}
ENVIRONMENT=${2}
SERVICE_NAME=${3}
ETCD=${4:-"127.0.0.1:4001"}
if [[ $FILE == "" || $ENVIRONMENT == "" || SERVICE_NAME == "" ]]; then
echo "Please specify file, environment and service name"
echo "Usage: ./set-env.sh pwd/fileenv staging myservice"
exit 1;
fi
while read -r line || [[ -n $line ]]
do
if [[ `echo $line | grep -c -e '^$'` -eq 1 ]]; then
continue;
fi
if [[ `echo $line | grep -c "^#"` -eq 1 ]]; then
continue;
fi
KEY=`echo $line | cut -d "=" -sf 1`
VALUE=`echo $line | cut -d "=" -sf 2-`
echo [set-env] set /$ENVIRONMENT/$SERVICE_NAME/$KEY "$VALUE"
echo "${VALUE}" | etcdctl --peers $ETCD set /$ENVIRONMENT/$SERVICE_NAME/$KEY
done < $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment