From 319316925628d96a9028d052c59f1813215dee52 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 1 Jan 2021 11:27:54 +0100 Subject: [PATCH] dev/: convert echo --- dev/all-tests.sh | 22 +++++++++++----------- dev/git-add.sh | 14 +++++++------- dev/install-hooks.sh | 10 +++++----- dev/make-distribution.sh | 18 +++++++++--------- dev/make-html.sh | 6 +++--- dev/make-standalone.sh | 17 ++++++++--------- dev/obfuscate.sh | 19 ++++++++++++------- dev/version.sh | 18 +++++++++--------- 8 files changed, 64 insertions(+), 60 deletions(-) diff --git a/dev/all-tests.sh b/dev/all-tests.sh index 7d74588..ae5b970 100755 --- a/dev/all-tests.sh +++ b/dev/all-tests.sh @@ -5,7 +5,7 @@ # # Description: run all tests, exit after failed test # -#### $$VERSION$$ v1.21-dev-46-gd13e95a +#### $$VERSION$$ v1.21-pre-3-gbbbf57c ############################################################# # magic to ensure that we're always inside the root of our application, @@ -14,7 +14,7 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) if [ "$GIT_DIR" != "" ] ; then cd "$GIT_DIR/.." || exit 1 else - echo "Sorry, no git repository $(pwd)" && exit 1 + printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi ########################## @@ -39,20 +39,20 @@ fail=0 tests=0 passed=0 #all_tests=${__dirname:} -#echo PLAN ${#all_tests} +#printf PLAN ${#all_tests} for test in $(find ./*-test.sh | sort -u) ; do [ "${test}" = "dev/all-tests.sh" ] && continue [ ! -x "${test}" ] && continue tests=$((tests+1)) - echo "TEST: ${test}" + printf "TEST: %s\n" "${test}" "${test}" "${TESTENV}" ret=$? if [ "$ret" -eq 0 ] ; then - echo "OK: ---- ${test}" + printf "OK: ---- %s\n" "${test}" passed=$((passed+1)) else - echo "FAIL: $test $fail" + printf "FAIL: %s\n" "${test} ${fail}" fail=$((fail+ret)) break fi @@ -61,11 +61,11 @@ done ########################### # cleanup depending on test state if [ "$fail" -eq 0 ]; then - /bin/echo -n 'SUCCESS ' + printf 'SUCCESS ' exitcode=0 rm -rf "${TESTENV}" else - /bin/echo -n 'FAILURE ' + printf 'FAILURE ' exitcode=1 rm -rf "${TESTENV}/test" find "${TESTENV}/"* ! -name '[a-z]-*' -delete @@ -73,9 +73,9 @@ fi ######################### # show test result and test logs -echo -e "${passed} / ${tests}\\n" -[ -d "${TESTENV}" ] && echo "Logfiles from run are in ${TESTENV}" +printf "%s\n\n" "${passed} / ${tests}" +[ -d "${TESTENV}" ] && printf "Logfiles from run are in %s\n" "${TESTENV}" -ls -ld /tmp/bashbot.test* 2>/dev/null && echo "Do not forget to delete bashbot test files in /tmp!!" +ls -ld /tmp/bashbot.test* 2>/dev/null && printf "Do not forget to delete bashbot test files in /tmp!!\n" exit ${exitcode} diff --git a/dev/git-add.sh b/dev/git-add.sh index 92119da..5614a90 100755 --- a/dev/git-add.sh +++ b/dev/git-add.sh @@ -3,7 +3,7 @@ # # works together with git pre-push.sh and ADD all changed files since last push -#### $$VERSION$$ v1.20-0-g2ab00a2 +#### $$VERSION$$ v1.21-pre-3-gbbbf57c # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -11,27 +11,27 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) if [ "$GIT_DIR" != "" ] ; then cd "$GIT_DIR/.." || exit 1 else - echo "Sorry, no git repository $(pwd)" && exit 1 + printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi -[ ! -f .git/.lastcommit ] && echo "No previous commit or hooks not installed, use \"git add\" instead ... Abort" && exit +[ ! -f .git/.lastcommit ] && printf "No previous commit or hooks not installed, use \"git add\" instead ... Abort\n" && exit set +f FILES="$(find ./* -newer .git/.lastpush| grep -v -e 'DIST\/' -e 'STANDALONE\/' -e 'JSON.sh')" set -f # FILES="$(find ./* -newer .git/.lastpush)" -[ "${FILES}" = "" ] && echo "Noting changed since last commit ..." && exit +[ "${FILES}" = "" ] && printf "Nothing changed since last commit ...\n" && exit # run pre_commit on files dev/hooks/pre-commit.sh -echo -e "Add files to repo: \c" +printf "Add files to repo: " # shellcheck disable=SC2086 for file in ${FILES} do [ -d "${file}" ] && continue - echo -e "${file} \c" + printf "%s" "${file} " git add "$file" done -echo " - Done." +printf " - Done.\n" diff --git a/dev/install-hooks.sh b/dev/install-hooks.sh index 37c071c..a66a988 100755 --- a/dev/install-hooks.sh +++ b/dev/install-hooks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ v1.20-0-g2ab00a2 +#### $$VERSION$$ v1.21-pre-3-gbbbf57c # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script @@ -9,18 +9,18 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) if [ "$GIT_DIR" != "" ] ; then cd "$GIT_DIR/.." || exit 1 else - echo "Sorry, no git repository $(pwd)" && exit 1 + printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi HOOKDIR="dev/hooks" -echo -n "Installing hooks..." +printf "Installing hooks..." for hook in pre-commit post-commit pre-push do rm -f "${GIT_DIR}/hooks/${hook}" if [ -f "${HOOKDIR}/${hook}.sh" ]; then - echo -n " $hook" + printf "%s"" $hook" ln -s "../../${HOOKDIR}/${hook}.sh" "${GIT_DIR}/hooks/${hook}" fi done -echo " Done!" +printf " Done!\n" diff --git a/dev/make-distribution.sh b/dev/make-distribution.sh index 1632236..a87d54f 100755 --- a/dev/make-distribution.sh +++ b/dev/make-distribution.sh @@ -7,7 +7,7 @@ # # Options: --notest - skip tests # -#### $$VERSION$$ v1.21-dev-36-gc6001c2 +#### $$VERSION$$ v1.21-pre-3-gbbbf57c ############################################################## # magic to ensure that we're always inside the root of our application, @@ -17,7 +17,7 @@ if [ "$GIT_DIR" != "" ] ; then [[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" cd "$GIT_DIR/.." || exit 1 else - echo "Sorry, no git repository $(pwd)" && exit 1 + printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')" @@ -33,7 +33,7 @@ do [[ "${test}" == "--notest"* ]] && break [ ! -x "${test}" ] && continue if ! "${test}" ; then - echo "Test ${test} failed, can't create dist!" + printf "Test %s failed, can't create dist!\n" "${test}" exit 1 fi done @@ -41,19 +41,19 @@ done # create dir for distribution and copy files mkdir -p "${DISTDIR}" 2>/dev/null -echo "Copy files" +printf "Copy files\n" # shellcheck disable=SC2086 cp -r ${DISTFILES} "${DISTDIR}" cd "${DISTDIR}" || exit 1 -echo "Create directories" +printf "Create directories\n" for dir in $DISTMKDIR do [ ! -d "${dir}" ] && mkdir "${dir}" done # do not overwrite on update -echo "Create .dist files" +printf "Create .dist files\n" for file in mycommands.sh bashbot.rc addons/*.sh do [ "${file}" = "addons/*.sh" ] && continue @@ -65,18 +65,18 @@ done source "$GIT_DIR/../dev/inject-json.sh" # make html doc -echo "Create html doc" +printf "Create html doc\n" # shellcheck disable=SC1090,SC1091 source "../../dev/make-html.sh" # create archive cd .. || exit 1 -echo "Create dist archives" +printf "Create dist archives\n" # shellcheck disable=SC2046 zip -rq - "${DISTNAME}" --exclude $(cat "$GIT_DIR/../dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip" tar --exclude-ignore="$GIT_DIR/../dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}" -echo "Done!" +printf "%s Done!\n" "$0" # shellcheck disable=SC2086 ls -ld ${DISTNAME}-${VERSION}.* diff --git a/dev/make-html.sh b/dev/make-html.sh index 1b9fca3..ad552c4 100644 --- a/dev/make-html.sh +++ b/dev/make-html.sh @@ -7,17 +7,17 @@ # # Usage: source make-hmtl # -#### $$VERSION$$ v1.21-pre-2-ge22fcbf +#### $$VERSION$$ v1.21-pre-3-gbbbf57c ############################################################## # check for correct dir if [[ ! ( -f README.html && -f README.md ) ]]; then - echo "Error: Can't create html, script must run where README.md and README.html is!" + printf "Error: Can't create html, script must run where README.md and README.html is!\n" else # check if pandoc installed if [ "$(type -t pandoc)" != "file" ]; then - echo "pandoc not found, skipping html generation ..." + printf "pandoc not found, skipping html generation ...\n" else ######## diff --git a/dev/make-standalone.sh b/dev/make-standalone.sh index 666928c..49691fb 100755 --- a/dev/make-standalone.sh +++ b/dev/make-standalone.sh @@ -9,7 +9,7 @@ # If you your bot is finished you can use make-standalone.sh to create the # the old all-in-one bashbot: bashbot.sh and commands.sh only! # -#### $$VERSION$$ v1.21-dev-17-g8c9298d +#### $$VERSION$$ v1.21-pre-3-gbbbf57c ################################################################### # magic to ensure that we're always inside the root of our application, @@ -19,7 +19,7 @@ if [ "$GIT_DIR" != "" ] ; then [[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}" cd "$GIT_DIR/.." || exit 1 else - [ ! -f "bashbot.sh" ] && echo "bashbot.sh not found in $(pwd)" && exit 1 + [ ! -f "bashbot.sh" ] && printf "bashbot.sh not found in %s\n" " $(pwd)" && exit 1 fi #DISTNAME="telegram-bot-bash" @@ -43,8 +43,7 @@ source "$GIT_DIR/../dev/inject-json.sh" # here the magic starts # create all in one bashbot.sh file -echo "OK, now lets do the magic ..." -echo " ... create unified commands.sh" +printf "OK, now lets do the magic ...\n... create unified commands.sh\n" { # first head of commands.sh @@ -63,7 +62,7 @@ echo " ... create unified commands.sh" mv $$commands.sh commands.sh rm -f mycommands.sh -echo " ... create unified bashbot.sh" +printf " ... create unified bashbot.sh\n" { # first head of bashbot.sh @@ -84,7 +83,7 @@ chmod +x bashbot.sh rm -rf modules -echo "Create minimized Version of bashbot.sh and commands.sh" +printf "Create minimized Version of bashbot.sh and commands.sh\n" sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' -e 'N;s/\\\n/ /;P;D' bashbot.sh |\ sed 'N;s/\\\n/ /;P;D' > bashbot.sh.min sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e 's/\)[[:space:]]+#.*/)/' -e '/^$/d' commands.sh |\ @@ -92,14 +91,14 @@ sed -E -e '/(shellcheck)|(#!\/bin\/bash)/! s/^[[:space:]]*#.*//' -e 's/^[[:space chmod +x bashbot.sh.min # make html doc -echo "Create html doc" +printf "Create html doc\n" #shellcheck disable=SC1090 source "$GIT_DIR/../dev/make-html.sh" -echo "Done!" +printf "%s Done!\n" "$0" cd .. || exit 1 -echo -e "\\nStandalone bashbot files are now available in \"${DISTDIR}\":\\n" +printf "\nStandalone bashbot files are now available in %s:\n\n" "${DISTDIR}" ls -l "${DISTDIR}" diff --git a/dev/obfuscate.sh b/dev/obfuscate.sh index 2cd77ca..0eb59d8 100755 --- a/dev/obfuscate.sh +++ b/dev/obfuscate.sh @@ -1,18 +1,23 @@ #!/bin/bash -# shellcheck disable=SC2028,SC2016,SC1117 +# # joke hack to obfuscate bashbot.min.sh +# +# shellcheck disable=SC2028,SC2016,SC1117 infile="bashbot.sh" outfile="./bashbot.obf.sh" -[ ! -f "${infile}" ] && echo "Hey, this is a joke hack to obfuscate ${infile}, copy me to STANDANLONE first" && exit - +if [ ! -f "${infile}" ]; then + printf "This is a hack to obfuscate %s, run me in STANDALONE after running make-standalone.sh\n" "${infile}" + exit 1 +fi +# create gzipped base64 encoded file plus commands to decode { -echo '#!/bin/bash' -echo 'a="$PWD";cd "$(mktemp -d)"||exit' -echo 'printf '"'%s\n'"' '"'$(gzip -9 a;export BASHBOT_HOME="$a";chmod +x a;./a "$@";a="$PWD";cd ..;rm -rf "$a"' +# shellcheck disable=SC2183 +printf '#!/bin/bash\na="$PWD";cd "$(mktemp -d)"||exit;%s'\ + 'printf '"'$(gzip -9 a;export BASHBOT_HOME="$a";chmod +x a;./a "$@";a="$PWD";cd ..;rm -rf "$a"' } >"${outfile}" chmod +x "${outfile}" ls -l "${outfile}" -echo "Try to run ${outfile} init ;-)" +printf "Try to run %s init ;-)\n" "${outfile}" diff --git a/dev/version.sh b/dev/version.sh index add9a3d..6314d28 100755 --- a/dev/version.sh +++ b/dev/version.sh @@ -1,6 +1,6 @@ #!/bin/bash # -#### $$VERSION$$ v1.20-0-g2ab00a2 +#### $$VERSION$$ v1.21-pre-3-gbbbf57c # shellcheck disable=SC2016 # # Easy Versioning in git: @@ -40,28 +40,28 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null) if [ "$GIT_DIR" != "" ] ; then cd "$GIT_DIR/.." || exit 1 else - echo "Sorry, no git repository $(pwd)" && exit 1 + printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1 fi unset IFS # set -f # if you are paranoid use set -f to disable globbing VERSION="$(git describe --tags --long)" -echo "Update to version $VERSION ..." +printf "Update to version %s ...\n" "${VERSION}" FILES="$(find ./*)" [ "$1" != "" ] && FILES="$*" for file in $FILES do - [ ! -f "$file" ] && continue - #[ "$file" == "version" ] && continue - echo -n " $file" >&2 - sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '"$VERSION"'/' "$file" + [ ! -f "${file}" ] && continue + #[ "${file}" == "version" ] && continue + printf "%s" " ${file}" >&2 + sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '"${VERSION}"'/' "${file}" done # try to compile README.txt -echo -n " README.txt" >&2 +printf " README.txt" >&2 type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html fold -s README.md >README.txt -echo " done." +printf " done.\n"