From adcb7e744944dbfc2cd196d0802ad3ba6072b1a8 Mon Sep 17 00:00:00 2001 From: "tlimoncelli@stackexchange.com" Date: Tue, 26 Aug 2014 16:26:25 -0400 Subject: [PATCH] Package tools --- Makefile | 14 +++++++++ SPECS/empty.spec | 0 tools/build_rpm.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Makefile create mode 100644 SPECS/empty.spec create mode 100755 tools/build_rpm.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..163d4ec --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +SHELL=/bin/sh +BIN=tools + +all: + @echo 'Menu:' + @echo ' make packages Make all RPM packages' + @echo ' make install (incomplete) + +packages: + @$(BIN)/make_rpm.sh PKGRELEASE="$${PKGRELEASE}" + +install: + @echo 'To install, copy the files from bin to somewhere in your PATH.' + @echo 'Or, if you use RPMs, "make packages" and install the result.' diff --git a/SPECS/empty.spec b/SPECS/empty.spec new file mode 100644 index 0000000..e69de29 diff --git a/tools/build_rpm.sh b/tools/build_rpm.sh new file mode 100755 index 0000000..64f2447 --- /dev/null +++ b/tools/build_rpm.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# build_rpm.sh - Build an RPM of these files. (uses FPM) + +# Usage: +# make_rpm.sh PACKAGENAME MANIFEST1 MANIFEST2 ... + +# Example: +# Make a package foopkg manifest.txt +# Where "manifest.txt" contains: +# exec /usr/bin/foo foo/foo +# exec /usr/bin/bar bar/bar.sh +# read /usr/man/man1/bar.1 bar/bar.1.man +# 0444 /etc/foo.conf bar/foo.conf +# +# Col1 chmod-style permissions or "exec" for 0755, "read" for 0744. +# Col2 Installation location. +# Col3 Source of the file. + +set -e + +# Parameters for this RPM: +PACKAGENAME=${1?"First arg must be the package name."} +shift + +# Defaults that can be overridden via env variables: +# All packages are 1.0 unless otherwise specifed: +: ${PKGVERSION:=1.0} ; +# If there is no iteration setting, assume "1": +: ${PKGRELEASE:=1} + +# The RPM is output here: (should be a place that can be wiped) +OUTPUTDIR="${HOME}/rpmbuild-$PACKAGENAME" +# Our build system expects to find the list of artifacts here: +RPM_BIN_LIST="${OUTPUTDIR}/bin-packages.txt" + +# -- Now the real work can be done. + +# Clean the output dir. +rm -rf "$OUTPUTDIR" +mkdir -p "$OUTPUTDIR/installroot" + +# Copy the files into place: +cat """$@""" | while read -a arr ; do + PERM="${arr[0]}" + case $PERM in + \#*) continue ;; # Skip comments. + exec) PERM=0755 ;; + read) PERM=0744 ;; + *) ;; + esac + DST="$OUTPUTDIR/installroot/${arr[1]}" + SRC="${arr[2]}" + install -D -T -b -m "$PERM" -T "$SRC" "$DST" +done + +# Build the RPM: +cd "$OUTPUTDIR" && fpm -s dir -t rpm \ + -a x86_64 \ + --epoch '0' \ + -n "${PACKAGENAME}" \ + --version "${PKGVERSION}" \ + --iteration "${PKGRELEASE}" \ + -C "$OUTPUTDIR/installroot" \ + . + +# Our build system expects to find the list of all packages created +# in bin-packages.txt. Generate that list: +find "$OUTPUTDIR" -maxdepth 1 -name '*.rpm' >"$RPM_BIN_LIST" +# Output the list for debugging purposes: +echo ========== "$RPM_BIN_LIST" +cat "$RPM_BIN_LIST"