Skip to content

Instantly share code, notes, and snippets.

@boldfield
Last active December 29, 2015 00:49
Show Gist options
  • Save boldfield/7588270 to your computer and use it in GitHub Desktop.
Save boldfield/7588270 to your computer and use it in GitHub Desktop.
Simple environment manager for use in WAL-E development.
#!/bin/bash
if [ -z $WALE_ENV_DIR ]
then
WALE_ENV_DIR='/etc/wal-e/env'
fi
STORE=$(echo $1 | tr '[:upper:]' '[:lower:]')
USTORE=$(echo $STORE | tr '[:lower:]' '[:upper:]')
BOX=$(echo $2 | tr '[:upper:]' '[:lower:]')
print_environment() {
for file in $(find $WALE_ENV_DIR -type l)
do
echo $file
if [[ $file =~ "PREFIX" ]]
then
echo "Current WAL-E Prefix: $(cat $file)"
fi
done
}
unlink_env() {
echo "Cleaning previous environment configuration..."
find $WALE_ENV_DIR -type l -exec rm -i {} +
}
make_link() {
source=$1
destination=$2
root=$(dirname $WALE_ENV_DIR)
ln -s $root/$source $WALE_ENV_DIR/$destination
}
case $USTORE in
AWS)
access_id_file=AWS_ACCESS_KEY_ID
secret_file=AWS_SECRET_ACCESS_KEY
prefix_link_name=WALE_S3_PREFIX
testing_link_name=WALE_S3_INTEGRATION_TESTS
;;
WABS)
access_id_file=WABS_ACCESS_KEY
secret_file=WABS_ACCOUNT_NAME
prefix_link_name=WALE_WABS_PREFIX
testing_link_name=WALE_WABS_INTEGRATION_TESTS
;;
SHOW)
print_environment
exit 0
;;
*)
echo "Unknown storage backend: ${USTORE}"
exit 1
esac
# Unlink previously existing environment
unlink_env
# Link requested environment
echo "Linking requested WAL-E environment..."
make_link $access_id_file $access_id_file
make_link $secret_file $secret_file
if [[ "$BOX" == "TESTING" ]]
then
make_link TESTING_FILE $testing_link_name
else
make_link "${BOX}-${STORE}" $prefix_link_name
fi
echo "Eeeeeevaaa"
@boldfield
Copy link
Author

WAL-E is a project to help simplify PostgreSQL WAL file archiving and recovery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment