github.com/StackExchange/blackbox/v2@v2.0.1-0.20220331193400-d84e904973ab/tools/mk_deb_fpmdir (about) 1 #! /usr/bin/env bash 2 3 # Use fpm to package up files into a DEB . 4 5 # Usage: 6 # mk_deb_fpmdir PACKAGENAME MANIFEST1 MANIFEST2 ... 7 8 # Example: 9 # Make a package foopkg manifest.txt 10 # Where "manifest.txt" contains: 11 # exec /usr/bin/stack_makefqdn misc/stack_makefqdn.py 12 # exec /usr/bin/bar bar/bar.sh 13 # read /usr/man/man1/bar.1 bar/bar.1.man 14 # 0444 /etc/foo.conf bar/foo.conf 15 16 set -e 17 18 # Parameters for this DEB: 19 PACKAGENAME=${1?"First arg must be the package name."} 20 shift 21 22 # Defaults that can be overridden: 23 # All packages are 1.0 unless otherwise specifed: 24 : ${PKGVERSION:=1.0} ; 25 # If there is no iteration set, default to use the number of commits in the repository: 26 if [[ -z "${PKGRELEASE}" ]]; then 27 PKGRELEASE=$(git rev-list HEAD --count) 28 if [[ $? != 0 ]]; then 29 # We're not in a git repo, fall back to 1 so we cope with being built from 30 # a tarball 31 PKGRELEASE=1 32 fi 33 fi 34 35 # If there is no epoch, assume 0 36 : ${PKGEPOCH:=0} 37 38 # Allow us to set a different OUTPUTDIR if we're building in CI/CD 39 if [[ -z "${OUTPUTDIR}" ]]; then 40 # The DEB is output here: (should be a place that can be wiped) 41 OUTPUTDIR="${HOME}/debbuild-${PACKAGENAME}" 42 else 43 echo "Using $OUTPUTDIR for OUTPUTDIR instead of ${HOME}/debbuild-${PACKAGENAME}" 44 fi 45 46 # The TeamCity templates expect to find the list of artifacts here: 47 DEB_BIN_LIST="${OUTPUTDIR}/bin-packages.txt" 48 49 # -- Now the real work can be done. 50 51 # Clean the output dir. 52 rm -rf "$OUTPUTDIR" 53 54 mkdir -p "$OUTPUTDIR/installroot" 55 56 # Copy the files into place: 57 set -o pipefail # Error out if any manifest is not found. 58 cat """$@""" | while read -a arr ; do 59 PERM="${arr[0]}" 60 case $PERM in 61 \#*) continue ;; # Skip comments. 62 exec) PERM=0755 ;; 63 read) PERM=0744 ;; 64 *) ;; 65 esac 66 DST="$OUTPUTDIR/installroot/${arr[1]}" 67 SRC="${arr[2]}" 68 if [[ $SRC == "cmd/"* || $SRC == *"/cmd/"* ]]; then 69 ( cd $(dirname "$SRC" ) && go build -a -v ) 70 fi 71 install -D -T -b -m "$PERM" -T "$SRC" "$DST" 72 done 73 74 # Build the DEB: 75 cd "$OUTPUTDIR" && fpm -s dir -t deb \ 76 -a all \ 77 -n "${PACKAGENAME}" \ 78 --epoch "${PKGEPOCH}" \ 79 --version "${PKGVERSION}" \ 80 --iteration "${PKGRELEASE}" \ 81 ${PKGDESCRIPTION:+ --description="${PKGDESCRIPTION}"} \ 82 ${PKGVENDOR:+ --vendor="${PKGVENDOR}"} \ 83 -C "$OUTPUTDIR/installroot" \ 84 . 85 86 # TeamCity templates for DEBS expect to find 87 # the list of all packages created in bin-packages.txt. 88 # Generate that list: 89 find "$OUTPUTDIR" -maxdepth 1 -name '*.deb' >"$DEB_BIN_LIST" 90 # Output it for debugging purposes: 91 cat "$DEB_BIN_LIST"