2019-05-11 12:07:06 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-12-27 21:19:32 +01:00
|
|
|
###################################################################
|
2019-05-11 12:17:38 +02:00
|
|
|
#
|
2020-12-27 21:19:32 +01:00
|
|
|
# File: make-standalone.sh
|
2019-05-11 12:17:38 +02:00
|
|
|
#
|
2020-12-27 21:19:32 +01:00
|
|
|
# Description:
|
|
|
|
# even after make-distribution.sh bashbot is not self contained as it was in the past.
|
|
|
|
#
|
|
|
|
# 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!
|
|
|
|
#
|
2021-01-05 16:17:34 +01:00
|
|
|
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
|
2020-12-27 21:19:32 +01:00
|
|
|
###################################################################
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
# magic to ensure that we're always inside the root of our application,
|
|
|
|
# no matter from which directory we'll run script
|
|
|
|
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
|
2021-01-05 11:40:28 +01:00
|
|
|
if [ "${GIT_DIR}" != "" ] ; then
|
|
|
|
[[ "${GIT_DIR}" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}"
|
|
|
|
cd "${GIT_DIR}/.." || exit 1
|
2019-05-11 12:07:06 +02:00
|
|
|
else
|
2021-01-01 11:27:54 +01:00
|
|
|
[ ! -f "bashbot.sh" ] && printf "bashbot.sh not found in %s\n" " $(pwd)" && exit 1
|
2019-05-11 12:07:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#DISTNAME="telegram-bot-bash"
|
2021-01-05 11:40:28 +01:00
|
|
|
DISTDIR="./STANDALONE"
|
2020-06-20 17:40:07 +02:00
|
|
|
DISTFILES="bashbot.sh bashbot.rc commands.sh mycommands.sh dev/obfuscate.sh modules scripts logs LICENSE README.* doc botacl botconfig.jssh"
|
2019-05-11 12:07:06 +02:00
|
|
|
|
2020-06-08 12:04:48 +02:00
|
|
|
# run pre_commit on files
|
|
|
|
dev/hooks/pre-commit.sh
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
# create dir for distribution and copy files
|
|
|
|
mkdir -p "${DISTDIR}" 2>/dev/null
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
cp -r ${DISTFILES} "${DISTDIR}" 2>/dev/null
|
|
|
|
cd "${DISTDIR}" || exit 1
|
|
|
|
|
2020-12-27 21:19:32 +01:00
|
|
|
# inject JSON.sh into distribution
|
|
|
|
# shellcheck disable=SC1090
|
2021-01-05 11:40:28 +01:00
|
|
|
source "${GIT_DIR}/../dev/inject-json.sh"
|
2020-12-27 21:19:32 +01:00
|
|
|
|
2019-05-11 12:07:06 +02:00
|
|
|
#######################
|
|
|
|
# here the magic starts
|
|
|
|
# create all in one bashbot.sh file
|
|
|
|
|
2021-01-01 11:43:50 +01:00
|
|
|
printf "OK, now lets do the magic ...\n\t... create unified commands.sh\n"
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
# first head of commands.sh
|
2020-11-30 18:36:21 +01:00
|
|
|
sed -n '0,/^if / p' commands.sh | grep -v -F -e "___" -e "*MUST*" -e "mycommands.sh.dist" -e "mycommands.sh.clean"| head -n -2
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
# then mycommands from first non comment line on
|
|
|
|
printf '\n##############################\n# my commands starts here ...\n'
|
|
|
|
sed -n '/^$/,$ p' mycommands.sh
|
|
|
|
|
|
|
|
# last tail of commands.sh
|
|
|
|
printf '\n##############################\n# default commands starts here ...\n'
|
2020-06-20 17:30:03 +02:00
|
|
|
sed -n '/source .*\/mycommands.sh"/,$ p' commands.sh | tail -n +2
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
} >>$$commands.sh
|
|
|
|
|
|
|
|
mv $$commands.sh commands.sh
|
|
|
|
rm -f mycommands.sh
|
|
|
|
|
2021-01-01 11:43:50 +01:00
|
|
|
printf "\n... create unified bashbot.sh\n"
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
# first head of bashbot.sh
|
2019-05-31 22:53:48 +02:00
|
|
|
sed -n '0,/for modules in/ p' bashbot.sh | head -n -3
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
# then mycommands from first non comment line on
|
|
|
|
printf '\n##############################\n# bashbot modules starts here ...\n'
|
|
|
|
cat modules/*.sh | sed -e 's/^#\!\/bin\/bash.*//'
|
|
|
|
|
|
|
|
# last tail of commands.sh
|
2019-05-14 17:56:23 +02:00
|
|
|
printf '\n##############################\n# bashbot internal functions starts here ...\n\n'
|
2020-06-08 12:58:36 +02:00
|
|
|
sed -n '/BASHBOT INTERNAL functions/,$ p' bashbot.sh
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
} >>$$bashbot.sh
|
|
|
|
|
|
|
|
mv $$bashbot.sh bashbot.sh
|
|
|
|
chmod +x bashbot.sh
|
|
|
|
|
|
|
|
rm -rf modules
|
|
|
|
|
2021-01-01 11:27:54 +01:00
|
|
|
printf "Create minimized Version of bashbot.sh and commands.sh\n"
|
2021-01-03 22:39:36 +01:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
sed -E -e '/(shellcheck)|(^#!\/)|(\$\$VERSION\$\$)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e '/^$/d' -e 'N;s/\\\n/ /;P;D' bashbot.sh |\
|
2020-06-28 23:02:58 +02:00
|
|
|
sed 'N;s/\\\n/ /;P;D' > bashbot.sh.min
|
2021-01-03 22:39:36 +01:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
sed -E -e '/(shellcheck)|(^#!\/)|(\$\$VERSION\$\$)/! s/^[[:space:]]*#.*//' -e 's/^[[:space:]]*//' -e 's/\)[[:space:]]+#.*/)/' -e '/^$/d' commands.sh |\
|
2020-06-28 23:02:58 +02:00
|
|
|
sed 'N;s/\\\n/ /;P;D' > commands.sh.min
|
2020-06-08 12:04:48 +02:00
|
|
|
chmod +x bashbot.sh.min
|
|
|
|
|
2020-06-20 17:30:03 +02:00
|
|
|
# make html doc
|
2021-01-01 11:27:54 +01:00
|
|
|
printf "Create html doc\n"
|
2020-06-20 17:30:03 +02:00
|
|
|
#shellcheck disable=SC1090
|
2021-01-05 11:40:28 +01:00
|
|
|
source "${GIT_DIR}/../dev/make-html.sh"
|
2020-06-20 17:30:03 +02:00
|
|
|
|
2021-01-01 11:27:54 +01:00
|
|
|
printf "%s Done!\n" "$0"
|
2019-05-11 12:07:06 +02:00
|
|
|
|
|
|
|
cd .. || exit 1
|
|
|
|
|
2021-01-01 11:27:54 +01:00
|
|
|
printf "\nStandalone bashbot files are now available in %s:\n\n" "${DISTDIR}"
|
2020-06-20 17:30:03 +02:00
|
|
|
ls -l "${DISTDIR}"
|
2019-05-11 12:07:06 +02:00
|
|
|
|