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
#
#### $$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}

View File

@ -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"

View File

@ -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"

View File

@ -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}.*

View File

@ -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
########

View File

@ -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}"

View File

@ -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 <bashbot.sh | base64)'"'|base64 -d|gunzip >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 <bashbot.sh | base64)'"'|base64 -d|gunzip >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}"

View File

@ -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"