dev/: convert echo

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-01 11:27:54 +01:00
parent bbbf57c5d6
commit 3193169256
8 changed files with 64 additions and 60 deletions

View File

@ -5,7 +5,7 @@
# #
# Description: run all tests, exit after failed test # 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, # 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 if [ "$GIT_DIR" != "" ] ; then
cd "$GIT_DIR/.." || exit 1 cd "$GIT_DIR/.." || exit 1
else else
echo "Sorry, no git repository $(pwd)" && exit 1 printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1
fi fi
########################## ##########################
@ -39,20 +39,20 @@ fail=0
tests=0 tests=0
passed=0 passed=0
#all_tests=${__dirname:} #all_tests=${__dirname:}
#echo PLAN ${#all_tests} #printf PLAN ${#all_tests}
for test in $(find ./*-test.sh | sort -u) ; for test in $(find ./*-test.sh | sort -u) ;
do do
[ "${test}" = "dev/all-tests.sh" ] && continue [ "${test}" = "dev/all-tests.sh" ] && continue
[ ! -x "${test}" ] && continue [ ! -x "${test}" ] && continue
tests=$((tests+1)) tests=$((tests+1))
echo "TEST: ${test}" printf "TEST: %s\n" "${test}"
"${test}" "${TESTENV}" "${test}" "${TESTENV}"
ret=$? ret=$?
if [ "$ret" -eq 0 ] ; then if [ "$ret" -eq 0 ] ; then
echo "OK: ---- ${test}" printf "OK: ---- %s\n" "${test}"
passed=$((passed+1)) passed=$((passed+1))
else else
echo "FAIL: $test $fail" printf "FAIL: %s\n" "${test} ${fail}"
fail=$((fail+ret)) fail=$((fail+ret))
break break
fi fi
@ -61,11 +61,11 @@ done
########################### ###########################
# cleanup depending on test state # cleanup depending on test state
if [ "$fail" -eq 0 ]; then if [ "$fail" -eq 0 ]; then
/bin/echo -n 'SUCCESS ' printf 'SUCCESS '
exitcode=0 exitcode=0
rm -rf "${TESTENV}" rm -rf "${TESTENV}"
else else
/bin/echo -n 'FAILURE ' printf 'FAILURE '
exitcode=1 exitcode=1
rm -rf "${TESTENV}/test" rm -rf "${TESTENV}/test"
find "${TESTENV}/"* ! -name '[a-z]-*' -delete find "${TESTENV}/"* ! -name '[a-z]-*' -delete
@ -73,9 +73,9 @@ fi
######################### #########################
# show test result and test logs # show test result and test logs
echo -e "${passed} / ${tests}\\n" printf "%s\n\n" "${passed} / ${tests}"
[ -d "${TESTENV}" ] && echo "Logfiles from run are in ${TESTENV}" [ -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} exit ${exitcode}

View File

@ -3,7 +3,7 @@
# #
# works together with git pre-push.sh and ADD all changed files since last push # 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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # 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 if [ "$GIT_DIR" != "" ] ; then
cd "$GIT_DIR/.." || exit 1 cd "$GIT_DIR/.." || exit 1
else else
echo "Sorry, no git repository $(pwd)" && exit 1 printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1
fi 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 set +f
FILES="$(find ./* -newer .git/.lastpush| grep -v -e 'DIST\/' -e 'STANDALONE\/' -e 'JSON.sh')" FILES="$(find ./* -newer .git/.lastpush| grep -v -e 'DIST\/' -e 'STANDALONE\/' -e 'JSON.sh')"
set -f set -f
# FILES="$(find ./* -newer .git/.lastpush)" # 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 # run pre_commit on files
dev/hooks/pre-commit.sh dev/hooks/pre-commit.sh
echo -e "Add files to repo: \c" printf "Add files to repo: "
# shellcheck disable=SC2086 # shellcheck disable=SC2086
for file in ${FILES} for file in ${FILES}
do do
[ -d "${file}" ] && continue [ -d "${file}" ] && continue
echo -e "${file} \c" printf "%s" "${file} "
git add "$file" git add "$file"
done done
echo " - Done." printf " - Done.\n"

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# this has to run once atfer git clone # this has to run once atfer git clone
# and every time we create new hooks # 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, # magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script # 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 if [ "$GIT_DIR" != "" ] ; then
cd "$GIT_DIR/.." || exit 1 cd "$GIT_DIR/.." || exit 1
else else
echo "Sorry, no git repository $(pwd)" && exit 1 printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1
fi fi
HOOKDIR="dev/hooks" HOOKDIR="dev/hooks"
echo -n "Installing hooks..." printf "Installing hooks..."
for hook in pre-commit post-commit pre-push for hook in pre-commit post-commit pre-push
do do
rm -f "${GIT_DIR}/hooks/${hook}" rm -f "${GIT_DIR}/hooks/${hook}"
if [ -f "${HOOKDIR}/${hook}.sh" ]; then if [ -f "${HOOKDIR}/${hook}.sh" ]; then
echo -n " $hook" printf "%s"" $hook"
ln -s "../../${HOOKDIR}/${hook}.sh" "${GIT_DIR}/hooks/${hook}" ln -s "../../${HOOKDIR}/${hook}.sh" "${GIT_DIR}/hooks/${hook}"
fi fi
done done
echo " Done!" printf " Done!\n"

View File

@ -7,7 +7,7 @@
# #
# Options: --notest - skip tests # 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, # 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}" [[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}"
cd "$GIT_DIR/.." || exit 1 cd "$GIT_DIR/.." || exit 1
else else
echo "Sorry, no git repository $(pwd)" && exit 1 printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1
fi fi
VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')" VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')"
@ -33,7 +33,7 @@ do
[[ "${test}" == "--notest"* ]] && break [[ "${test}" == "--notest"* ]] && break
[ ! -x "${test}" ] && continue [ ! -x "${test}" ] && continue
if ! "${test}" ; then if ! "${test}" ; then
echo "Test ${test} failed, can't create dist!" printf "Test %s failed, can't create dist!\n" "${test}"
exit 1 exit 1
fi fi
done done
@ -41,19 +41,19 @@ done
# create dir for distribution and copy files # create dir for distribution and copy files
mkdir -p "${DISTDIR}" 2>/dev/null mkdir -p "${DISTDIR}" 2>/dev/null
echo "Copy files" printf "Copy files\n"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
cp -r ${DISTFILES} "${DISTDIR}" cp -r ${DISTFILES} "${DISTDIR}"
cd "${DISTDIR}" || exit 1 cd "${DISTDIR}" || exit 1
echo "Create directories" printf "Create directories\n"
for dir in $DISTMKDIR for dir in $DISTMKDIR
do do
[ ! -d "${dir}" ] && mkdir "${dir}" [ ! -d "${dir}" ] && mkdir "${dir}"
done done
# do not overwrite on update # do not overwrite on update
echo "Create .dist files" printf "Create .dist files\n"
for file in mycommands.sh bashbot.rc addons/*.sh for file in mycommands.sh bashbot.rc addons/*.sh
do do
[ "${file}" = "addons/*.sh" ] && continue [ "${file}" = "addons/*.sh" ] && continue
@ -65,18 +65,18 @@ done
source "$GIT_DIR/../dev/inject-json.sh" source "$GIT_DIR/../dev/inject-json.sh"
# make html doc # make html doc
echo "Create html doc" printf "Create html doc\n"
# shellcheck disable=SC1090,SC1091 # shellcheck disable=SC1090,SC1091
source "../../dev/make-html.sh" source "../../dev/make-html.sh"
# create archive # create archive
cd .. || exit 1 cd .. || exit 1
echo "Create dist archives" printf "Create dist archives\n"
# shellcheck disable=SC2046 # shellcheck disable=SC2046
zip -rq - "${DISTNAME}" --exclude $(cat "$GIT_DIR/../dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip" 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}" tar --exclude-ignore="$GIT_DIR/../dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}"
echo "Done!" printf "%s Done!\n" "$0"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
ls -ld ${DISTNAME}-${VERSION}.* ls -ld ${DISTNAME}-${VERSION}.*

View File

@ -7,17 +7,17 @@
# #
# Usage: source make-hmtl # Usage: source make-hmtl
# #
#### $$VERSION$$ v1.21-pre-2-ge22fcbf #### $$VERSION$$ v1.21-pre-3-gbbbf57c
############################################################## ##############################################################
# check for correct dir # check for correct dir
if [[ ! ( -f README.html && -f README.md ) ]]; then 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 else
# check if pandoc installed # check if pandoc installed
if [ "$(type -t pandoc)" != "file" ]; then if [ "$(type -t pandoc)" != "file" ]; then
echo "pandoc not found, skipping html generation ..." printf "pandoc not found, skipping html generation ...\n"
else else
######## ########

View File

@ -9,7 +9,7 @@
# If you your bot is finished you can use make-standalone.sh to create the # 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! # 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, # 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}" [[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}"
cd "$GIT_DIR/.." || exit 1 cd "$GIT_DIR/.." || exit 1
else 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 fi
#DISTNAME="telegram-bot-bash" #DISTNAME="telegram-bot-bash"
@ -43,8 +43,7 @@ source "$GIT_DIR/../dev/inject-json.sh"
# here the magic starts # here the magic starts
# create all in one bashbot.sh file # create all in one bashbot.sh file
echo "OK, now lets do the magic ..." printf "OK, now lets do the magic ...\n... create unified commands.sh\n"
echo " ... create unified commands.sh"
{ {
# first head of commands.sh # first head of commands.sh
@ -63,7 +62,7 @@ echo " ... create unified commands.sh"
mv $$commands.sh commands.sh mv $$commands.sh commands.sh
rm -f mycommands.sh rm -f mycommands.sh
echo " ... create unified bashbot.sh" printf " ... create unified bashbot.sh\n"
{ {
# first head of bashbot.sh # first head of bashbot.sh
@ -84,7 +83,7 @@ chmod +x bashbot.sh
rm -rf modules 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 -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 '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 |\ 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 chmod +x bashbot.sh.min
# make html doc # make html doc
echo "Create html doc" printf "Create html doc\n"
#shellcheck disable=SC1090 #shellcheck disable=SC1090
source "$GIT_DIR/../dev/make-html.sh" source "$GIT_DIR/../dev/make-html.sh"
echo "Done!" printf "%s Done!\n" "$0"
cd .. || exit 1 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}" ls -l "${DISTDIR}"

View File

@ -1,18 +1,23 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC2028,SC2016,SC1117 #
# joke hack to obfuscate bashbot.min.sh # joke hack to obfuscate bashbot.min.sh
#
# shellcheck disable=SC2028,SC2016,SC1117
infile="bashbot.sh" infile="bashbot.sh"
outfile="./bashbot.obf.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' # shellcheck disable=SC2183
echo 'a="$PWD";cd "$(mktemp -d)"||exit' printf '#!/bin/bash\na="$PWD";cd "$(mktemp -d)"||exit;%s'\
echo 'printf '"'%s\n'"' '"'$(gzip -9 <bashbot.sh | base64)'"'|base64 -d|gunzip >a;export BASHBOT_HOME="$a";chmod +x a;./a "$@";a="$PWD";cd ..;rm -rf "$a"' 'printf '"'$(gzip -9 <bashbot.sh | base64)'"'|base64 -d|gunzip >a;export BASHBOT_HOME="$a";chmod +x a;./a "$@";a="$PWD";cd ..;rm -rf "$a"'
} >"${outfile}" } >"${outfile}"
chmod +x "${outfile}" chmod +x "${outfile}"
ls -l "${outfile}" ls -l "${outfile}"
echo "Try to run ${outfile} init ;-)" printf "Try to run %s init ;-)\n" "${outfile}"

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# #
#### $$VERSION$$ v1.20-0-g2ab00a2 #### $$VERSION$$ v1.21-pre-3-gbbbf57c
# shellcheck disable=SC2016 # shellcheck disable=SC2016
# #
# Easy Versioning in git: # Easy Versioning in git:
@ -40,28 +40,28 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
if [ "$GIT_DIR" != "" ] ; then if [ "$GIT_DIR" != "" ] ; then
cd "$GIT_DIR/.." || exit 1 cd "$GIT_DIR/.." || exit 1
else else
echo "Sorry, no git repository $(pwd)" && exit 1 printf "Sorry, no git repository %s\n" "$(pwd)" && exit 1
fi fi
unset IFS unset IFS
# set -f # if you are paranoid use set -f to disable globbing # set -f # if you are paranoid use set -f to disable globbing
VERSION="$(git describe --tags --long)" VERSION="$(git describe --tags --long)"
echo "Update to version $VERSION ..." printf "Update to version %s ...\n" "${VERSION}"
FILES="$(find ./*)" FILES="$(find ./*)"
[ "$1" != "" ] && FILES="$*" [ "$1" != "" ] && FILES="$*"
for file in $FILES for file in $FILES
do do
[ ! -f "$file" ] && continue [ ! -f "${file}" ] && continue
#[ "$file" == "version" ] && continue #[ "${file}" == "version" ] && continue
echo -n " $file" >&2 printf "%s" " ${file}" >&2
sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '"$VERSION"'/' "$file" sed -i 's/^#### $$VERSION$$.*/#### \$\$VERSION\$\$ '"${VERSION}"'/' "${file}"
done done
# try to compile README.txt # 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 type -f pandoc >/dev/null && pandoc -s -f commonmark -M "title=Bashbot README" README.md >README.html
fold -s README.md >README.txt fold -s README.md >README.txt
echo " done." printf " done.\n"