Follow bashstyle where possible

This commit is contained in:
Jose Diaz-Gonzalez
2015-09-14 21:20:35 -07:00
parent 1c53250211
commit 27a2478a33
20 changed files with 89 additions and 89 deletions

View File

@@ -31,7 +31,7 @@ which curl > /dev/null || apt-get install -qq -y curl
dokku_install_source() { dokku_install_source() {
apt-get install -qq -y git make software-properties-common apt-get install -qq -y git make software-properties-common
cd /root cd /root
if [ ! -d /root/dokku ]; then if [[ ! -d /root/dokku ]]; then
git clone $DOKKU_REPO /root/dokku git clone $DOKKU_REPO /root/dokku
fi fi

View File

@@ -3,15 +3,15 @@
# <UDF name="ssh_key" default="" label="Public SSH Key for root user" example="Sets the root user's public ssh key, which is also automatically imported into the dokku installer"> # <UDF name="ssh_key" default="" label="Public SSH Key for root user" example="Sets the root user's public ssh key, which is also automatically imported into the dokku installer">
# <UDF name="notify_email" default="" Label="Send Finish Notification To" example="Email address to send notification to when finished." /> # <UDF name="notify_email" default="" Label="Send Finish Notification To" example="Email address to send notification to when finished." />
function logit { logit() {
# Simple logging function that prepends an easy-to-find marker '=> ' and a timestamp to a message # Simple logging function that prepends an easy-to-find marker '=> ' and a timestamp to a message
TIMESTAMP=$(date -u +'%m/%d %H:%M:%S') TIMESTAMP=$(date -u +'%m/%d %H:%M:%S')
MSG="=> ${TIMESTAMP} $1" MSG="=> ${TIMESTAMP} $1"
echo ${MSG} echo ${MSG}
} }
function set_ssh_key { set_ssh_key() {
if [ -n "${SSH_KEY}" ]; then if [[ -n "${SSH_KEY}" ]]; then
logit "Setting root ssh key" logit "Setting root ssh key"
mkdir -p /root/.ssh mkdir -p /root/.ssh
chmod 700 /root/.ssh chmod 700 /root/.ssh
@@ -21,20 +21,20 @@ function set_ssh_key {
fi fi
} }
function set_passwordless_ssh { set_passwordless_ssh() {
logit "Turn off password authentication and root login for SSH" logit "Turn off password authentication and root login for SSH"
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
service ssh restart service ssh restart
} }
function system_primary_ip { system_primary_ip() {
# returns the primary IP assigned to eth0 # returns the primary IP assigned to eth0
ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }' ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }'
} }
function set_hostname { set_hostname() {
logit "Set up hostname" logit "Set up hostname"
if [ -n "${HOSTNAME}" ]; then if [[ -n "${HOSTNAME}" ]]; then
echo $HOSTNAME > /etc/hostname echo $HOSTNAME > /etc/hostname
echo $IPADDR $FQDN $HOSTNAME >> /etc/hosts echo $IPADDR $FQDN $HOSTNAME >> /etc/hosts
else else
@@ -46,7 +46,7 @@ function set_hostname {
hostname -F /etc/hostname hostname -F /etc/hostname
} }
function postfix_install_loopback_only { postfix_install_loopback_only() {
logit "Installing and configuring Postfix" logit "Installing and configuring Postfix"
# Installs postfix and configure to listen only on the local interface. Also # Installs postfix and configure to listen only on the local interface. Also
# allows for local mail delivery # allows for local mail delivery
@@ -62,8 +62,8 @@ function postfix_install_loopback_only {
touch /tmp/restart-postfix touch /tmp/restart-postfix
} }
function notify_install_via_email { notify_install_via_email() {
if [ -n "${NOTIFY_EMAIL}" ]; then if [[ -n "${NOTIFY_EMAIL}" ]]; then
logit "Sending notification email to ${NOTIFY_EMAIL}" logit "Sending notification email to ${NOTIFY_EMAIL}"
/usr/sbin/sendmail "${NOTIFY_EMAIL}" <<EOD /usr/sbin/sendmail "${NOTIFY_EMAIL}" <<EOD
To: ${NOTIFY_EMAIL} To: ${NOTIFY_EMAIL}
@@ -77,8 +77,8 @@ EOD
fi fi
} }
function notify_restart_via_email { notify_restart_via_email() {
if [ -n "${NOTIFY_EMAIL}" ]; then if [[ -n "${NOTIFY_EMAIL}" ]]; then
logit "Sending notification email to ${NOTIFY_EMAIL} of required restart" logit "Sending notification email to ${NOTIFY_EMAIL} of required restart"
/usr/sbin/sendmail "${NOTIFY_EMAIL}" <<EOD /usr/sbin/sendmail "${NOTIFY_EMAIL}" <<EOD
To: ${NOTIFY_EMAIL} To: ${NOTIFY_EMAIL}
@@ -103,7 +103,7 @@ EOD
fi fi
} }
function setup_linode { setup_linode() {
logit "Installing via linode" logit "Installing via linode"
DEBIAN_FRONTEND=noninteractive apt-get install -qq -y linux-virtual DEBIAN_FRONTEND=noninteractive apt-get install -qq -y linux-virtual
DEBIAN_FRONTEND=noninteractive apt-get purge -qq -y grub2 grub-pc DEBIAN_FRONTEND=noninteractive apt-get purge -qq -y grub2 grub-pc
@@ -133,7 +133,7 @@ EOF
chmod +x /etc/rc.local chmod +x /etc/rc.local
} }
function install_prerequisites { install_prerequisites() {
logit "Installing pre-requisites" logit "Installing pre-requisites"
sudo apt-get update -qq > /dev/null sudo apt-get update -qq > /dev/null
sudo apt-get install -qq -y apt-transport-https curl > /dev/null 2>&1 sudo apt-get install -qq -y apt-transport-https curl > /dev/null 2>&1
@@ -147,7 +147,7 @@ function install_prerequisites {
sudo apt-get update -qq > /dev/null sudo apt-get update -qq > /dev/null
} }
function install_dokku { install_dokku() {
logit "Installing pre-requisites" logit "Installing pre-requisites"
sudo apt-get install -qq -y linux-image-extra-"$(uname -r)" > /dev/null 2>&1 sudo apt-get install -qq -y linux-image-extra-"$(uname -r)" > /dev/null 2>&1
@@ -165,7 +165,7 @@ postfix_install_loopback_only
set_hostname set_hostname
install_prerequisites install_prerequisites
if [ -n "$LINODE_ID" ]; then if [[ -n "$LINODE_ID" ]]; then
setup_linode setup_linode
notify_restart_via_email notify_restart_via_email
else else

View File

@@ -191,7 +191,7 @@ do
fi fi
done done
if [ $FAILEDCHECKS -gt 0 ]; then if [[ $FAILEDCHECKS -gt 0 ]]; then
dokku_log_warn "Check attempt $ATTEMPT/$ATTEMPTS failed." dokku_log_warn "Check attempt $ATTEMPT/$ATTEMPTS failed."
SUCCESS=0 SUCCESS=0
else else
@@ -199,7 +199,7 @@ do
fi fi
done done
if [ $FAILEDCHECKS -gt 0 ]; then if [[ $FAILEDCHECKS -gt 0 ]]; then
dokku_log_fail "Could not start due to $FAILEDCHECKS failed checks." dokku_log_fail "Could not start due to $FAILEDCHECKS failed checks."
exit 1 exit 1
fi fi

View File

@@ -48,7 +48,7 @@ config_parse_args() {
config_create () { config_create () {
local ENV_FILE=$1 local ENV_FILE=$1
[ -f $ENV_FILE ] || touch $ENV_FILE [[ -f $ENV_FILE ]] || touch $ENV_FILE
} }
config_styled_hash () { config_styled_hash () {
@@ -58,7 +58,7 @@ config_styled_hash () {
while read -r word; do while read -r word; do
KEY=$(echo $word | cut -d"=" -f1) KEY=$(echo $word | cut -d"=" -f1)
if [ ${#KEY} -gt ${#longest} ]; then if [[ ${#KEY} -gt ${#longest} ]]; then
longest=$KEY longest=$KEY
fi fi
done <<< "$vars" done <<< "$vars"
@@ -69,7 +69,7 @@ config_styled_hash () {
num_zeros=$((${#longest} - ${#KEY})) num_zeros=$((${#longest} - ${#KEY}))
zeros=" " zeros=" "
while [ $num_zeros -gt 0 ]; do while [[ $num_zeros -gt 0 ]]; do
zeros="$zeros " zeros="$zeros "
num_zeros=$((num_zeros - 1)) num_zeros=$((num_zeros - 1))
done done
@@ -181,7 +181,7 @@ ${var}"
done done
ENV_ADD=$(echo "$ENV_ADD" | tail -n +2) #remove first empty line ENV_ADD=$(echo "$ENV_ADD" | tail -n +2) #remove first empty line
if [ $RESTART_APP ]; then if [[ $RESTART_APP ]]; then
dokku_log_info1 "Setting config vars" dokku_log_info1 "Setting config vars"
config_styled_hash "$ENV_ADD" " " config_styled_hash "$ENV_ADD" " "

View File

@@ -66,7 +66,7 @@ display_passed_phases_options() {
local phase local phase
for phase in "${passed_phases[@]}"; do for phase in "${passed_phases[@]}"; do
get_phase_file_path $phase get_phase_file_path $phase
if [ ! -s $phase_file_path ] ; then if [[ ! -s $phase_file_path ]]; then
echo "${phase^} options: none" echo "${phase^} options: none"
else else
display_phase_options $phase $phase_file_path display_phase_options $phase $phase_file_path

View File

@@ -31,8 +31,7 @@ case "$1" in
git-hook) git-hook)
APP=$2 APP=$2
while read oldrev newrev refname while read oldrev newrev refname; do
do
# Only run this script for the master branch. You can remove this # Only run this script for the master branch. You can remove this
# if block if you wish to run it for others as well. # if block if you wish to run it for others as well.
if [[ $refname = "refs/heads/master" ]]; then if [[ $refname = "refs/heads/master" ]]; then

View File

@@ -5,7 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
APP="$1"; REV="$2" APP="$1"; REV="$2"
# Don't trigger git build if there is no git repository. # Don't trigger git build if there is no git repository.
if [ ! -d "$DOKKU_ROOT/$APP/refs" ]; then if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then
true true
else else
dokku git-build $APP $REV dokku git-build $APP $REV

View File

@@ -4,8 +4,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
print_dokku_scale_file() { print_dokku_scale_file() {
local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
while read line || [ -n "$line" ] while read line || [[ -n "$line" ]]; do
do
dokku_log_info2_quiet "$line" dokku_log_info2_quiet "$line"
done < "$DOKKU_SCALE_FILE" done < "$DOKKU_SCALE_FILE"
} }

View File

@@ -25,7 +25,7 @@ case "$1" in
line=$(echo $line | trim) line=$(echo $line | trim)
CMD=$(echo $line | awk '{ print $1 }') CMD=$(echo $line | awk '{ print $1 }')
[ -z $CMD ] && continue [[ -z $CMD ]] && continue
[[ "$line" != "$(fc -ln -1 | trim)" ]] && history -s "$line" [[ "$line" != "$(fc -ln -1 | trim)" ]] && history -s "$line"

View File

@@ -5,7 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
APP="$1"; REV="$2" APP="$1"; REV="$2"
# Don't trigger tar build if there is no tarball. # Don't trigger tar build if there is no tarball.
if [ ! -f "$DOKKU_ROOT/$APP/src.tar" ]; then if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
true true
else else
dokku tar-build $APP dokku tar-build $APP

View File

@@ -12,7 +12,7 @@ TEST_APP=my-cool-guy-test-app
# test functions # test functions
flunk() { flunk() {
{ if [ "$#" -eq 0 ]; then cat - { if [[ "$#" -eq 0 ]]; then cat -
else echo "$*" else echo "$*"
fi fi
} }
@@ -20,23 +20,23 @@ flunk() {
} }
assert_success() { assert_success() {
if [ "$status" -ne 0 ]; then if [[ "$status" -ne 0 ]]; then
flunk "command failed with exit status $status" flunk "command failed with exit status $status"
elif [ "$#" -gt 0 ]; then elif [[ "$#" -gt 0 ]]; then
assert_output "$1" assert_output "$1"
fi fi
} }
assert_failure() { assert_failure() {
if [ "$status" -eq 0 ]; then if [[ "$status" -eq 0 ]]; then
flunk "expected failed exit status" flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then elif [[ "$#" -gt 0 ]]; then
assert_output "$1" assert_output "$1"
fi fi
} }
assert_equal() { assert_equal() {
if [ "$1" != "$2" ]; then if [[ "$1" != "$2" ]]; then
{ echo "expected: $1" { echo "expected: $1"
echo "actual: $2" echo "actual: $2"
} | flunk } | flunk
@@ -45,34 +45,36 @@ assert_equal() {
assert_output() { assert_output() {
local expected local expected
if [ $# -eq 0 ]; then expected="$(cat -)" if [[ $# -eq 0 ]]; then
else expected="$1" expected="$(cat -)"
else
expected="$1"
fi fi
assert_equal "$expected" "$output" assert_equal "$expected" "$output"
} }
assert_line() { assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then if [[ "$1" -ge 0 ]] 2>/dev/null; then
assert_equal "$2" "${lines[$1]}" assert_equal "$2" "${lines[$1]}"
else else
local line local line
for line in "${lines[@]}"; do for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then return 0; fi [[ "$line" = "$1" ]] && return 0
done done
flunk "expected line \`$1'" flunk "expected line \`$1'"
fi fi
} }
refute_line() { refute_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then if [[ "$1" -ge 0 ]] 2>/dev/null; then
local num_lines="${#lines[@]}" local num_lines="${#lines[@]}"
if [ "$1" -lt "$num_lines" ]; then if [[ "$1" -lt "$num_lines" ]]; then
flunk "output has $num_lines lines" flunk "output has $num_lines lines"
fi fi
else else
local line local line
for line in "${lines[@]}"; do for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then if [[ "$line" = "$1" ]]; then
flunk "expected to not find line \`$line'" flunk "expected to not find line \`$line'"
fi fi
done done