2019-05-11 10:07:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-05-11 10:17:38 +00:00
|
|
|
# file: make-standalone.sh
|
|
|
|
# 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!
|
|
|
|
#
|
2020-07-27 16:14:18 +00:00
|
|
|
#### $$VERSION$$ 0.99-0-g2775000
|
2019-05-11 10:07:06 +00: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)
|
|
|
|
if [ "$GIT_DIR" != "" ] ; then
|
|
|
|
cd "$GIT_DIR/.." || exit 1
|
|
|
|
else
|
|
|
|
[ ! -f "bashbot.sh" ] && echo "bashbot.sh not found in $(pwd)" && exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#DISTNAME="telegram-bot-bash"
|
2019-05-26 14:55:02 +00:00
|
|
|
DISTDIR="./STANDALONE/${DISTNAME}"
|
2020-06-20 15:40:07 +00: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 10:07:06 +00:00
|
|
|
|
2020-06-08 10:04:48 +00:00
|
|
|
# run pre_commit on files
|
|
|
|
dev/hooks/pre-commit.sh
|
2019-05-11 10:07:06 +00: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
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# here the magic starts
|
|
|
|
# create all in one bashbot.sh file
|
|
|
|
|
2020-06-08 10:04:48 +00:00
|
|
|
echo "OK, now lets do the magic ..."
|
2019-05-11 10:07:06 +00:00
|
|
|
echo " ... create unified commands.sh"
|
|
|
|
|
|
|
|
{
|
|
|
|
# first head of commands.sh
|
2020-06-20 15:30:03 +00:00
|
|
|
sed -n '0,/^if / p' commands.sh | head -n -2
|
2019-05-11 10:07:06 +00: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 15:30:03 +00:00
|
|
|
sed -n '/source .*\/mycommands.sh"/,$ p' commands.sh | tail -n +2
|
2019-05-11 10:07:06 +00:00
|
|
|
|
|
|
|
} >>$$commands.sh
|
|
|
|
|
|
|
|
mv $$commands.sh commands.sh
|
|
|
|
rm -f mycommands.sh
|
|
|
|
|
|
|
|
echo " ... create unified bashbot.sh"
|
|
|
|
|
|
|
|
{
|
|
|
|
# first head of bashbot.sh
|
2019-05-31 20:53:48 +00:00
|
|
|
sed -n '0,/for modules in/ p' bashbot.sh | head -n -3
|
2019-05-11 10:07:06 +00: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 15:56:23 +00:00
|
|
|
printf '\n##############################\n# bashbot internal functions starts here ...\n\n'
|
2020-06-08 10:58:36 +00:00
|
|
|
sed -n '/BASHBOT INTERNAL functions/,$ p' bashbot.sh
|
2019-05-11 10:07:06 +00:00
|
|
|
|
|
|
|
} >>$$bashbot.sh
|
|
|
|
|
|
|
|
mv $$bashbot.sh bashbot.sh
|
|
|
|
chmod +x bashbot.sh
|
|
|
|
|
|
|
|
rm -rf modules
|
|
|
|
|
2020-06-08 10:04:48 +00:00
|
|
|
echo "Create minimized Version of bashbot.sh and commands.sh"
|
2020-06-28 21:02:58 +00:00
|
|
|
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 '/^$/d' commands.sh |\
|
|
|
|
sed 'N;s/\\\n/ /;P;D' > commands.sh.min
|
2020-06-08 10:04:48 +00:00
|
|
|
chmod +x bashbot.sh.min
|
|
|
|
|
2020-06-20 15:30:03 +00:00
|
|
|
# make html doc
|
|
|
|
echo "Create html doc"
|
|
|
|
#shellcheck disable=SC1090
|
|
|
|
source "$GIT_DIR/../dev/make-html.sh"
|
|
|
|
|
2019-05-11 10:07:06 +00:00
|
|
|
echo "Done!"
|
|
|
|
|
|
|
|
cd .. || exit 1
|
|
|
|
|
2020-06-23 14:35:50 +00:00
|
|
|
echo -e "\\nStandalone bashbot files are now available in \"${DISTDIR}\":\\n"
|
2020-06-20 15:30:03 +00:00
|
|
|
ls -l "${DISTDIR}"
|
2019-05-11 10:07:06 +00:00
|
|
|
|