2019-05-11 10:07:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-12-27 20:19:32 +00:00
|
|
|
###################################################################
|
2019-05-11 10:17:38 +00:00
|
|
|
#
|
2020-12-27 20:19:32 +00:00
|
|
|
# File: make-standalone.sh
|
2019-05-11 10:17:38 +00:00
|
|
|
#
|
2020-12-27 20:19:32 +00:00
|
|
|
# Description:
|
|
|
|
# even after make-distribution.sh bashbot is not self contained as it was in the past.
|
|
|
|
#
|
2021-01-15 17:36:09 +00:00
|
|
|
# Options: --notest
|
|
|
|
#
|
2020-12-27 20:19:32 +00:00
|
|
|
# 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!
|
|
|
|
#
|
2022-06-27 18:18:58 +00:00
|
|
|
#### $$VERSION$$ v1.52-1-g0dae2db
|
2020-12-27 20:19:32 +00:00
|
|
|
###################################################################
|
2019-05-11 10:07:06 +00:00
|
|
|
|
2021-03-06 10:45:28 +00:00
|
|
|
# include git config and change to base dir
|
2021-03-05 19:12:30 +00:00
|
|
|
incfile="${0%/*}/dev.inc.sh"
|
2021-01-15 13:23:19 +00:00
|
|
|
#shellcheck disable=SC1090
|
2021-03-05 19:12:30 +00:00
|
|
|
[ -f "${incfile}" ] && source "${incfile}"
|
2021-03-06 10:45:28 +00:00
|
|
|
|
|
|
|
# seems we are not in a dev env
|
|
|
|
if [ -z "${BASE_DIR}" ]; then
|
|
|
|
BASE_DIR="$(pwd)"
|
|
|
|
[[ "${BASE_DIR}" == *"/dev" ]] && BASE_DIR="${BASE_DIR%/*}"
|
|
|
|
# go to basedir
|
|
|
|
cd "${BASE_DIR}" || exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# see if if bashbot is in base dir
|
2021-01-15 13:23:19 +00:00
|
|
|
[ ! -f "bashbot.sh" ] && printf "bashbot.sh not found in %s\n" " $(pwd)" && exit 1
|
2019-05-11 10:07:06 +00:00
|
|
|
|
2021-03-06 10:45:28 +00:00
|
|
|
# run pre_commit if exist
|
|
|
|
[[ -f "dev/dev.inc.sh" && "$1" != "--notest" ]] && dev/hooks/pre-commit.sh
|
|
|
|
|
|
|
|
# files and dirs to copy
|
2019-05-11 10:07:06 +00:00
|
|
|
#DISTNAME="telegram-bot-bash"
|
2021-01-05 10:40:28 +00:00
|
|
|
DISTDIR="./STANDALONE"
|
2021-03-06 10:45:28 +00:00
|
|
|
DISTMKDIR="data-bot-bash logs bin/logs addons"
|
2021-03-08 07:06:35 +00:00
|
|
|
DISTFILES="bashbot.sh commands.sh mycommands.sh modules scripts LICENSE README.* doc addons"
|
2021-03-06 10:45:28 +00:00
|
|
|
DISTBINFILES="bin/bashbot_env.inc.sh bin/bashbot_stats.sh bin/process_batch.sh bin/process_update.sh bin/send_broadcast.sh bin/send_message.sh"
|
2019-05-11 10:07:06 +00:00
|
|
|
|
2021-03-08 07:06:35 +00:00
|
|
|
# add extra files, minimum mycommands.conf
|
|
|
|
extrafile="${BASE_DIR}/dev/${0##*/}.include"
|
|
|
|
[ ! -f "${extrafile}" ] && printf "bashbot.rc\nbotacl\nbotconfig.jssh\nmycommands.conf\ndev/obfuscate.sh\n" >"${extrafile}"
|
|
|
|
DISTFILES+=" $(<"${extrafile}")"
|
2021-03-07 08:09:48 +00:00
|
|
|
|
2019-05-11 10:07:06 +00:00
|
|
|
# create dir for distribution and copy files
|
2021-01-15 17:36:09 +00:00
|
|
|
printf "Create directories and copy files\n"
|
2021-03-06 10:45:28 +00:00
|
|
|
mkdir -p "${DISTDIR}/bin" 2>/dev/null
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
cp -rp ${DISTFILES} "${DISTDIR}" 2>/dev/null
|
2019-05-11 10:07:06 +00:00
|
|
|
# shellcheck disable=SC2086
|
2021-03-06 10:45:28 +00:00
|
|
|
cp -p ${DISTBINFILES} "${DISTDIR}/bin" 2>/dev/null
|
|
|
|
|
2019-05-11 10:07:06 +00:00
|
|
|
cd "${DISTDIR}" || exit 1
|
|
|
|
|
2021-03-10 07:39:17 +00:00
|
|
|
# remove log files
|
|
|
|
find . -name '*.log' -delete
|
|
|
|
|
2021-01-15 17:36:09 +00:00
|
|
|
# shellcheck disable=SC2250
|
|
|
|
for dir in $DISTMKDIR
|
|
|
|
do
|
|
|
|
[ ! -d "${dir}" ] && mkdir "${dir}"
|
|
|
|
done
|
|
|
|
|
2020-12-27 20:19:32 +00:00
|
|
|
# inject JSON.sh into distribution
|
|
|
|
# shellcheck disable=SC1090
|
2021-01-15 13:23:19 +00:00
|
|
|
source "${BASE_DIR}/dev/inject-json.sh"
|
2020-12-27 20:19:32 +00:00
|
|
|
|
2019-05-11 10:07:06 +00:00
|
|
|
#######################
|
|
|
|
# here the magic starts
|
|
|
|
# create all in one bashbot.sh file
|
|
|
|
|
2021-01-01 10:43:50 +00:00
|
|
|
printf "OK, now lets do the magic ...\n\t... create unified commands.sh\n"
|
2019-05-11 10:07:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
# first head of commands.sh
|
2020-11-30 17:36:21 +00: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 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
|
|
|
|
|
2021-03-06 10:45:28 +00:00
|
|
|
printf "\t... create unified bashbot.sh\n"
|
2019-05-11 10:07:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
# first head of bashbot.sh
|
2021-01-15 17:36:09 +00:00
|
|
|
sed -n '0,/for module in/ p' bashbot.sh | head -n -3
|
2019-05-11 10:07:06 +00:00
|
|
|
|
2021-01-20 18:50:19 +00:00
|
|
|
# then modules without shebang
|
2019-05-11 10:07:06 +00:00
|
|
|
printf '\n##############################\n# bashbot modules starts here ...\n'
|
2021-01-20 18:50:19 +00:00
|
|
|
# shellcheck disable=SC2016
|
|
|
|
cat modules/*.sh | sed -e 's/^#\!\/bin\/bash.*//' -e '/^#.*\$\$VERSION\$\$/d'
|
2019-05-11 10:07:06 +00:00
|
|
|
|
2021-01-20 18:50:19 +00:00
|
|
|
# last remaining commands.sh
|
|
|
|
printf '\n##############################\n'
|
|
|
|
sed -n '/^# read commands file/,$ 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
|
|
|
|
|
2021-01-01 10:27:54 +00:00
|
|
|
printf "Create minimized Version of bashbot.sh and commands.sh\n"
|
2021-01-03 21:39:36 +00:00
|
|
|
# shellcheck disable=SC2016
|
2021-01-20 18:50:19 +00:00
|
|
|
sed -E -e '/(shellcheck)|(^#!\/)|(\$\$VERSION\$\$)/! s/^[[:space:]]*#.*//' -e '/shellcheck/! s/\t+#.*//' -e 's/^[[:space:]]*//'\
|
|
|
|
-e '/^$/d' bashbot.sh | sed 'N;s/\\\n/ /;P;D' | sed 'N;s/\\\n/ /;P;D' > bashbot.sh.min
|
2021-01-03 21:39:36 +00:00
|
|
|
# shellcheck disable=SC2016
|
2021-01-20 18:50:19 +00:00
|
|
|
sed -E -e '/(shellcheck)|(^#!\/)|(\$\$VERSION\$\$)/! s/^[[:space:]]*#.*//' -e '/shellcheck/! s/\t+#.*//' -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
|
2021-01-01 10:27:54 +00:00
|
|
|
printf "Create html doc\n"
|
2020-06-20 15:30:03 +00:00
|
|
|
#shellcheck disable=SC1090
|
2021-01-15 13:23:19 +00:00
|
|
|
source "${BASE_DIR}/dev/make-html.sh"
|
2020-06-20 15:30:03 +00:00
|
|
|
|
2021-01-01 10:27:54 +00:00
|
|
|
printf "%s Done!\n" "$0"
|
2019-05-11 10:07:06 +00:00
|
|
|
|
|
|
|
cd .. || exit 1
|
|
|
|
|
2021-01-01 10:27:54 +00:00
|
|
|
printf "\nStandalone bashbot files are now available in %s:\n\n" "${DISTDIR}"
|
2020-06-20 15:30:03 +00:00
|
|
|
ls -l "${DISTDIR}"
|
2019-05-11 10:07:06 +00:00
|
|
|
|