Skip to content

Commit

Permalink
remove tailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
DennyZhang committed Apr 25, 2016
1 parent 08a1769 commit 5e795f2
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 116 deletions.
48 changes: 24 additions & 24 deletions bash/backup_dir/backup_dir.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#!/bin/bash -e
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : backup_dir.sh
## Author : Denny <[email protected]>
## Description : Backup directory and tar it with timestamp
## --
## Created : <2015-04-21>
## Updated: Time-stamp: <2016-04-19 21:09:46>
## Updated: Time-stamp: <2016-04-25 11:16:04>
##-------------------------------------------------------------------

## Trap exit and dump status
function shell_exit() {
if [ $? -eq 0 ]; then
log "Backup operation is done"
log "########## Backup operation is done #############################"
echo "State: DONE Timestamp: $(current_time)" >> $STATUS_FILE
echo "State: DONE Timestamp: $(current_time)" >> "$STATUS_FILE"
else
log "ERROR: Backup operation fail"
log "########## ERROR: Backup operation fail #########################"
echo "State: FAILED Timestamp: $(current_time)" >> $STATUS_FILE
echo "State: FAILED Timestamp: $(current_time)" >> "$STATUS_FILE"
# TODO: send out email
exit 1
fi
Expand All @@ -31,17 +31,17 @@ function log() {
local msg=${1?}
echo -ne `date +['%Y-%m-%d %H:%M:%S']`" $msg\n"
if [ -n "$BACKUP_LOG_FILE" ]; then
echo -ne `date +['%Y-%m-%d %H:%M:%S']`" $msg\n" >> $BACKUP_LOG_FILE
echo -ne `date +['%Y-%m-%d %H:%M:%S']`" $msg\n" >> "$BACKUP_LOG_FILE"
fi
}

function tar_dir() {
local dir=${1?}
local tar_file=${2?}
working_dir=`dirname $dir`
cd $working_dir
log "tar -zcf $tar_file `basename $dir`"
tar -zcf $tar_file `basename $dir`
working_dir=`dirname "$dir"`
cd "$working_dir"
log "tar -zcf $tar_file `basename "$dir"`"
tar -zcf "$tar_file" `basename "$dir"`
}

function current_time() {
Expand All @@ -58,34 +58,34 @@ function ensure_is_root() {
################################################################
function backup_dir()
{
cd $DST_DIR
declare -a backup_list=$(echo $BACKUP_DIR | tr ';' ' ')
cd "$DST_DIR"
declare -a backup_list=$(echo "$BACKUP_DIR" | tr ';' ' ')
for item in ${backup_list[*]}; do
if [ -f $item ] || [ -d $item ]; then
dir_name=$(dirname $item)
if [ -f "$item" ] || [ -d "$item" ]; then
dir_name=$(dirname "$item")
mkdir -p "$DST_DIR/$backup_id/$dir_name/"
log "cp -r $item $DST_DIR/$backup_id/$dir_name/"
cp -r $item "$DST_DIR/$backup_id/$dir_name/"
cp -r "$item" "$DST_DIR/$backup_id/$dir_name/"
fi
done;
}

function archieve_backup() {
set -e
cd $DST_DIR
tar_dir $backup_id $backup_id.tar.gz
cd "$DST_DIR"
tar_dir "$backup_id" "${backup_id}.tar.gz"
log "rm -rf $backup_id"
rm -rf $backup_id
rm -rf "$backup_id"
}

function expire_old_backup() {
set -e
cd $DST_DIR
if [ $RETENTION_DAYS -eq 0 ]; then
cd "$DST_DIR"
if [ "$RETENTION_DAYS" -eq 0 ]; then
log "RETENTION_DAYS Parameter is 0, skip backup set retention"
else
log "find $DST_DIR -name \"*.gz\" -mtime +$RETENTION_DAYS -and -not -type d -delete"
find $DST_DIR -name "*.gz" -mtime +$RETENTION_DAYS -and -not -type d -delete
find "$DST_DIR" -name "*.gz" -mtime "+$RETENTION_DAYS" -and -not -type d -delete
fi
}

Expand All @@ -110,15 +110,15 @@ ensure_is_root
trap shell_exit SIGHUP SIGINT SIGTERM 0

# source file
if [ -f $BACKUP_RC_FILE ]; then
. $BACKUP_RC_FILE
if [ -f "$BACKUP_RC_FILE" ]; then
. "$BACKUP_RC_FILE"
fi

set_default_value

if [ -n "$BACKUP_LOG_FILE" ]; then
log_dir=`dirname $BACKUP_LOG_FILE`
[ -d $log_dir ] || mkdir -p $log_dir
log_dir=`dirname "$BACKUP_LOG_FILE"`
[ -d "$log_dir" ] || mkdir -p "$log_dir"
fi

# Format: +%Y-%m-%d-%H%M%S_$pid
Expand Down
21 changes: 11 additions & 10 deletions bash/enforce_all_nagios_check/enforce_all_nagios_check.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : enforce_all_nagios_check.sh
## Author : Denny <[email protected]>
## Description :
## --
## Created : <2015-06-24>
## Updated: Time-stamp: <2016-04-19 21:09:50>
## Updated: Time-stamp: <2016-04-25 11:16:04>
##-------------------------------------------------------------------
skip_check_pattern=${1:-""}
ignore_check_warn=${2:-"0"}
Expand All @@ -20,29 +20,30 @@ if [ -z "$nagios_check_dir" ]; then
nagios_check_dir="/etc/nagios3/conf.d/$server_name"
fi

if [ ! -d $nagios_check_dir ]; then
if [ ! -d "$nagios_check_dir" ]; then
echo "ERROR: $nagios_check_dir doesn't exist"
exit 1
fi
cd $nagios_check_dir

cd "$nagios_check_dir"

failed_checks=""
skipped_checks=""
IFS=$'\n'
for f in `ls -1 *.cfg`; do
if grep '^ *host_name *' $f 2>/dev/null 1>/dev/null; then
if grep '^ *host_name *' "$f" 2>/dev/null 1>/dev/null; then
host_name=$(grep '^ *host_name *' $f | awk -F' ' '{print $2}' | head -n 1)
for check in `grep '^ *check_command' $f | awk -F' ' "{print $2}" | awk -F'!' '{print $2}'`; do
for check in `grep '^ *check_command' "$f" | awk -F' ' "{print $2}" | awk -F'!' '{print $2}'`; do
command="/usr/lib/nagios/plugins/check_nrpe -H $host_name -c $check"
if [ -n "$skip_check_pattern" ]; then
if echo $check | grep -iE "$skip_check_pattern" 2>/dev/null 1>/dev/null; then
if echo "$check" | grep -iE "$skip_check_pattern" 2>/dev/null 1>/dev/null; then
echo "skip check: $command"
skipped_checks="${skipped_checks}${check};"
continue
fi
fi
echo $command
output=`eval $command`
echo "$command"
output=`eval "$command"`
errcode=$?
# check fail
if [ $errcode -ge 2 ]; then
Expand All @@ -51,7 +52,7 @@ for f in `ls -1 *.cfg`; do
fi

if [ $errcode -eq 1 ]; then
if [ "$ignore_check_warn" = "1" ] && echo $output | grep WARN 2>&1 1>/dev/null; then
if [ "$ignore_check_warn" = "1" ] && echo "$output" | grep WARN 1>/dev/null 2>&1; then
echo "skip failed warn check: $command"
skiped_checks="${skiped_checks}${check};"
continue
Expand Down
26 changes: 13 additions & 13 deletions bash/git_update.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash -e
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : git_update.sh
## Author : Denny <[email protected]>
## Description :
## --
## Created : <2016-04-15>
## Updated: Time-stamp: <2016-04-19 21:09:53>
## Updated: Time-stamp: <2016-04-25 11:16:04>
##-------------------------------------------------------------------
working_dir=${1?}
git_repo_url=${2?}
Expand All @@ -21,24 +21,24 @@ function git_update_code() {
local working_dir=${2?}
local git_repo_url=${3?}

git_repo=$(echo ${git_repo_url%.git} | awk -F '/' '{print $2}')
git_repo=$(echo "${git_repo_url%.git}" | awk -F '/' '{print $2}')
echo "Git update code for '$git_repo_url' to $working_dir, branch_name: $branch_name"
# checkout code, if absent
if [ ! -d $working_dir/$branch_name/$git_repo ]; then
mkdir -p $working_dir/$branch_name
cd $working_dir/$branch_name
git clone --depth 1 $git_repo_url --branch $branch_name --single-branch
if [ ! -d "$working_dir/$branch_name/$git_repo" ]; then
mkdir -p "$working_dir/$branch_name"
cd "$working_dir/$branch_name"
git clone --depth 1 "$git_repo_url" --branch "$branch_name" --single-branch
else
cd $working_dir/$branch_name/$git_repo
git config remote.origin.url $git_repo_url
cd "$working_dir/$branch_name/$git_repo"
git config remote.origin.url "$git_repo_url"
# add retry for network turbulence
git pull origin $branch_name || (sleep 2 && git pull origin $branch_name)
git pull origin "$branch_name" || (sleep 2 && git pull origin "$branch_name")
fi

cd $working_dir/$branch_name/$git_repo
git checkout $branch_name
cd "$working_dir/$branch_name/$git_repo"
git checkout "$branch_name"
git reset --hard
}

git_update_code $branch_name $working_dir $git_repo_url
git_update_code "$branch_name" "$working_dir" "$git_repo_url"
## File : git_update.sh ends
30 changes: 15 additions & 15 deletions bash/inject_ssh_key/inject_ssh_key.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash -e
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : inject_ssh_key.sh
## Author : Denny <[email protected]>
## Description :
## --
## Created : <2015-05-13>
## Updated: Time-stamp: <2016-04-19 21:09:57>
## Updated: Time-stamp: <2016-04-25 11:16:04>
##-------------------------------------------------------------------
user_home_list=${1?"To who the ssh key shall be injected. Users are separated by comma"}
ssh_email=${2?"email associated to this ssh key"}
Expand All @@ -21,23 +21,23 @@ function inject_ssh_key() {
local ssh_email=${3?}
local ssh_key=${4?}

if [ ! -d $home_dir/.ssh ] ; then
if [ ! -d "${home_dir}/.ssh" ] ; then
echo "sudo mkdir -p $home_dir/.ssh"
mkdir -p $home_dir/.ssh
chown $username:$username $home_dir/.ssh
mkdir -p "${home_dir}/.ssh"
chown "${username}:${username}" "${home_dir}/.ssh"
fi

if [ ! -f $home_dir/.ssh/authorized_keys ]; then
if [ ! -f "${home_dir}/.ssh/authorized_keys" ]; then
echo "touch $home_dir/.ssh/authorized_keys"
touch $home_dir/.ssh/authorized_keys
chmod 644 $home_dir/.ssh/authorized_keys
chown $username:$username $home_dir/.ssh/authorized_keys
touch "${home_dir}/.ssh/authorized_keys"
chmod 644 "${home_dir}/.ssh/authorized_keys"
chown "${username}:${username}" "${home_dir}/.ssh/authorized_keys"
fi

if ! grep $ssh_key $home_dir/.ssh/authorized_keys 1>/dev/null; then
if ! grep "$ssh_key" "${home_dir}/.ssh/authorized_keys" 1>/dev/null; then
command="echo \"ssh-rsa $ssh_key $ssh_email\" >> $home_dir/.ssh/authorized_keys"
echo $command
eval $command
echo "$command"
eval "$command"
else
echo "Skip. ssh key is already in $home_dir/.ssh/authorized_keys"
fi
Expand All @@ -50,11 +50,11 @@ if [[ $EUID -ne 0 ]]; then
exit 1
fi

declare -a username_list=$(echo $user_home_list | tr ',' ' ')
declare -a username_list=$(echo "$user_home_list" | tr ',' ' ')
for item in ${username_list[*]}; do
user_home=($(echo $item | tr ':', ' '))
user_home=($(echo "$item" | tr ':', ' '))
username=${user_home[0]}
home_dir=${user_home[1]}
inject_ssh_key $username $home_dir $ssh_email $ssh_key
inject_ssh_key $username $home_dir "$ssh_email" "$ssh_key"
done
## File : inject_ssh_key.sh ends
4 changes: 2 additions & 2 deletions chef/chef_kitchen_provision.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash -x
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : chef_kitchen_provision.sh
## Author : Denny <[email protected]>
## Description :
## --
## Created : <2015-11-30>
## Updated: Time-stamp: <2016-04-19 21:10:03>
## Updated: Time-stamp: <2016-04-25 11:16:03>
##-------------------------------------------------------------------
# pre-cache Chef Omnibus installation
mkdir -p /tmp/install.sh.14
Expand Down
4 changes: 2 additions & 2 deletions chef/chinese_chef_kitchen_provision.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash -x
##-------------------------------------------------------------------
## @copyright 2016 DennyZhang.com
## Licensed under MIT
## Licensed under MIT
## https://raw.githubusercontent.com/DennyZhang/devops_public/master/LICENSE
##
## File : chinese_chef_kitchen_provision.sh
## Author : Denny <[email protected]>
## Description :
## --
## Created : <2015-11-30>
## Updated: Time-stamp: <2016-04-19 21:10:08>
## Updated: Time-stamp: <2016-04-25 11:16:03>
##-------------------------------------------------------------------
# pre-cache Chef Omnibus installation
wget -O /tmp/chef_kitchen_provision.sh https://raw.githubusercontent.com/DennyZhang/devops_public/master/chef/chef_kitchen_provision.sh
Expand Down
Loading

0 comments on commit 5e795f2

Please sign in to comment.