Update automatic package generator

- add DEB package creation functionality
- update RPM spec file to work with SLES

Signed-off-by: Rafal Stefanowski <rafal.stefanowski@intel.com>
This commit is contained in:
Rafal Stefanowski 2020-09-14 14:17:28 +02:00
parent bc5c92d3ed
commit ef70bce154
13 changed files with 291 additions and 42 deletions

View File

@ -17,10 +17,14 @@ $(DIRS):
ifneq ($(MAKECMDGOALS),archives)
ifneq ($(MAKECMDGOALS),rpm)
ifneq ($(MAKECMDGOALS),srpm)
ifneq ($(MAKECMDGOALS),deb)
ifneq ($(MAKECMDGOALS),dsc)
cd $@ && $(MAKE) $(MAKECMDGOALS)
endif
endif
endif
endif
endif
archives:
@utils/pckgen $(PWD) tar zip
@ -30,3 +34,9 @@ rpm:
srpm:
@utils/pckgen $(PWD) srpm --debug
deb:
@utils/pckgen $(PWD) deb
dsc:
@utils/pckgen $(PWD) dsc

View File

@ -13,19 +13,27 @@
CAS_NAME="open-cas-linux"
CAS_HOMEPAGE="https://open-cas.github.io"
CAS_GIT="https://github.com/Open-CAS/open-cas-linux.git"
CAS_LICENSE_NAME="BSD-3-Clause-Clear"
SUPPORTED_FROM_VERSION="20.03"
THIS=$(basename "$0")
ARCH="$(uname -i)"
SYS_INFO="/etc/os-release"
SCRIPT_BASE_DIR=$(dirname $(realpath "$0"))
BASE_SPEC="$SCRIPT_BASE_DIR/$CAS_NAME.spec.base"
RPM_SPEC_FILE="$SCRIPT_BASE_DIR/$THIS.d/rpm/CAS_NAME.spec"
DEB_CONTROL_FILES_DIR="$SCRIPT_BASE_DIR/$THIS.d/deb/debian"
PACKAGE_MAINTAINER="Rafal Stefanowski <rafal.stefanowski@intel.com>"
PACKAGE_DATE="$(date -R)"
TEMP_TEMPLATE="opencas-${THIS}"
DEPENDENCIES=(sed git mktemp rsync)
DEPENDENCIES=(git mktemp rsync sed)
# Dependencies for particular packages creation:
DEPENDENCIES_TAR=(tar)
DEPENDENCIES_ZIP=(zip)
DEPENDENCIES_RPM=(tar rpmbuild)
DEPENDENCIES_RPM=(rpmbuild tar)
DEPENDENCIES_SRPM=("${DEPENDENCIES_RPM[@]}")
DEPENDENCIES_DEB=(debuild dh fakeroot tar)
DEPENDENCIES_DSC=("${DEPENDENCIES_DEB[@]}")
# List of relative submodule directories:
SUBMODULES=(
"ocf"
@ -57,7 +65,9 @@ print_help() {
echo " tar generate tar archive"
echo " zip generate zip archive"
echo " rpm generate RPM packages"
echo " srpm generate SRPM package"
echo " srpm generate SRPM (source RPM) package"
echo " deb generate DEB packages"
echo " dsc generate DSC (source DEB) package"
echo
echo "Options:"
echo " -o, --output-dir <DIR> put all created files in the given directory;"
@ -171,16 +181,34 @@ create_temp() {
fi
}
rename_templates() {
# Due to inconsistent ordering in 'find' output, it is necessary to
# rerun files renaming in order to include files and subdirectories
# when both need to be renamed. To prevent infinite loops, rerun is not
# based on 'mv' command exit status, but on specified subdirectory depth.
# This mechanism seems to be much simpler then piping the output through
# various external utilities.
SUBDIR_DEPTH=3
while [ $((SUBDIR_DEPTH--)) -gt 0 ]; do
for filename in $(find "$@"); do
if [[ "$filename" =~ CAS_NAME ]]; then
mv "$filename" "${filename//CAS_NAME/${CAS_NAME}}" 2>/dev/null
fi
done
done
}
archive_prepare() {
if [ "$ARCHIVE_PREPARED" ]; then
return 0
fi
echo "--- Copying sources to the working directory"
echo "--- Copying sources to the working directory and cleaning"
local TEMP_SOURCES_DIR="$TEMP_DIR/$CAS_FILENAME"
rm -rf "$TEMP_SOURCES_DIR"
mkdir -p "$TEMP_SOURCES_DIR"
rsync -a --exclude={/packages,.git*,.pep8speaks.yml} "$SOURCES_DIR/" "$TEMP_SOURCES_DIR"
make -C "$TEMP_SOURCES_DIR" clean distclean >/dev/null
ARCHIVE_PREPARED="archive_prepared"
}
@ -231,14 +259,42 @@ rpm_obtain_sources() {
fi
}
rpm_spec_prepare() {
echo "--- Preparing SPEC file"
if [ ! -f "$BASE_SPEC" ]; then
error "SPEC file '$BASE_SPEC' not found"
deb_obtain_sources() {
echo "--- Obtaining CAS sources for DEBs"
generate_tar temp
mkdir -p "$DEB_BUILD_DIR"
cp -v "$TEMP_DIR/$SOURCES_TAR_NAME" "$DEB_BUILD_DIR/$DEB_TAR_NAME"
if [ ! -f "$DEB_BUILD_DIR/$DEB_TAR_NAME" ]; then
error "couldn't obtain $DEB_TAR_NAME sources tarball!"
fi
cp -v "$BASE_SPEC" "$RPM_SPECS_DIR/$CAS_NAME.spec"
tar -C "$DEB_BUILD_DIR" -zxf "$DEB_BUILD_DIR/$DEB_TAR_NAME"
if [ $? -ne 0 ] || [ ! -d "$DEB_SOURCES_DIR" ]; then
error "couldn't unpack tar archive '$DEB_BUILD_DIR/$DEB_TAR_NAME'"\
"or it contains wrong sources dir name"\
"(should be '$(basename $DEB_SOURCES_DIR)')"
fi
}
rpm_spec_prepare() {
echo "--- Preparing SPEC file"
if [ ! -f "$RPM_SPEC_FILE" ]; then
error "SPEC file '$RPM_SPEC_FILE' not found"
fi
cp "$RPM_SPEC_FILE" "$RPM_SPECS_DIR"
if ! ls -A "$RPM_SPECS_DIR/"* &>/dev/null; then
error "couldn't copy SPEC file to working directory '$RPM_SPECS_DIR'"
fi
rename_templates "$RPM_SPECS_DIR"
sed -i "s/<CAS_NAME>/$CAS_NAME/g" "$RPM_SPECS_DIR/$CAS_NAME.spec"
sed -i "s/<CAS_VERSION>/$CAS_VERSION/g" "$RPM_SPECS_DIR/$CAS_NAME.spec"
sed -i "s/<CAS_LICENSE_NAME>/$CAS_LICENSE_NAME/g" "$RPM_SPECS_DIR/$CAS_NAME.spec"
sed -i "s/<CAS_HOMEPAGE>/${CAS_HOMEPAGE//\//\\/}/g" "$RPM_SPECS_DIR/$CAS_NAME.spec"
sed -i "s/<PACKAGE_MAINTAINER>/$PACKAGE_MAINTAINER/g" "$RPM_SPECS_DIR/$CAS_NAME.spec"
if [ "$DEBUG" ]; then
echo "--- Debug RPMs will be built as well"
sed -i "s/%define debug_package %{nil}//g" "$RPM_SPECS_DIR/$CAS_NAME.spec"
@ -249,6 +305,41 @@ rpm_spec_prepare() {
fi
}
deb_control_files_prepare() {
echo "--- Preparing DEB control files"
if ! ls -A "$DEB_CONTROL_FILES_DIR/"* &>/dev/null; then
error "DEB control files directory '$DEB_CONTROL_FILES_DIR' not found or empty"
fi
cp -r "$DEB_CONTROL_FILES_DIR" "$DEB_SOURCES_DIR"
if ! ls -A "$DEB_SOURCES_DIR/debian/"* &>/dev/null; then
error "couldn't copy DEB control files to working directory '$DEB_SOURCES_DIR'"
fi
rename_templates "$DEB_SOURCES_DIR/debian/"
# Parsing the CAS license file to fit Debian copyright file format
sed '${/^$/d}' "$CAS_LICENSE" > "$TEMP_DIR/LICENSE.deb.tmp"
sed -i 's/^$/./' "$TEMP_DIR/LICENSE.deb.tmp"
rm -f "$TEMP_DIR/LICENSE.deb"
while read -r line; do
echo " $line" >> "$TEMP_DIR/LICENSE.deb"
done < "$TEMP_DIR/LICENSE.deb.tmp"
rm -f "$TEMP_DIR/LICENSE.deb.tmp"
cat "$TEMP_DIR/LICENSE.deb" >> "$DEB_SOURCES_DIR/debian/copyright"
# Replacing tags
for file in $(find "$DEB_SOURCES_DIR/debian/" -type f); do
sed -i "s/<CAS_NAME>/$CAS_NAME/g" "$file"
sed -i "s/<CAS_VERSION>/$CAS_VERSION/g" "$file"
sed -i "s/<CAS_LICENSE_NAME>/$CAS_LICENSE_NAME/g" "$file"
sed -i "s/<CAS_HOMEPAGE>/${CAS_HOMEPAGE//\//\\/}/g" "$file"
sed -i "s/<CAS_GIT>/${CAS_GIT//\//\\/}/g" "$file"
sed -i "s/<PACKAGE_MAINTAINER>/$PACKAGE_MAINTAINER/g" "$file"
sed -i "s/<PACKAGE_DATE>/$PACKAGE_DATE/g" "$file"
done
}
generate_rpm() {
if [ "$RPM_BUILT" ]; then
return 0
@ -273,7 +364,7 @@ generate_rpm() {
if [ $? -ne 0 ]; then
error "couldn't create RPM packages"
fi
mv -t "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
mv -ft "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
fi
if [ "$GENERATE_SRPM" ] && [ ! "$GENERATE_RPM" ]; then
echo "--- Building source SRPM package"
@ -281,7 +372,7 @@ generate_rpm() {
if [ $? -ne 0 ]; then
error "couldn't create SRPM package"
fi
mv -t "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
fi
if [ "$GENERATE_SRPM" ] && [ "$GENERATE_RPM" ]; then
echo "--- Building source and binary RPM packages"
@ -289,8 +380,8 @@ generate_rpm() {
if [ $? -ne 0 ]; then
error "couldn't create RPM packages"
fi
mv -t "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
mv -t "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
mv -ft "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
fi
RPM_BUILT="rpm_built"
@ -300,6 +391,51 @@ generate_srpm() {
generate_rpm
}
generate_deb() {
if [ "$DEB_BUILT" ]; then
return 0
fi
deb_obtain_sources
deb_control_files_prepare
if [ ! "$GENERATE_DSC" ] && [ "$GENERATE_DEB" ]; then
echo "--- Building binary DEB packages"
(cd "$DEB_SOURCES_DIR" && debuild -us -uc -b)
if [ $? -ne 0 ]; then
error "couldn't create DEB packages"
fi
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*deb
fi
if [ "$GENERATE_DSC" ] && [ ! "$GENERATE_DEB" ]; then
echo "--- Building DSC (source DEB) package"
(cd "$DEB_SOURCES_DIR" && debuild -us -uc -S -d)
if [ $? -ne 0 ]; then
error "couldn't create DSC package"
fi
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*.dsc
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*.orig.tar.gz
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*.debian.tar.xz
fi
if [ "$GENERATE_DSC" ] && [ "$GENERATE_DEB" ]; then
echo "--- Building DEB and DSC (source DEB) packages"
(cd "$DEB_SOURCES_DIR" && debuild -us -uc -F)
if [ $? -ne 0 ]; then
error "couldn't create DEB and DSC packages"
fi
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*deb
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*.dsc
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*.orig.tar.gz
mv -ft "$OUTPUT_DIR" "$DEB_BUILD_DIR/$CAS_NAME"*.debian.tar.xz
fi
DEB_BUILT="deb_built"
}
generate_dsc() {
generate_deb
}
if (( ! $# )); then
invalid_usage "no arguments given\n$(usage)\n"
@ -319,6 +455,12 @@ while (( $# )); do
srpm)
GENERATE_SRPM="generate_srpm"
;;
deb)
GENERATE_DEB="generate_deb"
;;
dsc)
GENERATE_DSC="generate_dsc"
;;
--output-dir|-o)
OUTPUT_DIR="$2"
if ! dirname $OUTPUT_DIR &>/dev/null; then
@ -350,12 +492,17 @@ done
check_options
# Following line removes all temporary (build process) files and dirs
# even if this script ends with an error. For debuging purposes, when
# build-time files are needed for inspection, simply comment it out.
trap clean EXIT
create_temp
### Variables that relates on arguments passed to this script:
CAS_LICENSE="$SOURCES_DIR/LICENSE"
# By default all created packages will be put in:
: ${OUTPUT_DIR:="$SOURCES_DIR/packages"}
# RPM building directories:
@ -364,6 +511,7 @@ RPM_SOURCES_DIR="$RPM_BUILD_DIR/SOURCES"
RPM_SPECS_DIR="$RPM_BUILD_DIR/SPECS"
RPM_RPMS_DIR="$RPM_BUILD_DIR/RPMS"
RPM_SRPMS_DIR="$RPM_BUILD_DIR/SRPMS"
DEB_BUILD_DIR="$TEMP_DIR/debuild"
# Version file location:
VERSION_FILE="$SOURCES_DIR/.metadata/cas_version"
# CAS version generator location:
@ -376,6 +524,10 @@ CAS_FILENAME="$CAS_NAME-$CAS_VERSION"
# CAS sources archives filenames:
SOURCES_TAR_NAME="$CAS_FILENAME.tar.gz"
SOURCES_ZIP_NAME="$CAS_FILENAME.zip"
DEB_TAR_NAME="${CAS_NAME}_${CAS_VERSION}.orig.tar.gz"
# DEB sources dir needs to be obtained after version checking
# because its name contains version number
DEB_SOURCES_DIR="$DEB_BUILD_DIR/$CAS_NAME-$CAS_VERSION"

View File

@ -0,0 +1 @@
lib/modules/

View File

@ -0,0 +1 @@
README.md

View File

@ -0,0 +1,8 @@
etc/
lib/opencas/
lib/udev/
sbin/
var/
utils/open-cas.shutdown lib/systemd/system-shutdown/
utils/open-cas.service lib/systemd/system/
utils/open-cas-shutdown.service lib/systemd/system/

View File

@ -0,0 +1,3 @@
utils/opencas.conf.5
utils/casadm.8
utils/casctl.8

View File

@ -0,0 +1,11 @@
<CAS_NAME> (<CAS_VERSION>-1) trusty; urgency=medium
* pckgen: automated package generation
-- <PACKAGE_MAINTAINER> <PACKAGE_DATE>
open-cas-linux (20.03.2.0295-1) trusty; urgency=medium
* Initial OpenCAS DEB package release
-- Rafal Stefanowski <rafal.stefanowski@intel.com> Mon, 07 Sep 2020 14:17:04 +0200

View File

@ -0,0 +1 @@
12

View File

@ -0,0 +1,30 @@
Source: <CAS_NAME>
Section: utils
Priority: optional
Maintainer: <PACKAGE_MAINTAINER>
Build-Depends: debhelper (>= 11), gawk, libelf-dev, linux-headers-generic
Standards-Version: 4.1.2
Homepage: <CAS_HOMEPAGE>
Vcs-Git: <CAS_GIT>
Package: <CAS_NAME>
Architecture: amd64
Depends: ${shlibs:Depends}, ${misc:Depends}, python3,
<CAS_NAME>-modules (= <CAS_VERSION>-1)
Description: Open Cache Acceleration Software
Open Cache Acceleration Software (Open CAS) is an open source project
encompassing block caching software libraries, adapters, tools and more.
The main goal of this cache acceleration software is to accelerate a
backend block device(s) by utilizing a higher performance device(s).
This package contains tools and utilities for managing CAS and monitor
running cache instances (no kernel modules).
Package: <CAS_NAME>-modules
Architecture: amd64
Depends: ${misc:Depends}
Description: Open Cache Acceleration Software kernel modules (${kver})
Open Cache Acceleration Software (Open CAS) is an open source project
encompassing block caching software libraries, adapters, tools and more.
The main goal of this cache acceleration software is to accelerate a
backend block device(s) by utilizing a higher performance device(s).
This package contains only CAS kernel modules.

View File

@ -0,0 +1,7 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Intel Corporation
Source: <CAS_GIT>
Files: *
Copyright: 2019-2020 Intel Corporation
License: <CAS_LICENSE_NAME>

21
utils/pckgen.d/deb/debian/rules Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/make -f
# output every command that modifies files on the build system
#export DH_VERBOSE = 1
%:
dh $@
override_dh_auto_configure :
./configure
override_dh_auto_install :
make install_files DESTDIR="$(shell pwd)/debian/tmp"
override_dh_installsystemd :
dh_installsystemd --no-start
override_dh_missing :
override_dh_gencontrol :
dh_gencontrol -- -Vkver="$(shell uname -r)"

View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -4,7 +4,7 @@
#
#
# This is a base SPEC file for generating OpenCAS RPMs automatically.
# This is a template SPEC file for generating OpenCAS RPMs automatically.
# It contains tags in form of <TAG> which are substituted with particular
# values in the build time.
#
@ -15,24 +15,18 @@
%define kver_filename k%{expand:%(kname="%{kver}"; echo "${kname%.*}" | sed -r "y/-/_/;")}
Name: open-cas-linux
Name: <CAS_NAME>
Version: <CAS_VERSION>
Release: 1%{?dist}
Summary: Open Cache Acceleration Software
Group: System
License: BSD-3-Clause
URL: https://open-cas.github.io/
Vendor: Intel Corporation
License: <CAS_LICENSE_NAME>
URL: <CAS_HOMEPAGE>
Source0: https://github.com/Open-CAS/open-cas-linux/releases/download/v%{version}/%{name}-%{version}.tar.gz
BuildRequires: gcc
BuildRequires: kernel-devel
BuildRequires: kernel-headers
BuildRequires: make
BuildRequires: elfutils-libelf-devel
BuildRequires: coreutils
BuildRequires: gawk
Requires: python3
Requires: sed
Requires: open-cas-linux-modules-%{version}
Packager: <PACKAGE_MAINTAINER>
BuildRequires: coreutils, gawk, gcc, kernel-devel, kernel-headers, make
Requires: <CAS_NAME>-modules-%{version}, python3, sed
%description
Open Cache Acceleration Software (Open CAS) is an open source project
encompassing block caching software libraries, adapters, tools and more.
@ -46,13 +40,13 @@ running cache instances.
Summary: Open Cache Acceleration Software kernel modules
Group: System
Requires: kmod
Provides: open-cas-linux-modules-%{version}
Provides: <CAS_NAME>-modules-%{version}
%description modules_%{kver_filename}
Open Cache Acceleration Software (Open CAS) is an open source project
encompassing block caching software libraries, adapters, tools and more.
The main goal of this cache acceleration software is to accelerate a
backend block device(s) by utilizing a higher performance device(s).
This package contains CAS kernel modules.
This package contains only CAS kernel modules.
%prep
@ -88,13 +82,19 @@ fi
%post modules_%{kver_filename}
depmod
. /etc/os-release
if [[ ! "$ID_LIKE" =~ suse|sles ]]; then
modules=( $(realpath $(modinfo -F filename cas_cache cas_disk)) )
printf "%s\n" "${modules[@]}" | weak-modules --no-initramfs --add-modules
fi
%postun modules_%{kver_filename}
if [ $1 -eq 0 ]; then
. /etc/os-release
if [[ ! "$ID_LIKE" =~ suse|sles ]]; then
modules=( $(realpath $(modinfo -F filename cas_cache cas_disk 2>/dev/null)) )
printf "%s\n" "${modules[@]}" | weak-modules --no-initramfs --remove-modules
fi
depmod
fi
@ -133,6 +133,9 @@ fi
%changelog
* Fri Sep 11 2020 Rafal Stefanowski <rafal.stefanowski@intel.com> - 20.09-1
- SLES related modifications
- Add some missing info about a package
* Thu Jul 30 2020 Rafal Stefanowski <rafal.stefanowski@intel.com> - 20.09-1
- Improve adding and removing modules with weak-modules
* Wed Jun 10 2020 Rafal Stefanowski <rafal.stefanowski@intel.com> - 20.06-1