Cleanup all *.sh following shellcheck advice (#80)

* Cleanup all *.sh following shellcheck advice

Closes #79

* do not shellcheck scripts out of our control
This commit is contained in:
Manuel Streuhofer 2016-12-16 08:18:03 +01:00 committed by Kevin van Zonneveld
parent 044ef6d1c5
commit 785e7e9f8b
17 changed files with 85 additions and 80 deletions

View File

@ -43,7 +43,7 @@ read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered
parsed and will be added as-is to the help.
EOF
# shellcheck source=./main.sh
# shellcheck source=main.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/main.sh"

View File

@ -35,13 +35,15 @@ function ini_val() {
local key=""
# Split on . for section. However, section is optional
read section key <<<$(IFS="."; echo ${sectionkey})
IFS='.' read -r section key <<< "${sectionkey}"
if [ -z "${key}" ]; then
key="${section}"
section=""
fi
local current=$(awk -F "${delim}" "/^${key}${delim}/ {for (i=2; i<NF; i++) printf \$i \" \"; print \$NF}" "${file}")
local current
current=$(awk -F "${delim}" "/^${key}${delim}/ {for (i=2; i<NF; i++) printf \$i \" \"; print \$NF}" "${file}")
if [ -z "${val}" ]; then
# get a value
echo "${current}"

View File

@ -28,19 +28,28 @@
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
# as you leave these references intact in the header comments of your source files.
__dir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=src/parse_url.sh
source "${__dir}/parse_url.sh"
function megamount () {
local url="${1}"
local target="${2}"
local proto=$(parse_url "${url}" "proto")
local user=$(parse_url "${url}" "user")
local pass=$(parse_url "${url}" "pass")
local host=$(parse_url "${url}" "host")
local port=$(parse_url "${url}" "port")
local path=$(parse_url "${url}" "path")
local proto
local user
local pass
local host
local port
local path
proto=$(parse_url "${url}" "proto")
user=$(parse_url "${url}" "user")
pass=$(parse_url "${url}" "pass")
host=$(parse_url "${url}" "host")
port=$(parse_url "${url}" "port")
path=$(parse_url "${url}" "path")
(umount -lf "${target}" || umount -f "${target}") > /dev/null 2>&1 || true
mkdir -p "${target}"

View File

@ -30,15 +30,25 @@ function parse_url() {
local parse="${1}"
local need="${2:-}"
local proto="$(echo $parse | grep :// | sed -e's,^\(.*://\).*,\1,g')"
local url="$(echo ${parse/$proto/})"
local userpass="$(echo $url | grep @ | cut -d@ -f1)"
local user="$(echo $userpass | grep : | cut -d: -f1)"
local pass="$(echo $userpass | grep : | cut -d: -f2)"
local hostport="$(echo ${url/$userpass@/} | cut -d/ -f1)"
local host="$(echo $hostport | grep : | cut -d: -f1)"
local port="$(echo $hostport | grep : | cut -d: -f2)"
local path="$(echo $url | grep / | cut -d/ -f2-)"
local proto
local url
local userpass
local user
local pass
local hostport
local host
local port
local path
proto="$(echo "$parse" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url="${parse/$proto/}"
userpass="$(echo "$url" | grep @ | cut -d@ -f1)"
user="$(echo "$userpass" | grep : | cut -d: -f1)"
pass="$(echo "$userpass" | grep : | cut -d: -f2)"
hostport="$(echo "${url/$userpass@/}" | cut -d/ -f1)"
host="$(echo "$hostport" | grep : | cut -d: -f1)"
port="$(echo "$hostport" | grep : | cut -d: -f2)"
path="$(echo "$url" | grep / | cut -d/ -f2-)"
[ -z "${user}" ] && user="${userpass}"
[ -z "${host}" ] && host="${hostport}"
@ -50,7 +60,7 @@ function parse_url() {
fi
if [ -n "${need}" ]; then
echo ${!need}
echo "${!need}"
else
echo ""
echo " Use second argument to return just 1 variable."

View File

@ -48,6 +48,7 @@ function templater() {
# cat "${templateDst}"
# shellcheck disable=SC2016
if grep '${' "${templateDst}" && [ "${ALLOW_REMAINDERS}" = "0" ]; then
echo "ERROR: Unable to replace the above template vars"
exit 1

View File

@ -201,11 +201,8 @@ if [[ "$(command -v shellcheck)" ]]; then
failed="false"
while IFS=$'\n' read -r file; do
lint="false"
[[ "${file}" = "./main.sh" ]] && lint="true"
[[ "${file}" = "./example.sh" ]] && lint="true"
[[ "${file}" = "./test/acceptance.sh" ]] && lint="true"
[[ "${lint}" != "true" ]] && continue
[[ "${file}" =~ ^\./node_modules/ ]] && continue
[[ "${file}" =~ ^\./website/\.lanyon/ ]] && continue
echo -n " ${file}.. "

View File

@ -7,8 +7,8 @@ set -o nounset
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__base="$(basename "${__file}" .sh)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
# echo "ACCPTST:STDIO_REPLACE_DATETIMES"
@ -29,7 +29,10 @@ rm -f dummy.ini
# Use as include:
cp -f data.ini dummy.ini
source ${__root}/src/ini_val.sh
# shellcheck source=main.sh
source "${__root}/src/ini_val.sh"
echo "--> function: Read 3 values"
ini_val ./dummy.ini orphan
ini_val ./dummy.ini connection.host

View File

@ -4,11 +4,8 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"

View File

@ -4,11 +4,8 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"

View File

@ -4,14 +4,13 @@
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
(env LOG_LEVEL=6 bash "${__root}/main.sh" --file /tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" --file=/tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" -f /tmp/x) 2>&1 |grep arg_f
(
env LOG_LEVEL=6 bash "${__root}/main.sh" --file /tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" --file=/tmp/x;
env LOG_LEVEL=6 bash "${__root}/main.sh" -f /tmp/x
) 2>&1 |grep arg_f

View File

@ -4,11 +4,8 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
echo "ACCPTST:STDIO_REPLACE_DATETIMES"

View File

@ -4,13 +4,9 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
# Set __usage and source main.sh
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-1 --one Do one thing. Default="ONE"
More description.
@ -28,6 +24,7 @@ EOF
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
# shellcheck source=main.sh
source "${__root}/main.sh"
for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done

View File

@ -1,16 +1,14 @@
#!/usr/bin/env bash
# shellcheck source=main.sh
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
# Set __usage and source main.sh
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-0 --zero Do nothing.
-1 --one Do one thing. Required.

View File

@ -4,11 +4,8 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
__sysTmpDir="${TMPDIR:-/tmp}"
__sysTmpDir="${__sysTmpDir%/}" # <-- remove trailing slash on macosx
@ -18,5 +15,7 @@ __sysTmpDir="${__sysTmpDir%/}" # <-- remove trailing slash on macosx
bash "${__root}/src/megamount.sh" 'foobarfs://janedoe:abc123@192.168.0.1/documents' "${__sysTmpDir}/mnt/documents" || true
source ${__root}/src/megamount.sh
# shellcheck source=src/megamount.sh
source "${__root}/src/megamount.sh"
megamount 'foobarfs://janedoe:abc123@192.168.0.1/documents' "${__sysTmpDir}/mnt/documents"

View File

@ -4,15 +4,14 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
bash "${__root}/src/parse_url.sh" 'http://johndoe:abc123@example.com:8080/index.html' pass
bash "${__root}/src/parse_url.sh" 'http://johndoe:abc123@example.com:8080/index.html'
source ${__root}/src/parse_url.sh
# shellcheck source=src/parse_url.sh
source "${__root}/src/parse_url.sh"
parse_url 'http://johndoe:abc123@example.com:8080/index.html' pass
parse_url 'http://johndoe:abc123@example.com:8080/index.html'

View File

@ -4,11 +4,8 @@ set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
echo "--"
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./app.template.cfg ./app.cfg
@ -17,7 +14,10 @@ rm -f app.cfg
echo "--"
export TARGET_HOST="127.0.0.1"
source ${__root}/src/templater.sh
# shellcheck source=src/templater.sh
source "${__root}/src/templater.sh"
templater ./app.template.cfg ./app.cfg
cat app.cfg
rm -f app.cfg

View File

@ -30,7 +30,7 @@ set -o pipefail
# Set magic variables for current file, directory, os, etc.
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
__base="$(basename "${__file}" .sh)"
# Offer the main template for download as http://bash3boilerplate.sh/main.sh
cp -v main.sh website/
@ -38,10 +38,10 @@ cp -v main.sh website/
for doc in "README" "FAQ" "CHANGELOG"; do
targetName="$(echo "${doc}" | awk '{print tolower($0)}')"
permalink="/${targetName}/"
subtitle="$(tr '[:lower:]' '[:upper:]' <<< ${targetName:0:1})${targetName:1} | "
subtitle="$(tr '[:lower:]' '[:upper:]' <<< "${targetName:0:1}")${targetName:1} | "
redirectFrom="/${doc}.md/"
backLink="\n\n<a href=\"/\">&laquo; Home</a>"
if [ "${doc}" = "README" ]; then
if [[ "${doc}" = "README" ]]; then
targetName="index"
permalink="/"
subtitle=""
@ -49,7 +49,7 @@ for doc in "README" "FAQ" "CHANGELOG"; do
backLink=""
fi
cat <<EOF > website/${targetName}.md
cat <<EOF > "website/${targetName}.md"
---
layout: default
permalink: ${permalink}
@ -60,14 +60,14 @@ warning: This page is generated by ${__base}.sh based on ${doc}.md, please don't
EOF
# If '<!--more-->' exists, only inject what comes after it, so you can have e.g. a ToC or buildbuttons
# on GitHub, without that also rendering in the site (site may have its own ToC rendering for instance)
if grep '<!--more-->' ${doc}.md; then
cat ${doc}.md |sed -n -e '/<!--more-->/,$p' | tail -n +2 >> website/${targetName}.md
if grep '<!--more-->' "${doc}.md"; then
sed -n -e '/<!--more-->/,$p' "${doc}.md" | tail -n +2 >> "website/${targetName}.md"
else
cat ${doc}.md >> website/${targetName}.md
cat "${doc}.md" >> "website/${targetName}.md"
fi
# Add a "<- Back Home" link, if any
echo -e $backLink >> website/${targetName}.md
echo -e $backLink >> "website/${targetName}.md"
echo "--> written website/${targetName}.md"
done