Skip to content

Instantly share code, notes, and snippets.

@bmwant
Last active April 22, 2018 09:34
Show Gist options
  • Save bmwant/b3a41307e074d3e9b00511ed47d9a003 to your computer and use it in GitHub Desktop.
Save bmwant/b3a41307e074d3e9b00511ed47d9a003 to your computer and use it in GitHub Desktop.
Some shell hints and boilerplate code
#!/usr/bin/env bash
set -ex
## This is current directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
######
# Add variables to travis encrypted section
######
#awk -F '=' '{ print $2 }' creds
#travis encrypt SOMEVAR="secretvalue" --add
while read p; do
KEY=$(echo $p | awk -F '=' '{print $1}')
VALUE=$(echo $p | awk -F '=' '{print $2}')
echo "${KEY},${VALUE}"
travis encrypt "${KEY}"="${VALUE}" --add
done <creds.txt
######
# grab same environment from supervisor config file
######
ls /etc/supervisor/conf.d
ENV=$(cat /etc/supervisor/conf.d/myapp.conf | grep environment | cut -d '=' -f 2-)
IFS=',' read -ra RESS <<< "$ENV"
touch env.sh
for line in "${RESS[@]}"; do
echo "export ${line}" >> env.sh
done
cat env.sh # Make sure at this point you have valid file and none of variables will
# conflict with your current env. Edit with vim manually if needed.
source env.sh
######
# run sql files within a directory (postgresq)
######
for file in $files; do
echo -e "\n--- $file"
psql --username $user --host $server --file $file --dbname $dbname
done;
######
# default values for variables
######
FOO=${VARIABLE:-default} # If variable not set or null, use default.
FOO=${VARIABLE:=default} # If variable not set or null, set it to default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment