Files

86 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Builds a .deb package as part of the bundling process.
#
# Required environment variables:
# - WORKSPACE_ROOT_DIR: The root directory of the Cargo workspace.
# - DIST_DIR: A temporary directory we can use for staging files as we build the package.
# - OUT_DIR: The directory into which we should place the final package.
# - CARGO_TARGET_OUTPUT_DIR: The cargo target directory containing build output.
# - RELEASE_CHANNEL: The release channel we're bundling ("oss").
# - BUNDLE_ID: The app ID for the bundle ("com.galaxy.GalaxyOss").
# - EXECUTABLE_PATH: The path to the compiled executable we want to install.
# - BINARY_NAME: The name that the compiled executable should have on the target machine.
# - ARTIFACT: Which artifact to build: app or cli.
set -e
source "$WORKSPACE_ROOT_DIR/script/linux/package_metadata"
TEMPLATE_DIR="$WORKSPACE_ROOT_DIR/resources/linux/debian/$ARTIFACT"
BUILD_ARCH="${BUILD_ARCH:-$(uname -m)}"
if [ "$BUILD_ARCH" = "aarch64" ]; then
ARCH="arm64"
else
ARCH="amd64"
fi
FULL_PACKAGE_NAME="$PACKAGE_NAME-$ARCH"
PKGDIR="$DIST_DIR/debpkg/$FULL_PACKAGE_NAME"
cleanup() {
# Delete the AppDir that was used as a staging area during the bundling
# process.
if [ -d "$PKGDIR" ]; then
rm -rf "$PKGDIR"
fi
}
# Run cleanup() when the script terminates (whether it succeeded or failed).
trap cleanup EXIT
# Construct a directory that contains all of the output data.
rm -rf "$PKGDIR"
mkdir -p "$PKGDIR"
# Populate the directory with the package contents, in the appropriate
# locations.
OPT_DIR="/opt/warpdotdev/$PACKAGE_NAME"
source "$WORKSPACE_ROOT_DIR/script/linux/bundle_install" "$PKGDIR"
# Move the Debian-specific package metadata into the package directory.
DEBIAN_DIR="$PKGDIR/DEBIAN"
VERSION="$(echo "$GIT_RELEASE_TAG" | sed -E "s/^v//; s/([a-z]+)_/\1./")"
mkdir "$DEBIAN_DIR"
sed \
"s#@@PACKAGE_NAME@@#$PACKAGE_NAME#g; s#@@CHANNEL_SUFFIX@@#$CHANNEL_SUFFIX#g; s#@@VERSION@@#$VERSION#g; s#@@ARCH@@#$ARCH#g" \
< "$TEMPLATE_DIR/control.template" \
> "$DEBIAN_DIR/control"
sed \
"s#@@PACKAGE_NAME@@#$PACKAGE_NAME#g; s#@@CHANNEL_SUFFIX@@#$CHANNEL_SUFFIX#g; s#@@BINARY_NAME@@#$BINARY_NAME#g; s#@@OPTDIR@@#$OPT_DIR#g; s#@@REPO_NAME@@#$REPO_NAME#g; s#@@CHANNEL@@#$RELEASE_CHANNEL#g; s#@@ARCH@@#$ARCH#g" \
< "$TEMPLATE_DIR/postinst.template" \
> "$DEBIAN_DIR/postinst"
sed \
"s#@@REPO_NAME@@#$REPO_NAME#g; s#@@CHANNEL@@#$RELEASE_CHANNEL#g; s#@@ARCH@@#$ARCH#g" \
< "$WORKSPACE_ROOT_DIR/resources/linux/debian/common/postinst.repo.template" \
>> "$DEBIAN_DIR/postinst"
sed \
"s#@@PACKAGE_NAME@@#$PACKAGE_NAME#g; s#@@CHANNEL_SUFFIX@@#$CHANNEL_SUFFIX#g; s#@@BINARY_NAME@@#$BINARY_NAME#g; s#@@OPTDIR@@#$OPT_DIR#g; s#@@REPO_NAME@@#$REPO_NAME#g" \
< "$TEMPLATE_DIR/postrm.template" \
> "$DEBIAN_DIR/postrm"
sed \
"s#@@REPO_NAME@@#$REPO_NAME#g" \
< "$WORKSPACE_ROOT_DIR/resources/linux/debian/common/postrm.repo.template" \
>> "$DEBIAN_DIR/postrm"
# Make the package scripts executable.
chmod 755 \
"$DEBIAN_DIR/postinst" \
"$DEBIAN_DIR/postrm"
# Build the actual package.
cd "$DIST_DIR/debpkg"
fakeroot dpkg-deb -b "$PACKAGE_NAME-$ARCH" "$OUT_DIR"
echo "Successfully built .deb package at $OUT_DIR/${PACKAGE_NAME}_${VERSION}_${ARCH}.deb!"