telegram-bot-bash/dev/make-distribution.sh

89 lines
2.4 KiB
Bash
Raw Normal View History

2019-04-22 18:34:43 +00:00
#!/usr/bin/env bash
2020-12-27 16:27:04 +00:00
##############################################################
2019-05-11 10:17:38 +00:00
#
2020-12-27 16:27:04 +00:00
# File: make-distribution.sh
#
# Description: creates files and arcchives to distribute bashbot
#
# Options: --notest - skip tests
#
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
2020-12-27 16:27:04 +00:00
##############################################################
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
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
2021-01-05 10:40:28 +00:00
if [ "${GIT_DIR}" != "" ] ; then
[[ "${GIT_DIR}" != "/"* ]] && GIT_DIR="${PWD}/${GIT_DIR}"
cd "${GIT_DIR}/.." || exit 1
else
2021-01-01 10:27:54 +00:00
printf "Sorry, no git repository %s\n" "$(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}"
DISTMKDIR="data-bot-bash logs bin bin/logs addons"
DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh.clean bin doc examples scripts modules LICENSE README.md README.txt README.html"
DISTFILESDIST="mycommands.sh bashbot.rc $(echo "addons/"*.sh)"
2019-04-22 18:34:43 +00:00
# run tests first!
2020-12-27 16:27:04 +00:00
for test in $1 dev/all-test*.sh
2019-04-22 18:34:43 +00:00
do
2020-12-27 16:27:04 +00:00
[[ "${test}" == "--notest"* ]] && break
[ ! -x "${test}" ] && continue
2019-04-22 18:34:43 +00:00
if ! "${test}" ; then
printf "ERROR: Test %s failed, can't create dist!\n" "${test}"
2019-04-22 18:34:43 +00:00
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
2020-12-29 12:59:31 +00:00
2021-01-01 10:27:54 +00:00
printf "Copy files\n"
# shellcheck disable=SC2086
2019-04-22 18:34:43 +00:00
cp -r ${DISTFILES} "${DISTDIR}"
cd "${DISTDIR}" || exit 1
2021-01-01 10:27:54 +00:00
printf "Create directories\n"
2021-01-05 10:40:28 +00:00
# shellcheck disable=SC2250
2020-12-29 12:59:31 +00:00
for dir in $DISTMKDIR
do
[ ! -d "${dir}" ] && mkdir "${dir}"
done
2019-05-25 15:02:25 +00:00
# do not overwrite on update
2021-01-01 10:27:54 +00:00
printf "Create .dist files\n"
for file in ${DISTFILESDIST}
2019-05-25 15:02:25 +00:00
do
[ "${file}" = "addons/*.sh" ] && continue
cp "${GIT_DIR}/../${file}" "${file}.dist"
2019-05-25 15:02:25 +00:00
done
2019-04-22 18:34:43 +00:00
2020-12-27 20:19:32 +00:00
# inject JSON.sh into distribution
# shellcheck disable=SC1090
2021-01-05 10:40:28 +00:00
source "${GIT_DIR}/../dev/inject-json.sh"
2019-04-22 18:34:43 +00:00
2019-04-28 08:32:06 +00:00
# make html doc
2021-01-01 10:27:54 +00:00
printf "Create html doc\n"
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
2021-01-01 10:27:54 +00:00
printf "Create dist archives\n"
# shellcheck disable=SC2046
2021-01-05 10:40:28 +00:00
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}"
2019-04-22 18:34:43 +00:00
2021-01-01 10:27:54 +00:00
printf "%s Done!\n" "$0"
2019-04-22 18:34:43 +00:00
# shellcheck disable=SC2086
2021-01-05 10:40:28 +00:00
ls -ld "${DISTNAME}-${VERSION}".*
2019-04-22 18:34:43 +00:00
2021-01-03 11:06:39 +00:00
# an empty DEBUG.log is created ... :-(
2021-01-05 10:40:28 +00:00
rm -f "${GIT_DIR}/../test/"*.log