|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# build-deb.sh |
| 4 | +# Use shell script to build .deb packages. |
| 5 | +# |
| 6 | +# Copyright (c) 2024, Alibaba Group Holding Limited |
| 7 | +# |
| 8 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +# you may not use this file except in compliance with the License. |
| 10 | +# You may obtain a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# See the License for the specific language governing permissions and |
| 18 | +# limitations under the License. |
| 19 | +# |
| 20 | +# IDENTIFICATION |
| 21 | +# package/debian/build-deb.sh |
| 22 | + |
| 23 | +build_date=${1:-$(date +"%Y%m%d%H%M%S")} |
| 24 | +code_commit=$(git rev-parse HEAD || echo unknown) |
| 25 | +code_branch=$(git rev-parse --abbrev-ref HEAD || echo unknown) |
| 26 | +polar_commit=$(git rev-parse --short=8 HEAD || echo unknown) |
| 27 | +pg_version=$(grep AC_INIT ../../configure.ac | awk -F'[][]' '{print $4}') |
| 28 | +polar_majorversion=$(echo ${pg_version}) |
| 29 | +polar_minorversion=$(grep '^POLAR_MINORVERSION' ../../configure.ac | cut -d '"' -f2) |
| 30 | +polar_release_date=$(grep '^POLAR_RELEASE_DATE' ../../configure.ac | cut -d '"' -f2) |
| 31 | +polar_version=${polar_majorversion}.${polar_minorversion} |
| 32 | +polar_pg_version=${pg_version}.${polar_minorversion} |
| 33 | + |
| 34 | +package=PolarDB |
| 35 | +debpkgname=$(grep 'Package:' ./control | awk '{print $2}') |
| 36 | +distname=$(grep '^ID=' /etc/os-release | awk -F'=' '{print $2}') |
| 37 | +distversion=$(grep 'VERSION_ID=' /etc/os-release | awk -F\" '{print $2}') |
| 38 | +arch=$(dpkg --print-architecture) |
| 39 | + |
| 40 | +pkgname=${package}_${polar_version}-${polar_commit}-${distname}${distversion}_${arch} |
| 41 | +rm -rf ./${pkgname} |
| 42 | +mkdir -p ${pkgname}/DEBIAN |
| 43 | + |
| 44 | +cat ./control >> ${pkgname}/DEBIAN/control |
| 45 | +echo 'Version: '${polar_version}'-'${polar_commit}'' >> ${pkgname}/DEBIAN/control |
| 46 | +echo 'Architecture: '${arch}'' >> ${pkgname}/DEBIAN/control |
| 47 | + |
| 48 | +prefix=/u01/polardb_pg |
| 49 | +buildroot=$(pwd) |
| 50 | +cd ../../ |
| 51 | +export COPT="-Wno-error ${COPT-}" |
| 52 | +./build.sh --ec="--prefix=${buildroot}/${pkgname}${prefix} --with-pfsd" --debug=off --ni |
| 53 | +cd ${buildroot} |
| 54 | + |
| 55 | +polar_install_dependency() |
| 56 | +{ |
| 57 | + target_dir=${1} |
| 58 | + |
| 59 | + # create link for lib inside lib |
| 60 | + cd ${target_dir}/lib/ |
| 61 | + ln -sf ../lib ./lib |
| 62 | + |
| 63 | + cd ${target_dir} |
| 64 | + |
| 65 | + # generate list of .so files |
| 66 | + # collect all the executable binaries, scripts and shared libraries |
| 67 | + binfiles=`find ${target_dir}/bin` |
| 68 | + libfiles=`find ${target_dir}/lib` |
| 69 | + filelist=${binfiles}$'\n'${libfiles} |
| 70 | + exelist=`echo $filelist | xargs -r file | egrep -v ":.* (commands|script)" | \ |
| 71 | + grep ":.*executable" | cut -d: -f1` |
| 72 | + scriptlist=`echo $filelist | xargs -r file | \ |
| 73 | + egrep ":.* (commands|script)" | cut -d: -f1` |
| 74 | + liblist=`echo $filelist | xargs -r file | \ |
| 75 | + grep ":.*shared object" | cut -d : -f1` |
| 76 | + |
| 77 | + # dependency list of the executable binaries and shared libraries |
| 78 | + cp /dev/null mytmpfilelist |
| 79 | + cp /dev/null mytmpfilelist2 |
| 80 | + |
| 81 | + # put PolarDB-PG libs before any other libs to let ldd take it first |
| 82 | + export LD_LIBRARY_PATH=${target_dir}/lib:$LD_LIBRARY_PATH:/usr/lib |
| 83 | + |
| 84 | + # dependency list of all binaries and shared objects |
| 85 | + for f in $liblist $exelist; do |
| 86 | + ldd $f | awk '/=>/ { |
| 87 | + if (X$3 != "X" && $3 !~ /libNoVersion.so/ && $3 !~ /4[um]lib.so/ && $3 !~ /libredhat-kernel.so/ && $3 !~ /libselinux.so/ && $3 !~ /\/u01\/polardb_pg/ && $3 !~ /libjvm.so/ && $3 ~ /\.so/) { |
| 88 | + # printf "$s => $s\n", $1, $3 |
| 89 | + print $3 |
| 90 | + } |
| 91 | + }' >> mytmpfilelist |
| 92 | + done |
| 93 | + |
| 94 | + # deduplicate |
| 95 | + cat mytmpfilelist | sort -u > mytmpfilelist2 |
| 96 | + |
| 97 | + for f in `cat mytmpfilelist2`; do |
| 98 | + ldd $f | awk '/=>/ { |
| 99 | + if (X$3 != "X" && $3 !~ /libNoVersion.so/ && $3 !~ /4[um]lib.so/ && $3 !~ /libredhat-kernel.so/ && $3 !~ /libselinux.so/ && $3 !~ /\/u01\/polardb_pg/ && $3 !~ /libjvm.so/ && $3 ~ /\.so/) { |
| 100 | + # printf "$s => $s\n", $1, $3 |
| 101 | + print $3 |
| 102 | + } |
| 103 | + }' >> mytmpfilelist |
| 104 | + done |
| 105 | + |
| 106 | + # deduplicate |
| 107 | + cat mytmpfilelist | sort -u > mytmpfilelist2 |
| 108 | + |
| 109 | + # copy libraries if necessary |
| 110 | + for line in `cat mytmpfilelist2`; do |
| 111 | + base=`basename $line` |
| 112 | + dirpath=${target_dir}/lib |
| 113 | + filepath=$dirpath/$base |
| 114 | + |
| 115 | + objdump -p $line | awk 'BEGIN { START=0; LIBNAME=""; } |
| 116 | + /^$/ { START=0; } |
| 117 | + /^Dynamic Section:$/ { START=1; } |
| 118 | + (START==1) && /NEEDED/ { |
| 119 | + print $2 ; |
| 120 | + } |
| 121 | + (START==2) && /^[A-Za-z]/ { START=3; } |
| 122 | + /^Version References:$/ { START=2; } |
| 123 | + (START==2) && /required from/ { |
| 124 | + sub(/:/, "", $3); |
| 125 | + LIBNAME=$3; |
| 126 | + } |
| 127 | + (START==2) && (LIBNAME!="") && ($4!="") && (($4~/^GLIBC_*/) || ($4~/^GCC_*/)) { |
| 128 | + print LIBNAME "(" $4 ")"; |
| 129 | + } |
| 130 | + END { exit 0 } |
| 131 | + ' > objdumpfile |
| 132 | + |
| 133 | + has_private= |
| 134 | + if grep -q PRIVATE objdumpfile; then |
| 135 | + has_private=true |
| 136 | + fi |
| 137 | + |
| 138 | + if [[ ! -f $filepath ]]; then |
| 139 | + if [[ $has_private != "true" ]]; then |
| 140 | + cp $line $dirpath |
| 141 | + echo $line $dirpath |
| 142 | + fi |
| 143 | + fi |
| 144 | + done |
| 145 | + |
| 146 | + rm mytmpfilelist mytmpfilelist2 objdumpfile |
| 147 | +} |
| 148 | + |
| 149 | +# install package dependencies |
| 150 | +polar_install_dependency $(pwd)/${pkgname}${prefix} |
| 151 | +cd ${buildroot} |
| 152 | + |
| 153 | +dpkg --build ./${pkgname} |
0 commit comments