mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-06-18 14:18:06 +00:00
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:
committed by
Kevin van Zonneveld
parent
044ef6d1c5
commit
785e7e9f8b
@ -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.
|
parsed and will be added as-is to the help.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# shellcheck source=./main.sh
|
# shellcheck source=main.sh
|
||||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/main.sh"
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/main.sh"
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,13 +35,15 @@ function ini_val() {
|
|||||||
local key=""
|
local key=""
|
||||||
|
|
||||||
# Split on . for section. However, section is optional
|
# Split on . for section. However, section is optional
|
||||||
read section key <<<$(IFS="."; echo ${sectionkey})
|
IFS='.' read -r section key <<< "${sectionkey}"
|
||||||
if [ -z "${key}" ]; then
|
if [ -z "${key}" ]; then
|
||||||
key="${section}"
|
key="${section}"
|
||||||
section=""
|
section=""
|
||||||
fi
|
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
|
if [ -z "${val}" ]; then
|
||||||
# get a value
|
# get a value
|
||||||
echo "${current}"
|
echo "${current}"
|
||||||
|
@ -28,19 +28,28 @@
|
|||||||
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
|
# 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.
|
# 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"
|
source "${__dir}/parse_url.sh"
|
||||||
|
|
||||||
function megamount () {
|
function megamount () {
|
||||||
local url="${1}"
|
local url="${1}"
|
||||||
local target="${2}"
|
local target="${2}"
|
||||||
|
|
||||||
local proto=$(parse_url "${url}" "proto")
|
local proto
|
||||||
local user=$(parse_url "${url}" "user")
|
local user
|
||||||
local pass=$(parse_url "${url}" "pass")
|
local pass
|
||||||
local host=$(parse_url "${url}" "host")
|
local host
|
||||||
local port=$(parse_url "${url}" "port")
|
local port
|
||||||
local path=$(parse_url "${url}" "path")
|
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
|
(umount -lf "${target}" || umount -f "${target}") > /dev/null 2>&1 || true
|
||||||
mkdir -p "${target}"
|
mkdir -p "${target}"
|
||||||
|
@ -30,15 +30,25 @@ function parse_url() {
|
|||||||
local parse="${1}"
|
local parse="${1}"
|
||||||
local need="${2:-}"
|
local need="${2:-}"
|
||||||
|
|
||||||
local proto="$(echo $parse | grep :// | sed -e's,^\(.*://\).*,\1,g')"
|
local proto
|
||||||
local url="$(echo ${parse/$proto/})"
|
local url
|
||||||
local userpass="$(echo $url | grep @ | cut -d@ -f1)"
|
local userpass
|
||||||
local user="$(echo $userpass | grep : | cut -d: -f1)"
|
local user
|
||||||
local pass="$(echo $userpass | grep : | cut -d: -f2)"
|
local pass
|
||||||
local hostport="$(echo ${url/$userpass@/} | cut -d/ -f1)"
|
local hostport
|
||||||
local host="$(echo $hostport | grep : | cut -d: -f1)"
|
local host
|
||||||
local port="$(echo $hostport | grep : | cut -d: -f2)"
|
local port
|
||||||
local path="$(echo $url | grep / | cut -d/ -f2-)"
|
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 "${user}" ] && user="${userpass}"
|
||||||
[ -z "${host}" ] && host="${hostport}"
|
[ -z "${host}" ] && host="${hostport}"
|
||||||
@ -50,7 +60,7 @@ function parse_url() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${need}" ]; then
|
if [ -n "${need}" ]; then
|
||||||
echo ${!need}
|
echo "${!need}"
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
echo " Use second argument to return just 1 variable."
|
echo " Use second argument to return just 1 variable."
|
||||||
|
@ -48,6 +48,7 @@ function templater() {
|
|||||||
|
|
||||||
# cat "${templateDst}"
|
# cat "${templateDst}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2016
|
||||||
if grep '${' "${templateDst}" && [ "${ALLOW_REMAINDERS}" = "0" ]; then
|
if grep '${' "${templateDst}" && [ "${ALLOW_REMAINDERS}" = "0" ]; then
|
||||||
echo "ERROR: Unable to replace the above template vars"
|
echo "ERROR: Unable to replace the above template vars"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -201,11 +201,8 @@ if [[ "$(command -v shellcheck)" ]]; then
|
|||||||
failed="false"
|
failed="false"
|
||||||
|
|
||||||
while IFS=$'\n' read -r file; do
|
while IFS=$'\n' read -r file; do
|
||||||
lint="false"
|
[[ "${file}" =~ ^\./node_modules/ ]] && continue
|
||||||
[[ "${file}" = "./main.sh" ]] && lint="true"
|
[[ "${file}" =~ ^\./website/\.lanyon/ ]] && continue
|
||||||
[[ "${file}" = "./example.sh" ]] && lint="true"
|
|
||||||
[[ "${file}" = "./test/acceptance.sh" ]] && lint="true"
|
|
||||||
[[ "${lint}" != "true" ]] && continue
|
|
||||||
|
|
||||||
echo -n " ${file}.. "
|
echo -n " ${file}.. "
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ set -o nounset
|
|||||||
# Set magic variables for current FILE & DIR
|
# Set magic variables for current FILE & DIR
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||||
__base="$(basename ${__file} .sh)"
|
__base="$(basename "${__file}" .sh)"
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
|
|
||||||
# echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
# echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
@ -29,7 +29,10 @@ rm -f dummy.ini
|
|||||||
|
|
||||||
# Use as include:
|
# Use as include:
|
||||||
cp -f data.ini dummy.ini
|
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"
|
echo "--> function: Read 3 values"
|
||||||
ini_val ./dummy.ini orphan
|
ini_val ./dummy.ini orphan
|
||||||
ini_val ./dummy.ini connection.host
|
ini_val ./dummy.ini connection.host
|
||||||
|
@ -4,11 +4,8 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
|
||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
|
@ -4,11 +4,8 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
|
||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
|
@ -4,14 +4,13 @@
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
|
||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
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" --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" -f /tmp/x
|
||||||
|
) 2>&1 |grep arg_f
|
||||||
|
@ -4,11 +4,8 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
|
||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
|
@ -4,13 +4,9 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__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
|
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
|
||||||
-1 --one Do one thing. Default="ONE"
|
-1 --one Do one thing. Default="ONE"
|
||||||
More description.
|
More description.
|
||||||
@ -28,6 +24,7 @@ EOF
|
|||||||
|
|
||||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||||
|
|
||||||
|
# shellcheck source=main.sh
|
||||||
source "${__root}/main.sh"
|
source "${__root}/main.sh"
|
||||||
|
|
||||||
for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done
|
for argument in ${!arg_*}; do info "${argument}: ${!argument}"; done
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# shellcheck source=main.sh
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__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
|
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
|
||||||
-0 --zero Do nothing.
|
-0 --zero Do nothing.
|
||||||
-1 --one Do one thing. Required.
|
-1 --one Do one thing. Required.
|
||||||
|
@ -4,11 +4,8 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
|
||||||
|
|
||||||
__sysTmpDir="${TMPDIR:-/tmp}"
|
__sysTmpDir="${TMPDIR:-/tmp}"
|
||||||
__sysTmpDir="${__sysTmpDir%/}" # <-- remove trailing slash on macosx
|
__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
|
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"
|
megamount 'foobarfs://janedoe:abc123@192.168.0.1/documents' "${__sysTmpDir}/mnt/documents"
|
||||||
|
@ -4,15 +4,14 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__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' pass
|
||||||
bash "${__root}/src/parse_url.sh" 'http://johndoe:abc123@example.com:8080/index.html'
|
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' pass
|
||||||
parse_url 'http://johndoe:abc123@example.com:8080/index.html'
|
parse_url 'http://johndoe:abc123@example.com:8080/index.html'
|
||||||
|
@ -4,11 +4,8 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
# set -o xtrace
|
# set -o xtrace
|
||||||
|
|
||||||
# Set magic variables for current FILE & DIR
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||||
__base="$(basename ${__file} .sh)"
|
|
||||||
__root="$(cd "$(dirname $(dirname $(dirname "${__dir}")))" && pwd)"
|
|
||||||
|
|
||||||
echo "--"
|
echo "--"
|
||||||
env TARGET_HOST="127.0.0.1" bash "${__root}/src/templater.sh" ./app.template.cfg ./app.cfg
|
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 "--"
|
echo "--"
|
||||||
export TARGET_HOST="127.0.0.1"
|
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
|
templater ./app.template.cfg ./app.cfg
|
||||||
cat app.cfg
|
cat app.cfg
|
||||||
rm -f app.cfg
|
rm -f app.cfg
|
||||||
|
@ -30,7 +30,7 @@ set -o pipefail
|
|||||||
# Set magic variables for current file, directory, os, etc.
|
# Set magic variables for current file, directory, os, etc.
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
__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
|
# Offer the main template for download as http://bash3boilerplate.sh/main.sh
|
||||||
cp -v main.sh website/
|
cp -v main.sh website/
|
||||||
@ -38,10 +38,10 @@ cp -v main.sh website/
|
|||||||
for doc in "README" "FAQ" "CHANGELOG"; do
|
for doc in "README" "FAQ" "CHANGELOG"; do
|
||||||
targetName="$(echo "${doc}" | awk '{print tolower($0)}')"
|
targetName="$(echo "${doc}" | awk '{print tolower($0)}')"
|
||||||
permalink="/${targetName}/"
|
permalink="/${targetName}/"
|
||||||
subtitle="$(tr '[:lower:]' '[:upper:]' <<< ${targetName:0:1})${targetName:1} | "
|
subtitle="$(tr '[:lower:]' '[:upper:]' <<< "${targetName:0:1}")${targetName:1} | "
|
||||||
redirectFrom="/${doc}.md/"
|
redirectFrom="/${doc}.md/"
|
||||||
backLink="\n\n<a href=\"/\">« Home</a>"
|
backLink="\n\n<a href=\"/\">« Home</a>"
|
||||||
if [ "${doc}" = "README" ]; then
|
if [[ "${doc}" = "README" ]]; then
|
||||||
targetName="index"
|
targetName="index"
|
||||||
permalink="/"
|
permalink="/"
|
||||||
subtitle=""
|
subtitle=""
|
||||||
@ -49,7 +49,7 @@ for doc in "README" "FAQ" "CHANGELOG"; do
|
|||||||
backLink=""
|
backLink=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat <<EOF > website/${targetName}.md
|
cat <<EOF > "website/${targetName}.md"
|
||||||
---
|
---
|
||||||
layout: default
|
layout: default
|
||||||
permalink: ${permalink}
|
permalink: ${permalink}
|
||||||
@ -60,14 +60,14 @@ warning: This page is generated by ${__base}.sh based on ${doc}.md, please don't
|
|||||||
EOF
|
EOF
|
||||||
# If '<!--more-->' exists, only inject what comes after it, so you can have e.g. a ToC or buildbuttons
|
# 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)
|
# on GitHub, without that also rendering in the site (site may have its own ToC rendering for instance)
|
||||||
if grep '<!--more-->' ${doc}.md; then
|
if grep '<!--more-->' "${doc}.md"; then
|
||||||
cat ${doc}.md |sed -n -e '/<!--more-->/,$p' | tail -n +2 >> website/${targetName}.md
|
sed -n -e '/<!--more-->/,$p' "${doc}.md" | tail -n +2 >> "website/${targetName}.md"
|
||||||
else
|
else
|
||||||
cat ${doc}.md >> website/${targetName}.md
|
cat "${doc}.md" >> "website/${targetName}.md"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add a "<- Back Home" link, if any
|
# Add a "<- Back Home" link, if any
|
||||||
echo -e $backLink >> website/${targetName}.md
|
echo -e $backLink >> "website/${targetName}.md"
|
||||||
|
|
||||||
echo "--> written website/${targetName}.md"
|
echo "--> written website/${targetName}.md"
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user