|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +CURDIR="$(dirname "$(readlink -f "$0")")" |
| 4 | +BASEDIR="$(readlink -f "${CURDIR}"/../../)" |
| 5 | +. /etc/os-release |
| 6 | +print_usage() { |
| 7 | + echo "build_deb.sh --jobs 2 --target jammy" |
| 8 | + echo " --target target distribution codename" |
| 9 | + echo " --no-clean don't rebuild pbuilder tgz" |
| 10 | + echo " --jobs specify number of jobs" |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
| 14 | +TARGET= |
| 15 | +NO_CLEAN=0 |
| 16 | +JOBS="$(nproc)" |
| 17 | +while [ $# -gt 0 ]; do |
| 18 | + case "$1" in |
| 19 | + "--target") |
| 20 | + TARGET=$2 |
| 21 | + shift 2 |
| 22 | + ;; |
| 23 | + "--no-clean") |
| 24 | + NO_CLEAN=1 |
| 25 | + shift 1 |
| 26 | + ;; |
| 27 | + "--jobs") |
| 28 | + JOBS=$2 |
| 29 | + shift 2 |
| 30 | + ;; |
| 31 | + *) |
| 32 | + print_usage |
| 33 | + ;; |
| 34 | + esac |
| 35 | +done |
| 36 | + |
| 37 | +is_redhat_variant() { |
| 38 | + [[ -f /etc/redhat-release ]] |
| 39 | +} |
| 40 | +is_debian_variant() { |
| 41 | + [[ -f /etc/debian_version ]] |
| 42 | +} |
| 43 | +is_debian() { |
| 44 | + case "$1" in |
| 45 | + buster|bullseye|bookworm|trixie|sid) return 0;; |
| 46 | + *) return 1;; |
| 47 | + esac |
| 48 | +} |
| 49 | +is_ubuntu() { |
| 50 | + case "$1" in |
| 51 | + bionic|focal|jammy|mantic|noble) return 0;; |
| 52 | + *) return 1;; |
| 53 | + esac |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +APT_UPDATED=0 |
| 58 | +declare -A DEB_PKG=( |
| 59 | + ["debian-keyring"]="debian-archive-keyring" |
| 60 | + ["ubu-keyring"]="ubuntu-keyring" |
| 61 | +) |
| 62 | +pkg_install() { |
| 63 | + if is_redhat_variant; then |
| 64 | + sudo yum install -y "$1" |
| 65 | + elif is_debian_variant; then |
| 66 | + if [[ "${APT_UPDATED}" -eq 0 ]]; then |
| 67 | + sudo apt-get -y update |
| 68 | + APT_UPDATED=1 |
| 69 | + fi |
| 70 | + if [[ -n "${DEB_PKG[$1]}" ]]; then |
| 71 | + pkg="${DEB_PKG[$1]}" |
| 72 | + else |
| 73 | + pkg="$1" |
| 74 | + fi |
| 75 | + sudo apt-get install -y "$pkg" |
| 76 | + else |
| 77 | + echo "Requires to install following command: $1" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | +} |
| 81 | + |
| 82 | +if [[ ! -e dist/debian/build_deb.sh ]]; then |
| 83 | + echo "run build_deb.sh in top of scylla dir" |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | + |
| 87 | +if [[ -z "${TARGET}" ]]; then |
| 88 | + echo "Please specify target" |
| 89 | + exit 1 |
| 90 | +fi |
| 91 | + |
| 92 | +if [[ ! -f /usr/bin/git ]]; then |
| 93 | + pkg_install git |
| 94 | +fi |
| 95 | +if [[ ! -f /usr/sbin/pbuilder ]]; then |
| 96 | + pkg_install pbuilder |
| 97 | +fi |
| 98 | +if [[ ! -f /usr/bin/dh_testdir ]]; then |
| 99 | + pkg_install debhelper |
| 100 | +fi |
| 101 | +if is_debian "${TARGET}" && [[ ! -f /usr/share/keyrings/debian-archive-keyring.gpg ]]; then |
| 102 | + pkg_install debian-keyring |
| 103 | +fi |
| 104 | +if is_ubuntu "${TARGET}" && [[ ! -f /usr/share/keyrings/ubuntu-archive-keyring.gpg ]]; then |
| 105 | + pkg_install ubu-keyring |
| 106 | +fi |
| 107 | + |
| 108 | +./SCYLLA-VERSION-GEN |
| 109 | +DRIVER_NAME=scylla-cpp-rust-driver |
| 110 | +DRIVER_VERSION="$(sed 's/-/~/' build/SCYLLA-VERSION-FILE)" |
| 111 | +DRIVER_RELEASE="$(cat build/SCYLLA-RELEASE-FILE)" |
| 112 | +ARCH="$(dpkg --print-architecture)" |
| 113 | + |
| 114 | +mkdir -p build/debian/debs |
| 115 | +git archive HEAD --prefix "${DRIVER_NAME}-${DRIVER_VERSION}/" --output "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz" |
| 116 | + |
| 117 | +if is_debian "${TARGET}"; then |
| 118 | + DRIVER_REVISION="1~${TARGET}" |
| 119 | +elif is_ubuntu "${TARGET}"; then |
| 120 | + DRIVER_REVISION="0ubuntu1~${TARGET}" |
| 121 | +else |
| 122 | + echo "Unknown distribution: ${TARGET}" |
| 123 | +fi |
| 124 | +tar xpvf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz" -C build/debian |
| 125 | + |
| 126 | +./dist/debian/debian_files_gen.py --version "${DRIVER_VERSION}" --release "${DRIVER_RELEASE}" --revision "${DRIVER_REVISION}" --codename "${TARGET}" --output-dir "build/debian/${DRIVER_NAME}"-"${DRIVER_VERSION}"/debian |
| 127 | + |
| 128 | +# pbuilder generates files owned by root, fix this up |
| 129 | +fix_ownership() { |
| 130 | + CURRENT_UID="$(id -u)" |
| 131 | + CURRENT_GID="$(id -g)" |
| 132 | + sudo chown "${CURRENT_UID}":"${CURRENT_GID}" -R "$@" |
| 133 | +} |
| 134 | + |
| 135 | +BASETGZ="/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}-base.tgz" |
| 136 | +# use from pbuilderrc |
| 137 | +if [[ "${NO_CLEAN}" -eq 0 ]]; then |
| 138 | + sudo rm -fv "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}-base.tgz" |
| 139 | + sudo mkdir -p "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}/aptcache" |
| 140 | + sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder clean --configfile ./dist/debian/pbuilderrc |
| 141 | + sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder create --configfile ./dist/debian/pbuilderrc |
| 142 | +fi |
| 143 | +sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder update --configfile ./dist/debian/pbuilderrc |
| 144 | +(cd "build/debian/${DRIVER_NAME}"-"${DRIVER_VERSION}"; dpkg-source -b .) |
| 145 | +sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder build --configfile ./dist/debian/pbuilderrc --buildresult build/debian/debs "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}-${DRIVER_REVISION}.dsc" |
| 146 | +fix_ownership build/debian/debs |
0 commit comments