#!/usr/bin/env bash set -e # Avoid dependency on locale LC_ALL=C # Normalize output directory if [ -n "$OUTPUT_DIR" ]; then OUTPUT_DIR=$(realpath -m "$OUTPUT_DIR") fi CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$CUR_DIR" ROOT_DIR=$(readlink -f "$(git rev-parse --show-cdup)") PKG_ROOT='root' DEB_ARCH=${DEB_ARCH:-amd64} OUTPUT_DIR=${OUTPUT_DIR:-$ROOT_DIR} [ -d "${OUTPUT_DIR}" ] || mkdir -p "${OUTPUT_DIR}" SANITIZER=${SANITIZER:-""} SOURCE=${SOURCE:-$PKG_ROOT} HELP="${0} [--test] [--rpm] [-h|--help] --test - adds '+test' prefix to version --apk - build APK packages --archlinux - build archlinux packages --rpm - build RPM packages --tgz - build tarball package --deb - build deb package --help - show this help and exit Used envs: DEB_ARCH='${DEB_ARCH}' OUTPUT_DIR='${OUTPUT_DIR}' - where the artifact will be placed SANITIZER='${SANITIZER}' - if any sanitizer is used, affects version string SOURCE='${SOURCE}' - directory with sources tree VERSION_STRING='${VERSION_STRING}' - the package version to overwrite " if [ -z "${VERSION_STRING}" ]; then # Get CLICKHOUSE_VERSION_STRING from the current git repo eval "$("$ROOT_DIR/tests/ci/version_helper.py" -e)" else CLICKHOUSE_VERSION_STRING=${VERSION_STRING} fi export CLICKHOUSE_VERSION_STRING while [[ $1 == --* ]] do case "$1" in --test ) VERSION_POSTFIX+='+test' shift ;; --deb ) MAKE_DEB=1 shift ;; --apk ) MAKE_APK=1 shift ;; --archlinux ) MAKE_ARCHLINUX=1 shift ;; --rpm ) MAKE_RPM=1 shift ;; --tgz ) MAKE_TGZ=1 shift ;; --help ) echo "$HELP" exit ;; * ) echo "Unknown option $1" exit 2 ;; esac done function deb2tgz { local FILE PKG_NAME PKG_DIR PKG_PATH TARBALL FILE=$1 PKG_NAME=${FILE##*/}; PKG_NAME=${PKG_NAME%%_*} PKG_DIR="$PKG_NAME-$CLICKHOUSE_VERSION_STRING" PKG_PATH="$OUTPUT_DIR/$PKG_NAME-$CLICKHOUSE_VERSION_STRING" TARBALL="$OUTPUT_DIR/$PKG_NAME-$CLICKHOUSE_VERSION_STRING-$DEB_ARCH.tgz" rm -rf "$PKG_PATH" dpkg-deb -R "$FILE" "$PKG_PATH" mkdir -p "$PKG_PATH/install" cat > "$PKG_PATH/install/doinst.sh" << 'EOF' #!/bin/sh set -e SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" for filepath in `find $SCRIPTPATH/.. -type f -or -type l | grep -v "\.\./install/"`; do destpath=${filepath##$SCRIPTPATH/..} mkdir -p $(dirname "$destpath") cp -r "$filepath" "$destpath" done EOF chmod +x "$PKG_PATH/install/doinst.sh" if [ -f "$PKG_PATH/DEBIAN/postinst" ]; then tail +2 "$PKG_PATH/DEBIAN/postinst" >> "$PKG_PATH/install/doinst.sh" fi rm -rf "$PKG_PATH/DEBIAN" if [ -f "/usr/bin/pigz" ]; then tar --use-compress-program=pigz -cf "$TARBALL" -C "$OUTPUT_DIR" "$PKG_DIR" else tar -czf "$TARBALL" -C "$OUTPUT_DIR" "$PKG_DIR" fi rm -r "$PKG_PATH" } # Build options if [ -n "$SANITIZER" ]; then if [[ "$SANITIZER" == "address" ]]; then VERSION_POSTFIX+="+asan" elif [[ "$SANITIZER" == "thread" ]]; then VERSION_POSTFIX+="+tsan" elif [[ "$SANITIZER" == "memory" ]]; then VERSION_POSTFIX+="+msan" elif [[ "$SANITIZER" == "undefined" ]]; then VERSION_POSTFIX+="+ubsan" else echo "Unknown value of SANITIZER variable: $SANITIZER" exit 3 fi elif [[ $BUILD_TYPE == 'debug' ]]; then VERSION_POSTFIX+="+debug" fi if [[ "$PKG_ROOT" != "$SOURCE" ]]; then # packages are built only from PKG_SOURCE rm -rf "./$PKG_ROOT" ln -sf "$SOURCE" "$PKG_SOURCE" fi CLICKHOUSE_VERSION_STRING+=$VERSION_POSTFIX echo -e "\nCurrent version is $CLICKHOUSE_VERSION_STRING" for config in clickhouse*.yaml; do if [ -n "$MAKE_DEB" ] || [ -n "$MAKE_TGZ" ]; then echo "Building deb package for $config" # Preserve package path exec 9>&1 PKG_PATH=$(nfpm package --target "$OUTPUT_DIR" --config "$config" --packager deb | tee /dev/fd/9) PKG_PATH=${PKG_PATH##*created package: } exec 9>&- fi if [ -n "$MAKE_APK" ]; then echo "Building apk package for $config" nfpm package --target "$OUTPUT_DIR" --config "$config" --packager apk fi if [ -n "$MAKE_ARCHLINUX" ]; then echo "Building archlinux package for $config" nfpm package --target "$OUTPUT_DIR" --config "$config" --packager archlinux fi if [ -n "$MAKE_RPM" ]; then echo "Building rpm package for $config" nfpm package --target "$OUTPUT_DIR" --config "$config" --packager rpm fi if [ -n "$MAKE_TGZ" ]; then echo "Building tarball for $config" deb2tgz "$PKG_PATH" fi done # vim: ts=4: sw=4: sts=4: expandtab