Files
cloudron-box/scripts/create-release-tarball

68 lines
2.1 KiB
Plaintext
Raw Normal View History

2015-08-04 16:29:49 -07:00
#!/bin/bash
set -eu
# Only GNU getopt supports long options. OS X comes bundled with the BSD getopt
# brew install gnu-getopt to get the GNU getopt on OS X
[[ $(uname -s) == "Darwin" ]] && GNU_GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" || GNU_GETOPT="getopt"
readonly GNU_GETOPT
args=$(${GNU_GETOPT} -o "" -l "output:,version:" -n "$0" -- "$@")
2015-08-04 16:29:49 -07:00
eval set -- "${args}"
readonly SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
2015-08-04 16:29:49 -07:00
bundle_file=""
version=""
2015-08-04 16:29:49 -07:00
while true; do
case "$1" in
--output) bundle_file="$2"; shift 2;;
--version) version="$2"; shift 2;;
2015-08-04 16:29:49 -07:00
--) break;;
*) echo "Unknown option $1"; exit 1;;
esac
done
if [[ -z "${version}" ]]; then
echo "--version is required"
exit 1
fi
2015-08-04 16:29:49 -07:00
readonly TMPDIR=${TMPDIR:-/tmp} # why is this not set on mint?
if ! $(cd "${SOURCE_DIR}" && git diff --exit-code >/dev/null); then
2023-02-25 00:00:40 +01:00
echo "You have local changes, stash or commit them to proceed"
2015-08-04 16:29:49 -07:00
exit 1
fi
if [[ "$(node --version)" != "v20.18.0" ]]; then
echo "This script requires node 20.18.0"
exit 1
fi
box_version=$(cd "${SOURCE_DIR}" && git rev-parse "HEAD")
2015-08-04 16:29:49 -07:00
bundle_dir=$(mktemp -d -t box 2>/dev/null || mktemp -d box-XXXXXXXXXX --tmpdir=$TMPDIR)
2023-02-25 00:00:40 +01:00
[[ -z "$bundle_file" ]] && bundle_file="${TMPDIR}/box-${box_version:0:10}-${box_version:0:10}-${version}.tar.gz"
2015-08-04 16:29:49 -07:00
chmod "o+rx,g+rx" "${bundle_dir}" # otherwise extracted tarball director won't be readable by others/group
2023-02-25 00:00:40 +01:00
echo "==> Checking out code box version [${box_version}] into ${bundle_dir}"
(cd "${SOURCE_DIR}" && git archive --format=tar ${box_version} | (cd "${bundle_dir}" && tar xf -))
echo "${version}" > "${bundle_dir}/VERSION"
2015-08-04 16:29:49 -07:00
echo "==> Building dashboard assets"
2023-09-27 11:21:12 +05:30
(cd "${bundle_dir}/dashboard" && npm ci --omit=dev)
2024-10-04 17:43:45 +02:00
(cd "${bundle_dir}/dashboard" && ./build.sh)
2023-02-25 00:38:35 +01:00
rm -rf "${bundle_dir}/dashboard/node_modules"
2015-08-04 16:29:49 -07:00
echo "==> Installing toplevel node modules"
(cd "${bundle_dir}" && npm ci --omit=dev --omit=optional --tldjs-update-rules)
2015-08-04 16:29:49 -07:00
echo "==> Create final tarball"
2015-08-04 16:29:49 -07:00
(cd "${bundle_dir}" && tar czf "${bundle_file}" .)
echo "==> Cleaning up ${bundle_dir}"
2015-08-04 16:29:49 -07:00
rm -rf "${bundle_dir}"
echo "==> Tarball saved at ${bundle_file}"