2016-02-28 15:05:32 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-11-18 15:43:30 -08:00
|
|
|
# This script builds and archives binaries and supporting files for mac, linux, and windows.
|
|
|
|
# If directory ./server/static exists, it's asumed to contain TinodeWeb and then it's also
|
|
|
|
# copied and archived.
|
2020-02-13 14:32:18 +03:00
|
|
|
|
2021-11-18 15:43:30 -08:00
|
|
|
# Supported OSs: mac (darwin), windows, linux.
|
2023-07-02 08:18:28 -07:00
|
|
|
goplat=( darwin darwin windows linux linux )
|
2021-11-13 09:29:46 -08:00
|
|
|
|
2021-11-18 15:43:30 -08:00
|
|
|
# CPUs architectures: amd64 and arm64. The same order as OSs.
|
2023-07-02 08:18:28 -07:00
|
|
|
goarc=( amd64 arm64 amd64 amd64 arm64 )
|
2021-11-13 09:29:46 -08:00
|
|
|
|
|
|
|
# Number of platform+architectures.
|
|
|
|
buildCount=${#goplat[@]}
|
|
|
|
|
2018-04-17 18:28:43 -07:00
|
|
|
# Supported database tags
|
2023-04-06 13:59:11 -07:00
|
|
|
dbadapters=( mysql mongodb rethinkdb postgres )
|
2020-03-09 00:40:26 -07:00
|
|
|
dbtags=( ${dbadapters[@]} alldbs )
|
2018-04-17 18:28:43 -07:00
|
|
|
|
2018-04-19 19:15:34 -07:00
|
|
|
for line in $@; do
|
|
|
|
eval "$line"
|
|
|
|
done
|
|
|
|
|
|
|
|
version=${tag#?}
|
|
|
|
|
|
|
|
if [ -z "$version" ]; then
|
|
|
|
# Get last git tag as release version. Tag looks like 'v.1.2.3', so strip 'v'.
|
2018-04-29 10:43:36 -07:00
|
|
|
version=`git describe --tags`
|
2018-04-19 19:15:34 -07:00
|
|
|
version=${version#?}
|
|
|
|
fi
|
|
|
|
|
2018-04-22 20:35:32 -07:00
|
|
|
echo "Releasing $version"
|
|
|
|
|
2022-12-03 12:16:22 +08:00
|
|
|
GOSRC=..
|
2018-04-17 18:28:43 -07:00
|
|
|
|
2018-04-19 19:15:34 -07:00
|
|
|
pushd ${GOSRC}/chat > /dev/null
|
2018-04-17 18:28:43 -07:00
|
|
|
|
2018-04-18 10:17:54 -07:00
|
|
|
# Prepare directory for the new release
|
|
|
|
rm -fR ./releases/${version}
|
|
|
|
mkdir ./releases/${version}
|
|
|
|
|
2021-11-17 18:04:17 -08:00
|
|
|
# Tar on Mac is inflexible about directories. Let's just copy release files to
|
|
|
|
# one directory.
|
|
|
|
rm -fR ./releases/tmp
|
|
|
|
mkdir -p ./releases/tmp/templ
|
|
|
|
|
|
|
|
# Copy templates and database initialization files
|
|
|
|
cp ./server/tinode.conf ./releases/tmp
|
|
|
|
cp ./server/templ/*.templ ./releases/tmp/templ
|
|
|
|
cp ./tinode-db/data.json ./releases/tmp
|
|
|
|
cp ./tinode-db/*.jpg ./releases/tmp
|
|
|
|
cp ./tinode-db/credentials.sh ./releases/tmp
|
|
|
|
|
|
|
|
# Create directories for and copy TinodeWeb files.
|
|
|
|
if [[ -d ./server/static ]]
|
|
|
|
then
|
|
|
|
mkdir -p ./releases/tmp/static/img
|
|
|
|
mkdir ./releases/tmp/static/css
|
|
|
|
mkdir ./releases/tmp/static/audio
|
|
|
|
mkdir ./releases/tmp/static/src
|
|
|
|
mkdir ./releases/tmp/static/umd
|
|
|
|
|
|
|
|
cp ./server/static/img/*.png ./releases/tmp/static/img
|
|
|
|
cp ./server/static/img/*.svg ./releases/tmp/static/img
|
2022-06-20 19:45:39 -07:00
|
|
|
cp ./server/static/img/*.jpeg ./releases/tmp/static/img
|
2022-06-19 14:47:49 -07:00
|
|
|
cp ./server/static/audio/*.m4a ./releases/tmp/static/audio
|
2021-11-17 18:04:17 -08:00
|
|
|
cp ./server/static/css/*.css ./releases/tmp/static/css
|
|
|
|
cp ./server/static/index.html ./releases/tmp/static
|
|
|
|
cp ./server/static/index-dev.html ./releases/tmp/static
|
|
|
|
cp ./server/static/version.js ./releases/tmp/static
|
|
|
|
cp ./server/static/umd/*.js ./releases/tmp/static/umd
|
|
|
|
cp ./server/static/manifest.json ./releases/tmp/static
|
|
|
|
cp ./server/static/service-worker.js ./releases/tmp/static
|
|
|
|
# Create empty FCM client-side config.
|
2023-03-20 09:04:26 -07:00
|
|
|
echo 'const FIREBASE_INIT = {};' > ./releases/tmp/static/firebase-init.js
|
2021-11-17 18:04:17 -08:00
|
|
|
else
|
|
|
|
echo "TinodeWeb not found, skipping"
|
|
|
|
fi
|
|
|
|
|
2021-11-13 09:29:46 -08:00
|
|
|
for (( i=0; i<${buildCount}; i++ ));
|
2018-04-17 18:28:43 -07:00
|
|
|
do
|
2021-11-13 09:29:46 -08:00
|
|
|
plat="${goplat[$i]}"
|
|
|
|
arc="${goarc[$i]}"
|
2020-02-13 14:32:18 +03:00
|
|
|
|
2022-11-05 08:02:49 -07:00
|
|
|
# Use .exe file extension for binaries on Windows.
|
|
|
|
ext=""
|
|
|
|
if [ "$plat" = "windows" ]; then
|
|
|
|
ext=".exe"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove possibly existing keygen from previous build.
|
|
|
|
rm -f ./releases/tmp/keygen
|
|
|
|
rm -f ./releases/tmp/keygen.exe
|
2021-11-17 18:04:17 -08:00
|
|
|
|
2021-11-13 09:29:46 -08:00
|
|
|
# Keygen is database-independent
|
2022-11-05 08:02:49 -07:00
|
|
|
env GOOS="${plat}" GOARCH="${arc}" go build -ldflags "-s -w" -o ./releases/tmp/keygen${ext} ./keygen > /dev/null
|
2021-11-13 09:29:46 -08:00
|
|
|
|
|
|
|
for dbtag in "${dbtags[@]}"
|
|
|
|
do
|
|
|
|
echo "Building ${dbtag}-${plat}/${arc}..."
|
|
|
|
|
2022-11-05 08:02:49 -07:00
|
|
|
# Remove possibly existing binaries from previous build.
|
|
|
|
rm -f ./releases/tmp/tinode
|
|
|
|
rm -f ./releases/tmp/tinode.exe
|
|
|
|
rm -f ./releases/tmp/init-db
|
|
|
|
rm -f ./releases/tmp/init-db.exe
|
2021-11-17 18:04:17 -08:00
|
|
|
|
2021-11-13 09:29:46 -08:00
|
|
|
# Build tinode server and database initializer for RethinkDb and MySQL.
|
|
|
|
# For 'alldbs' tag, we compile in all available DB adapters.
|
|
|
|
if [ "$dbtag" = "alldbs" ]; then
|
|
|
|
buildtag="${dbadapters[@]}"
|
|
|
|
else
|
|
|
|
buildtag=$dbtag
|
|
|
|
fi
|
2021-11-17 18:04:17 -08:00
|
|
|
|
2021-11-13 09:29:46 -08:00
|
|
|
env GOOS="${plat}" GOARCH="${arc}" go build \
|
|
|
|
-ldflags "-s -w -X main.buildstamp=`git describe --tags`" -tags "${buildtag}" \
|
2022-11-05 08:02:49 -07:00
|
|
|
-o ./releases/tmp/tinode${ext} ./server > /dev/null
|
2021-11-13 09:29:46 -08:00
|
|
|
env GOOS="${plat}" GOARCH="${arc}" go build \
|
2022-11-05 08:02:49 -07:00
|
|
|
-ldflags "-s -w" -tags "${buildtag}" -o ./releases/tmp/init-db${ext} ./tinode-db > /dev/null
|
2021-11-13 09:29:46 -08:00
|
|
|
|
|
|
|
# Build archive. All platforms but Windows use tar for archiving. Windows uses zip.
|
|
|
|
if [ "$plat" = "windows" ]; then
|
|
|
|
# Remove possibly existing archive.
|
|
|
|
rm -f ./releases/${version}/tinode-${dbtag}."${plat}-${arc}".zip
|
|
|
|
# Generate a new one
|
|
|
|
pushd ./releases/tmp > /dev/null
|
|
|
|
zip -q -r ../${version}/tinode-${dbtag}."${plat}-${arc}".zip ./*
|
|
|
|
popd > /dev/null
|
|
|
|
else
|
|
|
|
plat2=$plat
|
|
|
|
# Rename 'darwin' tp 'mac'
|
|
|
|
if [ "$plat" = "darwin" ]; then
|
|
|
|
plat2=mac
|
2018-04-17 18:28:43 -07:00
|
|
|
fi
|
2021-11-13 09:29:46 -08:00
|
|
|
|
|
|
|
# Remove possibly existing archive.
|
|
|
|
rm -f ./releases/${version}/tinode-${dbtag}."${plat2}-${arc}".tar.gz
|
|
|
|
# Generate a new one
|
2021-11-17 18:04:17 -08:00
|
|
|
tar -C ./releases/tmp -zcf ./releases/${version}/tinode-${dbtag}."${plat2}-${arc}".tar.gz .
|
2021-11-13 09:29:46 -08:00
|
|
|
fi
|
2018-04-17 18:28:43 -07:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2018-04-19 11:17:39 -07:00
|
|
|
# Build chatbot release
|
2018-09-21 14:09:17 +03:00
|
|
|
echo "Building python code..."
|
2018-04-19 11:17:39 -07:00
|
|
|
|
2018-10-09 10:09:14 +03:00
|
|
|
./build-py-grpc.sh
|
2018-08-31 17:26:34 +03:00
|
|
|
|
2018-09-21 14:09:17 +03:00
|
|
|
# Release chatbot
|
|
|
|
echo "Packaging chatbot.py..."
|
2018-04-19 11:17:39 -07:00
|
|
|
rm -fR ./releases/tmp
|
|
|
|
mkdir -p ./releases/tmp
|
|
|
|
|
2018-09-21 14:09:17 +03:00
|
|
|
cp ${GOSRC}/chat/chatbot/python/chatbot.py ./releases/tmp
|
|
|
|
cp ${GOSRC}/chat/chatbot/python/quotes.txt ./releases/tmp
|
2020-02-15 08:57:04 +03:00
|
|
|
cp ${GOSRC}/chat/chatbot/python/requirements.txt ./releases/tmp
|
2018-04-19 11:17:39 -07:00
|
|
|
|
2018-09-21 14:09:17 +03:00
|
|
|
tar -C ${GOSRC}/chat/releases/tmp -zcf ./releases/${version}/py-chatbot.tar.gz .
|
2018-04-19 11:17:39 -07:00
|
|
|
pushd ./releases/tmp > /dev/null
|
2018-09-21 14:09:17 +03:00
|
|
|
zip -q -r ../${version}/py-chatbot.zip ./*
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
# Release tn-cli
|
|
|
|
echo "Packaging tn-cli..."
|
|
|
|
|
|
|
|
rm -fR ./releases/tmp
|
|
|
|
mkdir -p ./releases/tmp
|
|
|
|
|
2020-02-15 08:57:04 +03:00
|
|
|
cp ${GOSRC}/chat/tn-cli/*.py ./releases/tmp
|
2021-11-17 18:04:17 -08:00
|
|
|
cp ${GOSRC}/chat/tn-cli/*.txt ./releases/tmp
|
2018-09-21 14:09:17 +03:00
|
|
|
|
|
|
|
tar -C ${GOSRC}/chat/releases/tmp -zcf ./releases/${version}/tn-cli.tar.gz .
|
|
|
|
pushd ./releases/tmp > /dev/null
|
|
|
|
zip -q -r ../${version}/tn-cli.zip ./*
|
2018-04-19 11:17:39 -07:00
|
|
|
popd > /dev/null
|
|
|
|
|
2018-04-18 10:17:54 -07:00
|
|
|
# Clean up temporary files
|
|
|
|
rm -fR ./releases/tmp
|
|
|
|
|
2018-04-17 18:28:43 -07:00
|
|
|
popd > /dev/null
|