Skip to content

Commit

Permalink
Feature happy shellcheck (#5)
Browse files Browse the repository at this point in the history
* Enough for one day. skipped: 0 failed: 52 passed: 15

* skipped: 0 failed: 42 passed: 25

* skipped: 0 failed: 25 passed: 42

* skipped: 0 failed: 0 passed: 67

* Bumped version
  • Loading branch information
qs5779 authored Jan 1, 2021
1 parent 573acdf commit 5624b96
Show file tree
Hide file tree
Showing 67 changed files with 476 additions and 381 deletions.
16 changes: 5 additions & 11 deletions files/bin/apt-clean
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20190625 - que - initial version
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 2123 $'
VERBOSE=0
DEBUG=0
ERRORS=0
VERSION=2.2.0

function usage {
cat << EOM
Expand All @@ -23,18 +21,14 @@ EOM
exit 1
}

while getopts ":d:hvV" opt
while getopts ":hV" opt
do
case "$opt" in
d )
DETAIL="$OPTARG"
;;
h )
usage
;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
echo "$SCRIPT VERSION: $VERSION"
exit 0
;;
* )
Expand Down
11 changes: 6 additions & 5 deletions files/bin/checkgemdeps
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20160811 - quiensabe - initial version
# 20160811 - que - initial version
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 2123 $'
VERSION=2.2.0
VERBOSE=0
DEBUG=0
ERRORS=0
Expand Down Expand Up @@ -35,7 +36,7 @@ do
;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
echo "$SCRIPT VERSION: $VERSION"
exit 0
;;
* )
Expand All @@ -61,4 +62,4 @@ fi

rm -f $TLIST $TDEP

exit $ERRORS
exit "$ERRORS"
16 changes: 9 additions & 7 deletions files/bin/filenameclean.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20180819 - que - initial version
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 1.0.0 $'
VERSION=1.0.1
VERBOSE=0
MAYBE=''
ERRORS=0
Expand All @@ -30,7 +32,7 @@ do
t ) MAYBE='echo [noex] ' ;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
echo "$SCRIPT VERSION: $VERSION"
exit 0
;;
* )
Expand All @@ -39,7 +41,7 @@ do
;;
esac
done
shift $(($OPTIND - 1))
shift $((OPTIND - 1))

while [ -n "$1" ]
do
Expand All @@ -51,8 +53,8 @@ do
SRCDIR=$(dirname "$SRC") # TODO: make sure src dir is writable
SRCBAS=$(basename "$SRC")

TGTBAS=$(echo $SRCBAS | tr -d "['\"]" | sed -e 's/ /-/g' -e 's/--/-/g' -e 's/\.\./\./g' -e 's/\//-/g')
NEWNM=${SRCDIR}/${TGTBAS}
TGTBAS=$(echo "$SRCBAS" | tr -d \" | sed -e 's/ /-/g' -e 's/--/-/g' -e 's/\.\./\./g' -e 's/\//-/g')
NEWNM="${SRCDIR}/${TGTBAS}"
#echo "NEWNM: $NEWNM"

if [ "$SRC" != "$TGTBAS" ]
Expand All @@ -66,4 +68,4 @@ do
fi
done

exit $ERRORS
exit "$ERRORS"
11 changes: 6 additions & 5 deletions files/bin/find-fifo.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20160811 - quiensabe - initial version
# 20160811 - que - initial version
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 2123 $'
VERSION=2.2.0
VERBOSE=0
DEBUG=0
ERRORS=0
Expand Down Expand Up @@ -38,7 +39,7 @@ do
;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
echo "$SCRIPT VERSION: $VERSION"
exit 0
;;
* )
Expand All @@ -51,4 +52,4 @@ shift $((OPTIND - 1))

find . -type p

exit $ERRORS
exit "$ERRORS"
8 changes: 6 additions & 2 deletions files/bin/fix-sudo-xauth.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History
# 20210101 - que - shellcheck corrections

DISPLAY_NUMBER=$(echo $DISPLAY | awk -F: '{print $2}' | awk -F. '{print $1}')
DISPLAY_NUMBER=$(echo "$DISPLAY" | awk -F: '{print $2}' | awk -F. '{print $1}')
EC=0

if [ -n "$DISPLAY_NUMBER" ]
Expand All @@ -11,7 +15,7 @@ then
if [ -n "$COOKIE" ]
then
echo "executing: sudo xauth add $COOKIE"
sudo xauth add $COOKIE
sudo xauth add "$COOKIE"
else
echo "No cookie found!"
EC=1
Expand Down
25 changes: 20 additions & 5 deletions files/bin/fix_whitespace.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
#!/bin/bash
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20210101 - que - shellcheck corrections

# This script expects $1 to be passed and for $1 to be the filesystem location
# to a yaml file for which it will run syntax checks against.
# to a file for which it will fix white space issues

file="$1"
FIXLFEOF=$2

if file --mime "$file" | grep -q 'charset=binary'
then
exit 0
fi

case "$(uname -s)" in
MING* )
PLATFORM=win
;;
Darwin )
PLATFORM=mac
;;
* )
PLATFORM=dunno
;;
esac

function auto_fix_lfeof {
typeset F="$1"
typeset I="$2"
Expand All @@ -25,7 +40,7 @@ function auto_fix_lfeof {
elif [ "$(tail -c2 "$F")" == '' ]
then
# remove all but last newline
case "$platform" in
case "$PLATFORM" in
win )
sed -i "" -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$F" > "${F}.bak"
mv -f "${F}.bak" "$F"
Expand Down Expand Up @@ -62,12 +77,12 @@ function auto_fix_whitespace {

if grep -q '[[:space:]]$' "$F"
then
if [[ "$platform" == "win" ]]
if [[ "$PLATFORM" == "win" ]]
then
# in windows, `sed -i` adds ready-only attribute to $F(I don't kown why), so we use temp file instead
sed 's/[[:space:]]*$//' "$F" > "${F}.bak"
mv -f "${F}.bak" "$file"
elif [[ "$platform" == "mac" ]]
elif [[ "$PLATFORM" == "mac" ]]
then
sed -i "" 's/[[:space:]]*$//' "$file"
else
Expand Down
13 changes: 7 additions & 6 deletions files/bin/import-cacert.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# YYYYmmdd - whoami - initial version
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 0.1 $' # will be replaced by svn commit # if using subversion with Revision keywords on
VERSION=1.0.0
VERBOSE=0
DEBUG=0
ERRORS=0
Expand Down Expand Up @@ -39,7 +40,7 @@ do
;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
echo "$SCRIPT VERSION: $VERSION"
exit 0
;;
* )
Expand Down Expand Up @@ -67,7 +68,7 @@ then

if [ -n "$CN" ]
then
certutil -d sql:${HOME}/.pki/nssdb -A -t TC -n "$CN" -i "$INFILE"
certutil -d "sql:${HOME}/.pki/nssdb" -A -t TC -n "$CN" -i "$INFILE"
else
echo "Failed to determine commonName for: $INFILE" >&2
((ERRORS+=1))
Expand All @@ -78,4 +79,4 @@ else
fi

# ERRORS=$((ERRORS+=1)) # darn ubuntu default dash shell
exit $ERRORS
exit "$ERRORS"
6 changes: 3 additions & 3 deletions files/bin/import-cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
REMHOST=$1
REMPORT=${2:-443}
exec 6>&1
exec > $REMHOST
echo | openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
certutil -d sql:$HOME/.pki/nssdb -A -t TC -n "$REMHOST" -i $REMHOST
exec > "$REMHOST"
echo | openssl s_client -connect "${REMHOST}:${REMPORT}" 2>&1 |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
certutil -d "sql:$HOME/.pki/nssdb" -A -t TC -n "$REMHOST" -i "$REMHOST"
exec 1>&6 6>&-
17 changes: 9 additions & 8 deletions files/bin/lfeof
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20160811 - que - initial version
# 20171218 - que - corrected error messages, adusted version
# 20171224 - que - cleanup tmp file
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 1.03 $'
VERSION=1.1.0
VERBOSE=0
DEBUG=0
ERRORS=0
Expand Down Expand Up @@ -48,7 +49,7 @@ do
q ) ((QUIET+=1)) ;;
v ) ((VERBOSE+=1)) ;;
V )
echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"
echo "$SCRIPT VERSION: $VERSION"
exit 0
;;
* )
Expand Down Expand Up @@ -85,14 +86,14 @@ do
then
if [ $RC -eq 1 ]
then
cp $B "$TMPF" "$SRC"
if [ $QUIET -eq 0 ]
cp "$B" "$TMPF" "$SRC"
if [ "$QUIET" -eq 0 ]
then
echo -e "corrected line feeds at end of file: \033[31m$SRC\033[0m"
fi
rm -f "$TMPF"
else
if [ $QUIET -eq 0 ]
if [ "$QUIET" -eq 0 ]
then
echo "diff $TMPF $SRC returned $RC. $SRC left unchanged."
fi
Expand All @@ -104,6 +105,6 @@ do
fi
done

rm -f $TMPF
rm -f "$TMPF"

exit $ERRORS
exit "$ERRORS"
11 changes: 6 additions & 5 deletions files/bin/psgrep
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# Revision History:
# 20150129 - richarjt - initial version
# 20150129 - que - initial version
# 20210101 - que - shellcheck corrections
#

SCRIPT=$(basename "$0")
VERSION='$Revision: 1388 $'
VERSION=1.4.0
USECASE=1

function usage {
Expand All @@ -31,11 +32,11 @@ do
case $OPT in
h ) usage ;;
i ) USECASE=0 ;;
V ) echo "$SCRIPT VERSION: $(echo $VERSION | awk '{ print $2 }')"; exit 0 ;;
V ) echo "$SCRIPT VERSION: $VERSION" ;;
* ) echo "Unrecognized option $OPT" ;;
esac
done
shift $(($OPTIND - 1))
shift $((OPTIND - 1))

OS=$(uname -s)

Expand Down
2 changes: 1 addition & 1 deletion files/bin/rmblankseof.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ done

rm -f "$tmpfile"

exit $ERRORS
exit "$ERRORS"
4 changes: 2 additions & 2 deletions files/bin/rmknownhost
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*- vim:sta:et:sw=2:ts=2:syntax=sh
# vim:sta:et:sw=2:ts=2:syntax=sh
#
# $Id: rmknownhost 1388 2016-07-02 17:54:43Z jim $
# $Date: 2016-07-02 13:54:43 -0400 (Sat, 02 Jul 2016) $
Expand Down Expand Up @@ -44,7 +44,7 @@ do
HN="$1"
shift
ssh-keygen -R "$HN"
if [ $PORT -ne 0 ]
if [ "$PORT" -ne 0 ]
then
ssh-keygen -R "[$HN]:${PORT}"
fi
Expand Down
2 changes: 1 addition & 1 deletion files/bin/showpathvar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

# -*- Mode: Bash; tab-width: 2; indent-tabs-mode: nil -*-
# vim:sta:et:sw=2:ts=2:syntax=sh
#

SCRIPT=$(basename "$0")
Expand Down
Loading

0 comments on commit 5624b96

Please sign in to comment.