2019-04-22 18:34:43 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-05-11 10:17:38 +00:00
|
|
|
# file: make-distribution.sh
|
|
|
|
# creates files and arcchives to dirtribute bashbot
|
|
|
|
#
|
2020-12-25 20:47:08 +00:00
|
|
|
#### $$VERSION$$ v1.20-0-g2ab00a2
|
2019-04-22 18:34:43 +00:00
|
|
|
|
|
|
|
# magic to ensure that we're always inside the root of our application,
|
|
|
|
# no matter from which directory we'll run script
|
2019-05-11 10:07:06 +00:00
|
|
|
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
|
|
|
|
if [ "$GIT_DIR" != "" ] ; then
|
2020-12-19 13:41:04 +00:00
|
|
|
[[ "$GIT_DIR" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}"
|
2019-05-11 10:07:06 +00:00
|
|
|
cd "$GIT_DIR/.." || exit 1
|
|
|
|
else
|
|
|
|
echo "Sorry, no git repository $(pwd)" && exit 1
|
|
|
|
fi
|
2019-04-22 18:34:43 +00:00
|
|
|
|
2019-04-30 12:21:24 +00:00
|
|
|
VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')"
|
2019-04-22 18:34:43 +00:00
|
|
|
|
|
|
|
DISTNAME="telegram-bot-bash"
|
2019-05-26 14:55:02 +00:00
|
|
|
DISTDIR="./DIST/${DISTNAME}"
|
2020-12-16 17:01:16 +00:00
|
|
|
DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh mycommands.sh.clean bin doc examples scripts modules addons LICENSE README.md README.txt README.html"
|
2019-04-22 18:34:43 +00:00
|
|
|
|
|
|
|
# run tests first!
|
|
|
|
|
2020-05-31 09:04:38 +00:00
|
|
|
for test in dev/all-test*.sh
|
2019-04-22 18:34:43 +00:00
|
|
|
do
|
2020-05-31 09:04:38 +00:00
|
|
|
[ ! -x "${test}" ] && continue
|
2019-04-22 18:34:43 +00:00
|
|
|
if ! "${test}" ; then
|
|
|
|
echo "Test ${test} failed, can't create dist!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-04-28 08:32:06 +00:00
|
|
|
# create dir for distribution and copy files
|
2019-04-22 18:34:43 +00:00
|
|
|
mkdir -p "${DISTDIR}" 2>/dev/null
|
|
|
|
# shellcheck disable=SC2086
|
2020-06-20 15:30:03 +00:00
|
|
|
echo "Copy files"
|
|
|
|
# shellcheck disable=SC2086
|
2019-04-22 18:34:43 +00:00
|
|
|
cp -r ${DISTFILES} "${DISTDIR}"
|
|
|
|
cd "${DISTDIR}" || exit 1
|
|
|
|
|
2019-05-25 15:02:25 +00:00
|
|
|
# do not overwrite on update
|
2020-06-20 15:30:03 +00:00
|
|
|
echo "Create .dist files"
|
2019-05-25 15:02:25 +00:00
|
|
|
for file in mycommands.sh bashbot.rc addons/*.sh
|
|
|
|
do
|
|
|
|
[ "${file}" = "addons/*.sh" ] && continue
|
|
|
|
mv "${file}" "${file}.dist"
|
|
|
|
done
|
2019-04-22 18:34:43 +00:00
|
|
|
|
2019-05-25 15:02:25 +00:00
|
|
|
# dwonload JSON.sh
|
2020-06-20 15:30:03 +00:00
|
|
|
echo "Inject JSON.sh"
|
2019-04-22 18:34:43 +00:00
|
|
|
JSONSHFILE="JSON.sh/JSON.sh"
|
2020-12-23 12:43:31 +00:00
|
|
|
if [ ! -r "${JSONSHFILE}" ]; then
|
2019-04-30 12:21:24 +00:00
|
|
|
mkdir "JSON.sh" 2>/dev/null
|
2019-04-22 18:34:43 +00:00
|
|
|
curl -sL -o "${JSONSHFILE}" "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh"
|
|
|
|
chmod +x "${JSONSHFILE}"
|
|
|
|
fi
|
2020-12-23 12:43:31 +00:00
|
|
|
echo "Inject JSON.awk"
|
|
|
|
JSONSHFILE="JSON.sh/JSON.awk"
|
|
|
|
if [ ! -r "${JSONSHFILE}" ]; then
|
|
|
|
curl -sL -o "${JSONSHFILE}" "https://cdn.jsdelivr.net/gh/step-/JSON.awk/JSON.awk"
|
|
|
|
curl -sL -o "${JSONSHFILE%/*}/awk-patch.sh" "https://cdn.jsdelivr.net/gh/step-/JSON.awk/tool/patch-for-busybox-awk.sh"
|
|
|
|
bash "${JSONSHFILE%/*}/awk-patch.sh" "${JSONSHFILE%/*}/JSON.awk"
|
|
|
|
fi
|
|
|
|
rm -f "${JSONSHFILE%/*}"/*.bak
|
2019-04-22 18:34:43 +00:00
|
|
|
|
2019-04-28 08:32:06 +00:00
|
|
|
# make html doc
|
2020-06-20 15:30:03 +00:00
|
|
|
echo "Create html doc"
|
2020-11-29 16:44:20 +00:00
|
|
|
# shellcheck disable=SC1090,SC1091
|
|
|
|
source "../../dev/make-html.sh"
|
2019-04-28 08:32:06 +00:00
|
|
|
|
2019-04-22 18:34:43 +00:00
|
|
|
# create archive
|
|
|
|
cd .. || exit 1
|
2020-06-20 15:30:03 +00:00
|
|
|
echo "Create dist archives"
|
2020-12-18 16:26:05 +00:00
|
|
|
# shellcheck disable=SC2046
|
2020-12-19 13:41:04 +00:00
|
|
|
zip -rq - "${DISTNAME}" --exclude $(cat "$GIT_DIR/../dev/${0##*/}.exclude") >"${DISTNAME}-${VERSION}.zip"
|
2020-12-18 16:26:05 +00:00
|
|
|
tar --exclude-ignore="$GIT_DIR/../dev/${0##*/}.exclude" -czf "${DISTNAME}-${VERSION}.tar.gz" "${DISTNAME}"
|
2019-04-22 18:34:43 +00:00
|
|
|
|
2020-06-20 15:30:03 +00:00
|
|
|
echo "Done!"
|
2019-04-22 18:34:43 +00:00
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
ls -ld ${DISTNAME}-${VERSION}.*
|
|
|
|
|
|
|
|
|