From 59137f2d2f9211f7e135a8dead5571b9c7774e73 Mon Sep 17 00:00:00 2001 From: Surabhi Bhat Date: Fri, 26 Apr 2024 15:09:27 +0530 Subject: [PATCH] PKG-31 PG packages with Percona Telemetry Ph1 --- percona-packaging/debian/changelog | 5 + percona-packaging/debian/compat | 1 + percona-packaging/debian/control | 15 + percona-packaging/debian/control.in | 15 + percona-packaging/debian/pgversions | 1 + percona-packaging/debian/postinst | 12 + percona-packaging/debian/postrm | 48 ++ percona-packaging/debian/preinst | 11 + percona-packaging/debian/rules | 31 + percona-packaging/debian/source/format | 1 + .../debian/source/lintian-overrides | 3 + .../rpm/pg-percona-telemetry.spec | 72 +++ .../scripts/pg_percona_telemetry_builder.sh | 544 ++++++++++++++++++ 13 files changed, 759 insertions(+) create mode 100644 percona-packaging/debian/changelog create mode 100644 percona-packaging/debian/compat create mode 100644 percona-packaging/debian/control create mode 100644 percona-packaging/debian/control.in create mode 100644 percona-packaging/debian/pgversions create mode 100644 percona-packaging/debian/postinst create mode 100755 percona-packaging/debian/postrm create mode 100644 percona-packaging/debian/preinst create mode 100755 percona-packaging/debian/rules create mode 100644 percona-packaging/debian/source/format create mode 100644 percona-packaging/debian/source/lintian-overrides create mode 100644 percona-packaging/rpm/pg-percona-telemetry.spec create mode 100755 percona-packaging/scripts/pg_percona_telemetry_builder.sh diff --git a/percona-packaging/debian/changelog b/percona-packaging/debian/changelog new file mode 100644 index 0000000..37080b8 --- /dev/null +++ b/percona-packaging/debian/changelog @@ -0,0 +1,5 @@ +percona-pg-telemetry (1.0.0-1) unstable; urgency=medium + + * Initial build. + + -- Surabhi Bhat Fri, 26 Apr 2024 19:20:11 +0100 diff --git a/percona-packaging/debian/compat b/percona-packaging/debian/compat new file mode 100644 index 0000000..ec63514 --- /dev/null +++ b/percona-packaging/debian/compat @@ -0,0 +1 @@ +9 diff --git a/percona-packaging/debian/control b/percona-packaging/debian/control new file mode 100644 index 0000000..341f119 --- /dev/null +++ b/percona-packaging/debian/control @@ -0,0 +1,15 @@ +Source: percona-pg-telemetry +Section: database +Priority: optional +Maintainer: Percona Development Team +Build-Depends: + debhelper (>= 9), + postgresql-server-dev-all (>= 153~) | percona-postgresql-server-dev-all (>= 153~), + +Package: percona-pg-telemetryPGVERSION +Architecture: any +Depends: + percona-telemetry-agent, + ${misc:Depends}, + ${shlibs:Depends}, +Description:The percona_pg_telemetry is an extension for Percona telemetry data collection for PostgreSQL. diff --git a/percona-packaging/debian/control.in b/percona-packaging/debian/control.in new file mode 100644 index 0000000..341f119 --- /dev/null +++ b/percona-packaging/debian/control.in @@ -0,0 +1,15 @@ +Source: percona-pg-telemetry +Section: database +Priority: optional +Maintainer: Percona Development Team +Build-Depends: + debhelper (>= 9), + postgresql-server-dev-all (>= 153~) | percona-postgresql-server-dev-all (>= 153~), + +Package: percona-pg-telemetryPGVERSION +Architecture: any +Depends: + percona-telemetry-agent, + ${misc:Depends}, + ${shlibs:Depends}, +Description:The percona_pg_telemetry is an extension for Percona telemetry data collection for PostgreSQL. diff --git a/percona-packaging/debian/pgversions b/percona-packaging/debian/pgversions new file mode 100644 index 0000000..8f5523f --- /dev/null +++ b/percona-packaging/debian/pgversions @@ -0,0 +1 @@ +9.3+ diff --git a/percona-packaging/debian/postinst b/percona-packaging/debian/postinst new file mode 100644 index 0000000..f5d96da --- /dev/null +++ b/percona-packaging/debian/postinst @@ -0,0 +1,12 @@ +#!/bin/sh + +#DEBHELPER# +usermod -a -G percona-telemetry postgres + +mkdir /usr/local/percona/telemetry/pg +chown postgres:percona-telemetry /usr/local/percona/telemetry/pg +chmod 775 /usr/local/percona/telemetry/pg +chmod g+s /usr/local/percona/telemetry/pg +chmod u+s /usr/local/percona/telemetry/pg +exit 0 + diff --git a/percona-packaging/debian/postrm b/percona-packaging/debian/postrm new file mode 100755 index 0000000..20107ca --- /dev/null +++ b/percona-packaging/debian/postrm @@ -0,0 +1,48 @@ +#!/bin/bash + +# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; +then +. /usr/share/debconf/confmodule +fi + +case "$1" in + remove | purge) + set -e + PG_TELEMETRY=/usr/local/percona/telemetry/pg + if [ -d ${PG_TELEMETRY} ]; + then + rm -rf ${PG_TELEMETRY} + fi + + set +e + + ;; + + upgrade | failed-upgrade | abort-install | abort-upgrade | disappear) + + ;; + + *) + echo "postrm called with unknown argument '$1'" 1>&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/percona-packaging/debian/preinst b/percona-packaging/debian/preinst new file mode 100644 index 0000000..bce5718 --- /dev/null +++ b/percona-packaging/debian/preinst @@ -0,0 +1,11 @@ +#!/bin/sh +# preinst script for percona-pg-telemetry +# +# see: dh_installdeb(1) + +# create a postgres group and user +if ! getent passwd postgres > /dev/null 2>&1; then + groupadd -g 26 -o -r postgres >/dev/null 2>&1 || : + /usr/sbin/useradd -M -g postgres -s /bin/bash \ + -c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || : +fi diff --git a/percona-packaging/debian/rules b/percona-packaging/debian/rules new file mode 100755 index 0000000..519e76f --- /dev/null +++ b/percona-packaging/debian/rules @@ -0,0 +1,31 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# Using pg_buildext +include /usr/share/postgresql-common/pgxs_debian_control.mk + +export USE_PGXS=1 + +%: + dh $@ + +override_dh_builddeb: + dh_builddeb -- -Zgzip + +override_dh_auto_build: + +pg_buildext clean . build-%v + +pg_buildext build . build-%v + +override_dh_auto_test: + # nothing to do here + +override_dh_auto_install: + +pg_buildext install . build-%v percona-pg-telemetry@@PG_REL@@ + +override_dh_installdocs: + dh_installdocs --all README.* + +override_dh_auto_clean: + rm -rf results/* regression.* diff --git a/percona-packaging/debian/source/format b/percona-packaging/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/percona-packaging/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/percona-packaging/debian/source/lintian-overrides b/percona-packaging/debian/source/lintian-overrides new file mode 100644 index 0000000..4076145 --- /dev/null +++ b/percona-packaging/debian/source/lintian-overrides @@ -0,0 +1,3 @@ +# don't bug people uploading from @work +source: changelog-should-mention-nmu +source: source-nmu-has-incorrect-version-number diff --git a/percona-packaging/rpm/pg-percona-telemetry.spec b/percona-packaging/rpm/pg-percona-telemetry.spec new file mode 100644 index 0000000..23648bb --- /dev/null +++ b/percona-packaging/rpm/pg-percona-telemetry.spec @@ -0,0 +1,72 @@ +%global sname percona-pg-telemetry +%global pgrel @@PG_REL@@ +%global rpm_release @@RPM_RELEASE@@ +%global pginstdir /usr/pgsql-@@PG_REL@@/ + +Summary: Statistics collector for PostgreSQL +Name: %{sname}%{pgrel} +Version: @@VERSION@@ +Release: %{rpm_release}%{?dist} +License: PostgreSQL +Source0: percona-pg-telemetry%{pgrel}-%{version}.tar.gz +URL: https://github.com/Percona-Lab/percona_pg_telemetry +BuildRequires: percona-postgresql%{pgrel}-devel +Requires: percona-telemetry-agent +Provides: percona-pg-telemetry%{pgrel} +Conflicts: percona-pg-telemetry%{pgrel} +Obsoletes: percona-pg-telemetry%{pgrel} <= %{version}-%{release} +Epoch: 1 +Packager: Percona Development Team +Vendor: Percona, Inc + +%description +The percona_pg_telemetry is an extension for Percona telemetry data collection for PostgreSQL. + +%prep +%setup -q -n percona-pg-telemetry%{pgrel}-%{version} + + +%build +sed -i 's:PG_CONFIG = pg_config:PG_CONFIG = /usr/pgsql-%{pgrel}/bin/pg_config:' Makefile +%{__make} USE_PGXS=1 %{?_smp_mflags} + + +%install +%{__rm} -rf %{buildroot} +%{__make} USE_PGXS=1 %{?_smp_mflags} install DESTDIR=%{buildroot} +%{__install} -d %{buildroot}%{pginstdir}/share/extension +%{__install} -m 755 README.md %{buildroot}%{pginstdir}/share/extension/README-percona_pg_telemetry + + +%clean +%{__rm} -rf %{buildroot} + +%pre -n percona-pg-telemetry%{pgrel} +if [ $1 == 1 ]; then + if ! getent passwd postgres > /dev/null 2>&1; then + groupadd -g 26 -o -r postgres >/dev/null 2>&1 || : + /usr/sbin/useradd -M -g postgres -o -r -d /var/lib/pgsql -s /bin/bash \ + -c "PostgreSQL Server" -u 26 postgres >/dev/null 2>&1 || : + fi +fi + +%post -n percona-pg-telemetry%{pgrel} +usermod -a -G percona-telemetry postgres +install -d -m 2775 -o postgres -g percona-telemetry /usr/local/percona/telemetry/pg + +%postun -n percona-pg-telemetry%{pgrel} +rm -rf /usr/local/percona/telemetry/pg + +%files +%defattr(755,root,root,755) +%doc %{pginstdir}/share/extension/README-percona_pg_telemetry +%{pginstdir}/lib/percona_pg_telemetry.so +%{pginstdir}/share/extension/percona_pg_telemetry--*.sql +%{pginstdir}/share/extension/percona_pg_telemetry.control +%{pginstdir}/lib/bitcode/percona_pg_telemetry*.bc +%{pginstdir}/lib/bitcode/percona_pg_telemetry/*.bc + + +%changelog +* Fri Apr 26 2024 Surabhi Bhat - 1.0.0-1 +- Initial build diff --git a/percona-packaging/scripts/pg_percona_telemetry_builder.sh b/percona-packaging/scripts/pg_percona_telemetry_builder.sh new file mode 100755 index 0000000..4973fbd --- /dev/null +++ b/percona-packaging/scripts/pg_percona_telemetry_builder.sh @@ -0,0 +1,544 @@ +#!/usr/bin/env bash + +shell_quote_string() { + echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g' +} + +usage () { + cat <&2 "Current directory cannot be used for building!" + exit 1 + else + if ! test -d "$WORKDIR" + then + echo >&2 "$WORKDIR is not a directory." + exit 1 + fi + fi + return +} + +set_changelog(){ + if [ -z $1 ] + then + echo "No spec file is provided" + return + else + start_line=0 + while read -r line; do + (( start_line++ )) + if [ "$line" = "%changelog" ] + then + (( start_line++ )) + echo "$start_line" + current_date=$(date +"%a %b %d %Y") + sed -i "$start_line,$ d" $1 + echo "* $current_date Percona Build/Release Team - ${VERSION}-${RPM_RELEASE}" >> $1 + echo "- Release ${VERSION}-${RPM_RELEASE}" >> $1 + echo >> $1 + return + fi + done <$1 + fi +} + +get_sources(){ + cd "${WORKDIR}" + if [ "${SOURCE}" = 0 ] + then + echo "Sources will not be downloaded" + return 0 + fi + PRODUCT=percona-pg-telemetry${PG_RELEASE} + PRODUCT_FULL=${PRODUCT}-${VERSION} + + echo "PRODUCT=${PRODUCT}" > pg-percona-telemetry.properties + echo "PRODUCT_FULL=${PRODUCT_FULL}" >> pg-percona-telemetry.properties + echo "VERSION=${VERSION}" >> pg-percona-telemetry.properties + echo "BRANCH_NAME=$(echo ${BRANCH} | awk -F '/' '{print $(NF)}')" >> pg-percona-telemetry.properties + echo "BUILD_NUMBER=${BUILD_NUMBER}" >> pg-percona-telemetry.properties + echo "BUILD_ID=${BUILD_ID}" >> pg-percona-telemetry.properties + echo "BRANCH_NAME=$(echo ${BRANCH} | awk -F '/' '{print $(NF)}')" >> pg-percona-telemetry.properties + echo "PG_RELEASE=${PG_RELEASE}" >> pg-percona-telemetry.properties + echo "RPM_RELEASE=${RPM_RELEASE}" >> pg-percona-telemetry.properties + echo "DEB_RELEASE=${DEB_RELEASE}" >> pg-percona-telemetry.properties + git clone "$GIT_REPO" ${PRODUCT_FULL} + retval=$? + if [ $retval != 0 ] + then + echo "There were some issues during repo cloning from github. Please retry one more time" + exit 1 + fi + cd ${PRODUCT_FULL} + if [ ! -z "$BRANCH" ] + then + git reset --hard + git clean -xdf + git checkout "$BRANCH" + fi + REVISION=$(git rev-parse --short HEAD) + echo "REVISION=${REVISION}" >> ${WORKDIR}/pg-percona-telemetry.properties + + EDITFILES="percona-packaging/debian/control percona-packaging/debian/control.in percona-packaging/debian/rules percona-packaging/rpm/pg-percona-telemetry.spec" + for file in $EDITFILES; do + sed -i "s:@@PG_REL@@:${PG_RELEASE}:g" "$file" + done + + sed -i "s:@@RPM_RELEASE@@:${RPM_RELEASE}:g" percona-packaging/rpm/pg-percona-telemetry.spec + sed -i "s:@@VERSION@@:${VERSION}:g" percona-packaging/rpm/pg-percona-telemetry.spec + + set_changelog percona-packaging/rpm/pg-percona-telemetry.spec + + cd ${WORKDIR} + # + source pg-percona-telemetry.properties + # + tar --owner=0 --group=0 --exclude=.* -czf ${PRODUCT_FULL}.tar.gz ${PRODUCT_FULL} + echo "UPLOAD=UPLOAD/experimental/BUILDS/${PRODUCT}/${PRODUCT_FULL}/${BRANCH}/${REVISION}/${BUILD_ID}" >> pg-percona-telemetry.properties + mkdir $WORKDIR/source_tarball + mkdir $CURDIR/source_tarball + cp ${PRODUCT_FULL}.tar.gz $WORKDIR/source_tarball + cp ${PRODUCT_FULL}.tar.gz $CURDIR/source_tarball + cd $CURDIR + rm -rf percona-pg-telemetry* + return +} + +get_system(){ + if [ -f /etc/redhat-release ]; then + GLIBC_VER_TMP="$(rpm glibc -qa --qf %{VERSION})" + export RHEL=$(rpm --eval %rhel) + export ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g') + export OS_NAME="el$RHEL" + export OS="rpm" + else + ARCH=$(uname -m) + apt-get -y update + apt-get -y install lsb-release + export OS_NAME="$(lsb_release -sc)" + export OS="deb" + fi + return +} + +install_deps() { + if [ $INSTALL = 0 ] + then + echo "Dependencies will not be installed" + return; + fi + if [ $( id -u ) -ne 0 ] + then + echo "It is not possible to instal dependencies. Please run as root" + exit 1 + fi + CURPLACE=$(pwd) + if [ "$OS" == "rpm" ] + then + yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm + percona-release enable ${PPG_REPO} testing + + yum -y install git wget + PKGLIST="percona-postgresql${PG_RELEASE}-devel" + if [ x"$RHEL" = x8 ]; then + yum -y install python2-devel + llvm_version=$(yum list --showduplicates llvm-devel | grep "17.0" | grep llvm | awk '{print $2}' | head -n 1) + yum -y install llvm-devel--${llvm_version} + else + yum -y install python-devel llvm-devel + fi + if [ x"$RHEL" = x8 ]; + then + clang_version=$(yum list --showduplicates clang-devel | grep "17.0" | grep clang | awk '{print $2}' | head -n 1) + yum install -y clang-devel-${clang_version} clang-${clang_version} + dnf module -y disable llvm-toolset + else + yum install -y clang-devel clang + fi + PKGLIST+=" git rpmdevtools vim wget" + PKGLIST+=" perl binutils gcc gcc-c++" + PKGLIST+=" git rpm-build rpmdevtools wget gcc make autoconf" + if [[ "${RHEL}" -ge 8 ]]; then + dnf config-manager --set-enabled ol${RHEL}_codeready_builder + dnf -y module disable postgresql || true + elif [[ "${RHEL}" -eq 7 ]]; then + PKGLIST+=" llvm-toolset-7-clang llvm-toolset-7-llvm-devel llvm5.0-devel" + until yum -y install epel-release centos-release-scl; do + yum clean all + sleep 1 + echo "waiting" + done + until yum -y makecache; do + yum clean all + sleep 1 + echo "waiting" + done + fi + until yum -y install ${PKGLIST}; do + echo "waiting" + sleep 1 + done + else + apt-get -y update + DEBIAN_FRONTEND=noninteractive apt-get -y install lsb-release gnupg git wget curl + + wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb + dpkg -i percona-release_latest.generic_all.deb + rm -f percona-release_latest.generic_all.deb + percona-release enable ${PPG_REPO} testing + + + PKGLIST="percona-postgresql-${PG_RELEASE} percona-postgresql-common percona-postgresql-server-dev-all" + + # ---- using a community version of postgresql + #wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - + #echo "deb http://apt.postgresql.org/pub/repos/apt/ ${PG_RELEASE}"-pgdg main | sudo tee /etc/apt/sources.list.d/pgdg.list + #PKGLIST="postgresql-${PG_RELEASE} postgresql-common postgresql-server-dev-all" + + apt-get update + + if [[ "${OS_NAME}" != "focal" ]]; then + LLVM_EXISTS=$(grep -c "apt.llvm.org" /etc/apt/sources.list) + if [ "${LLVM_EXISTS}" == 0 ]; then + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - + echo "deb http://apt.llvm.org/${OS_NAME}/ llvm-toolchain-${OS_NAME}-7 main" >> /etc/apt/sources.list + echo "deb-src http://apt.llvm.org/${OS_NAME}/ llvm-toolchain-${OS_NAME}-7 main" >> /etc/apt/sources.list + apt-get update + fi + fi + + PKGLIST+=" debconf debhelper clang devscripts dh-exec git wget libkrb5-dev libssl-dev" + PKGLIST+=" build-essential debconf debhelper devscripts dh-exec git wget libxml-checker-perl" + PKGLIST+=" libxml-libxml-perl libio-socket-ssl-perl libperl-dev libssl-dev libxml2-dev txt2man zlib1g-dev libpq-dev" + + until DEBIAN_FRONTEND=noninteractive apt-get -y install ${PKGLIST}; do + sleep 1 + echo "waiting" + done + + fi + return; +} + +get_tar(){ + TARBALL=$1 + TARFILE=$(basename $(find $WORKDIR/$TARBALL -name 'percona-pg-telemetry*.tar.gz' | sort | tail -n1)) + if [ -z $TARFILE ] + then + TARFILE=$(basename $(find $CURDIR/$TARBALL -name 'percona-pg-telemetry*.tar.gz' | sort | tail -n1)) + if [ -z $TARFILE ] + then + echo "There is no $TARBALL for build" + exit 1 + else + cp $CURDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE + fi + else + cp $WORKDIR/$TARBALL/$TARFILE $WORKDIR/$TARFILE + fi + return +} + +get_deb_sources(){ + param=$1 + echo $param + FILE=$(basename $(find $WORKDIR/source_deb -name "percona-pg-telemetry*.$param" | sort | tail -n1)) + if [ -z $FILE ] + then + FILE=$(basename $(find $CURDIR/source_deb -name "percona-pg-telemetry*.$param" | sort | tail -n1)) + if [ -z $FILE ] + then + echo "There is no sources for build" + exit 1 + else + cp $CURDIR/source_deb/$FILE $WORKDIR/ + fi + else + cp $WORKDIR/source_deb/$FILE $WORKDIR/ + fi + return +} + +build_srpm(){ + if [ $SRPM = 0 ] + then + echo "SRC RPM will not be created" + return; + fi + if [ "x$OS" = "xdeb" ] + then + echo "It is not possible to build src rpm here" + exit 1 + fi + cd $WORKDIR + get_tar "source_tarball" + rm -fr rpmbuild + ls | grep -v tar.gz | xargs rm -rf + TARFILE=$(find . -name 'percona-pg-telemetry*.tar.gz' | sort | tail -n1) + SRC_DIR=${TARFILE%.tar.gz} + # + mkdir -vp rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS} + tar vxzf ${WORKDIR}/${TARFILE} --wildcards '*/rpm' --strip=1 + # + cp -av percona-packaging/rpm/* rpmbuild/SOURCES + cp -av percona-packaging/rpm/*.spec rpmbuild/SPECS + # + mv -fv ${TARFILE} ${WORKDIR}/rpmbuild/SOURCES + rpmbuild -bs --define "_topdir ${WORKDIR}/rpmbuild" --define "dist .generic" \ + --define "version ${VERSION}" rpmbuild/SPECS/pg-percona-telemetry.spec + mkdir -p ${WORKDIR}/srpm + mkdir -p ${CURDIR}/srpm + cp rpmbuild/SRPMS/*.src.rpm ${CURDIR}/srpm + cp rpmbuild/SRPMS/*.src.rpm ${WORKDIR}/srpm + return +} + +build_rpm(){ + if [ $RPM = 0 ] + then + echo "RPM will not be created" + return; + fi + if [ "x$OS" = "xdeb" ] + then + echo "It is not possible to build rpm here" + exit 1 + fi + SRC_RPM=$(basename $(find $WORKDIR/srpm -name 'percona-pg-telemetry*.src.rpm' | sort | tail -n1)) + if [ -z $SRC_RPM ] + then + SRC_RPM=$(basename $(find $CURDIR/srpm -name 'percona-pg-telemetry*.src.rpm' | sort | tail -n1)) + if [ -z $SRC_RPM ] + then + echo "There is no src rpm for build" + echo "You can create it using key --build_src_rpm=1" + exit 1 + else + cp $CURDIR/srpm/$SRC_RPM $WORKDIR + fi + else + cp $WORKDIR/srpm/$SRC_RPM $WORKDIR + fi + cd $WORKDIR + rm -fr rpmbuild + mkdir -vp rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS} + cp $SRC_RPM rpmbuild/SRPMS/ + + cd rpmbuild/SRPMS/ + # + cd $WORKDIR + RHEL=$(rpm --eval %rhel) + ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g') + if [ -f /opt/rh/devtoolset-7/enable ]; then + source /opt/rh/devtoolset-7/enable + source /opt/rh/llvm-toolset-7/enable + fi + export LIBPQ_DIR=/usr/pgsql-${PG_RELEASE}/ + export LIBRARY_PATH=/usr/pgsql-${PG_RELEASE}/lib/:/usr/pgsql-${PG_RELEASE}/include/ + rpmbuild --define "_topdir ${WORKDIR}/rpmbuild" --define "dist .$OS_NAME" --define "version ${VERSION}" --rebuild rpmbuild/SRPMS/$SRC_RPM + + return_code=$? + if [ $return_code != 0 ]; then + exit $return_code + fi + mkdir -p ${WORKDIR}/rpm + mkdir -p ${CURDIR}/rpm + cp rpmbuild/RPMS/*/*.rpm ${WORKDIR}/rpm + cp rpmbuild/RPMS/*/*.rpm ${CURDIR}/rpm +} + +build_source_deb(){ + if [ $SDEB = 0 ] + then + echo "source deb package will not be created" + return; + fi + if [ "x$OS" = "xrpm" ] + then + echo "It is not possible to build source deb here" + exit 1 + fi + rm -rf percona-pg-telemetry* + get_tar "source_tarball" + rm -f *.dsc *.orig.tar.gz *.debian.tar.gz *.changes + # + TARFILE=$(basename $(find . -name 'percona-pg-telemetry*.tar.gz' | sort | tail -n1)) + DEBIAN=$(lsb_release -sc) + ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g') + tar zxf ${TARFILE} + BUILDDIR=${TARFILE%.tar.gz} + # + rm -fr ${BUILDDIR}/debian + cp -av ${BUILDDIR}/percona-packaging/debian ${BUILDDIR} + mv ${TARFILE} percona-pg-telemetry_${VERSION}.orig.tar.gz + cd ${BUILDDIR} + + dch -D unstable --force-distribution -v "${VERSION}-${DEB_RELEASE}" "Update to new percona-pg-telemetry${PG_RELEASE} version ${VERSION}" + pg_buildext updatecontrol + dpkg-buildpackage -S + cd ../ + mkdir -p $WORKDIR/source_deb + mkdir -p $CURDIR/source_deb + cp *.debian.tar.* $WORKDIR/source_deb + cp *_source.changes $WORKDIR/source_deb + cp *.dsc $WORKDIR/source_deb + cp *.orig.tar.gz $WORKDIR/source_deb + cp *.debian.tar.* $CURDIR/source_deb + cp *_source.changes $CURDIR/source_deb + cp *.dsc $CURDIR/source_deb + cp *.orig.tar.gz $CURDIR/source_deb +} + +change_ddeb_package_to_deb(){ + + directory=$1 + + for file in "$directory"/*.ddeb; do + if [ -e "$file" ]; then + # Change extension to .deb + mv "$file" "${file%.ddeb}.deb" + echo "Changed extension of $file to ${file%.ddeb}.deb" + fi + done +} + +build_deb(){ + if [ $DEB = 0 ] + then + echo "source deb package will not be created" + return; + fi + if [ "x$OS" = "xrmp" ] + then + echo "It is not possible to build source deb here" + exit 1 + fi + for file in 'dsc' 'orig.tar.gz' 'changes' 'debian.tar*' + do + get_deb_sources $file + done + cd $WORKDIR + rm -fv *.deb + # + export ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g') + # + echo "DEBIAN=${OS_NAME}" >> pg-percona-telemetry.properties + echo "ARCH=${ARCH}" >> pg-percona-telemetry.properties + # + DSC=$(basename $(find . -name '*.dsc' | sort | tail -n1)) + # + dpkg-source -x ${DSC} + # + cd percona-pg-telemetry-${VERSION} + sed -i "s:\. :${WORKDIR}/percona-pg-telemetry-${VERSION} :g" percona-packaging/debian/rules + dch -m -D "${OS_NAME}" --force-distribution -v "1:${VERSION}-${DEB_RELEASE}.${OS_NAME}" 'Update distribution' + unset $(locale|cut -d= -f1) + pg_buildext updatecontrol + dpkg-buildpackage -rfakeroot -us -uc -b + mkdir -p $CURDIR/deb + mkdir -p $WORKDIR/deb + cp $WORKDIR/*.*deb $WORKDIR/deb + cp $WORKDIR/*.*deb $CURDIR/deb + change_ddeb_package_to_deb "$CURDIR/deb" +} + +CURDIR=$(pwd) +VERSION_FILE=$CURDIR/pg-percona-telemetry.properties +args= +WORKDIR= +SRPM=0 +SDEB=0 +RPM=0 +DEB=0 +SOURCE=0 +TARBALL=0 +OS_NAME= +ARCH= +OS= +REVISION=0 +BRANCH="main" +INSTALL=0 +RPM_RELEASE=1 +DEB_RELEASE=1 +GIT_REPO="https://github.com/Percona-Lab/percona_pg_telemetry.git" +VERSION="1.0.0" +PG_RELEASE=16 +PPG_REPO=ppg-16.2 +parse_arguments PICK-ARGS-FROM-ARGV "$@" + +check_workdir +get_system +install_deps +get_sources +build_srpm +build_source_deb +build_rpm +build_deb