Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Shellcheck - shellscript syntax improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDaveHello committed Jan 6, 2017
1 parent f575540 commit 6c3e581
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
13 changes: 6 additions & 7 deletions backup.sh
Expand Up @@ -9,7 +9,7 @@ set -e
# Be somewhere predictable.
# =========================

cd "`dirname $0`"
cd "$(dirname "$0")"


# Helpers
Expand All @@ -19,7 +19,7 @@ confirm () {
proceed=""
while [ "$proceed" != "y" ]; do
read -p"$1 (y/N) " proceed
if [ "$proceed" == "n" -o "$proceed" == "N" -o "$proceed" == "" ]
if [ "$proceed" == "n" ] || [ "$proceed" == "N" ] || [ "$proceed" == "" ]
then
return 1
fi
Expand All @@ -28,15 +28,15 @@ confirm () {
}

require () {
if [ ! `which $1` ]; then
if [ ! "$(which "$1")" ]; then
echo "The '$1' command was not found."
return 1
fi
return 0
}

get_filepath () {
TODAY="`date +%F`"
TODAY="$(date +%F)"
CANDIDATE="$DIRPATH/$TODAY.psql"
if [ -f "$CANDIDATE" ]
then
Expand Down Expand Up @@ -76,8 +76,7 @@ then
exit "Too many backups!"
fi

confirm "Backup the Gratipay database to $FILEPATH?"
if [ $? -eq 0 ]; then
if confirm "Backup the Gratipay database to $FILEPATH?"; then
export PGSSLMODE=require
pg_dump `heroku config:get DATABASE_URL -a gratipay` > $FILEPATH
pg_dump "$(heroku config:get DATABASE_URL -a gratipay)" > "$FILEPATH"
fi
2 changes: 1 addition & 1 deletion bin/sync-npm.sh
Expand Up @@ -3,7 +3,7 @@
# sync our database with the npm registry.

set -e
cd "`dirname $0`/.."
cd "$(dirname "$0")/.."

# Install dependencies.
# =====================
Expand Down
8 changes: 4 additions & 4 deletions deploy.sh
Expand Up @@ -6,7 +6,7 @@ set -e


# Be somewhere predictable
cd "`dirname $0`"
cd "$(dirname "$0")"


# Helpers
Expand All @@ -21,7 +21,7 @@ yesno () {
}

require () {
if [ ! `which $1` ]; then
if [ ! "$(which "$1")" ]; then
echo "The '$1' command was not found."
exit 1
fi
Expand All @@ -35,7 +35,7 @@ require curl


# Make sure we have the latest master
if [ "`git rev-parse --abbrev-ref HEAD`" != "master" ]; then
if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
echo "Not on master, checkout master first."
exit
fi
Expand All @@ -54,7 +54,7 @@ heroku config -s -a gratipay | ./env/bin/honcho run -e /dev/stdin \

# Sync the translations
echo "Syncing translations ..."
if [ ! -e .transifexrc -a ! -e ~/.transifexrc ]; then
if [ ! -e .transifexrc ] && [ ! -e ~/.transifexrc ]; then
heroku config -s -a gratipay | ./env/bin/honcho run -e /dev/stdin make transifexrc
fi
make i18n_upload
Expand Down
22 changes: 11 additions & 11 deletions payday.sh
Expand Up @@ -9,13 +9,13 @@ set -e
# Be somewhere predictable.
# =========================

cd "`dirname $0`"
cd "$(dirname "$0")"


# --help
# ======

if [ $# = 0 -o "$1" = "" ]; then
if [ $# = 0 ] || [ "$1" = "" ]; then
echo
echo "Usage: $0 <number> [\"for_real_please\"]"
echo
Expand All @@ -40,7 +40,7 @@ confirm () {
proceed=""
while [ "$proceed" != "y" ]; do
read -p"$1 (y/N) " proceed
if [ "$proceed" == "n" -o "$proceed" == "N" -o "$proceed" == "" ]
if [ "$proceed" == "n" ] || [ "$proceed" == "N" ] || [ "$proceed" == "" ]
then
return 1
fi
Expand All @@ -49,7 +49,7 @@ confirm () {
}

require () {
if [ ! `which $1` ]; then
if [ ! "$(which "$1")" ]; then
echo "The '$1' command was not found."
exit 1
fi
Expand All @@ -58,8 +58,8 @@ require () {

start () {
echo "Logging to $LOG."
echo >> $LOG
date -u >> $LOG
echo >> "$LOG"
date -u >> "$LOG"
}


Expand All @@ -72,11 +72,11 @@ else
LOG="../logs/payday/test-$1.log"
fi

if [ -f $LOG ]; then
if [ -f "$LOG" ]; then
RUN="Rerun"
else
# If the path is bad the next line will fail and we'll exit.
touch $LOG
touch "$LOG"
RUN="Run"
fi

Expand All @@ -89,12 +89,12 @@ confirm "$RUN payday #$1?" || exit 0
case "$2" in
"")
start
honcho run -e defaults.env,local.env ./env/bin/payday >>$LOG 2>&1 &
honcho run -e defaults.env,local.env ./env/bin/payday >> "$LOG" 2>&1 &
;;
"for_real_please")
confirm "$RUN payday #$1 FOR REAL?!?!?!??!?!?" || exit 0
start
heroku config -s -a gratipay | ./env/bin/honcho run -e /dev/stdin ./env/bin/payday >>$LOG 2>&1 &
heroku config -s -a gratipay | ./env/bin/honcho run -e /dev/stdin ./env/bin/payday >> "$LOG" 2>&1 &
;;
*)
echo "Your second arg was $2. Wazzat mean?"
Expand All @@ -103,4 +103,4 @@ case "$2" in
esac

disown -a
tail -f $LOG
tail -f "$LOG"
8 changes: 4 additions & 4 deletions recreate-schema.sh
Expand Up @@ -15,23 +15,23 @@ echo "==========================================================================
# whole.

echo "Recreating public schema ... "
echo "DROP SCHEMA public CASCADE" | psql $DATABASE_URL
echo "CREATE SCHEMA public" | psql $DATABASE_URL
echo "DROP SCHEMA public CASCADE" | psql "$DATABASE_URL"
echo "CREATE SCHEMA public" | psql "$DATABASE_URL"


echo "=============================================================================="
echo "Applying sql/schema.sql ..."
echo

psql $DATABASE_URL < sql/schema.sql
psql "$DATABASE_URL" < sql/schema.sql


echo "=============================================================================="
echo "Looking for sql/branch.sql ..."
echo

if [ -f sql/branch.sql ]
then psql $DATABASE_URL < sql/branch.sql
then psql "$DATABASE_URL" < sql/branch.sql
else
echo "None found. That's cool. You only need a sql/branch.sql file if you want to "
echo "include schema changes with your pull request."
Expand Down
6 changes: 3 additions & 3 deletions scripts/bootstrap-debian.sh
Expand Up @@ -41,17 +41,17 @@ sudo apt-get install -y \

echo "[*] Checking if current user has access to create databases.."

if [ -z ""`sudo -i -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER'"` ];
if [ -z "$(sudo -i -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER'")" ];
then
echo "'$USER' entry does not exist in PostgreSQL, creating.."
sudo -i -u postgres createuser --superuser $USER
sudo -i -u postgres createuser --superuser "$USER"
fi;


echo "[*] Creating databases.."

db_exists() {
if [ -n ""`psql template1 -tAc "select datname from pg_database where datname='$1'"` ];
if [ -n "$(psql template1 -tAc "select datname from pg_database where datname='$1'")" ];
then
return 0;
fi
Expand Down

0 comments on commit 6c3e581

Please sign in to comment.