Move build system tools to separate directory

Separate tools used internally by build system from utilities that are
part of Open CAS installation package.

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga
2021-03-19 13:35:54 +01:00
parent feaafdfe06
commit e58dae02ac
17 changed files with 12 additions and 12 deletions

View File

@@ -70,11 +70,11 @@ endif
uninstall:
@echo "Uninstalling Open-CAS utils"
@rm $(DESTDIR)/etc/opencas/opencas.conf
@rm $(DESTDIR)/etc/opencas/ioclass-config.csv
@rm -rf $(DESTDIR)/etc/opencas
@rm $(DESTDIR)/var/lib/opencas/cas_version
@rm -rf $(DESTDIR)/var/lib/opencas
@rm $(DESTDIR)/etc/opencas/opencas.conf
@rm $(DESTDIR)/etc/opencas/ioclass-config.csv
@rm -rf $(DESTDIR)/etc/opencas
@rm $(DESTDIR)/var/lib/opencas/cas_version
@rm -rf $(DESTDIR)/var/lib/opencas
@rm $(DESTDIR)/usr/share/man/man5/opencas.conf.5
@rm $(DESTDIR)$(CASCTL_DIR)/opencas.py

View File

@@ -1,107 +0,0 @@
#!/bin/bash
#
# Copyright(c) 2020-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
THIS=$(basename "$0")
SOURCES_DIR="$(realpath ../)"
MANUAL_VERSION_INPUT="$SOURCES_DIR/version"
VERSION_FILE="$SOURCES_DIR/.metadata/cas_version"
SUBMODULES=(
"ocf"
"test/functional/test-framework"
)
warning() {
echo -e "\e[33mWARNING\e[0m: $THIS: $*" >&2
}
error() {
echo -e "\e[31mERROR\e[0m: $THIS: $*" >&2
exit 1
}
# Check if we're inside a git repository
if [[ -d "$SOURCES_DIR/.git" ]] && which git &>/dev/null &&\
(cd "$SOURCES_DIR" && git rev-parse --is-inside-work-tree &>/dev/null); then
if [[ ! -r "$MANUAL_VERSION_INPUT" ]]; then
error "can't read version input file '$MANUAL_VERSION_INPUT'"
fi
. "$MANUAL_VERSION_INPUT"
if [[ ! "$CAS_VERSION_MAIN" || ! "$CAS_VERSION_MAJOR" || ! "$CAS_VERSION_MINOR" ]]; then
error "'$MANUAL_VERSION_INPUT' - wrong version input file format;"\
"file should contain CAS_VERSION_MAIN, CAS_VERSION_MAJOR and CAS_VERSION_MINOR"\
"variables along with their respective values"
fi
CAS_VERSION_BUILD=$(cd "$SOURCES_DIR" && git log --merges --oneline | wc -l)
LAST_COMMIT_HASH=$(cd "$SOURCES_DIR" && git log -1 --pretty=format:%H)
LAST_COMMIT_HASH_ABBR=$(cd "$SOURCES_DIR" && git log -1 --pretty=format:%h)
LAST_COMMIT_DATE=$(cd "$SOURCES_DIR" && git log -1 --pretty=format:%ci |\
sed "s/ /T/" | sed "s/ //" | sed "s/00$/:00/")
LAST_COMMIT_TIMESTAMP=$(cd "$SOURCES_DIR" && git log -1 --pretty=format:%ct)
for SUBMOD in ${SUBMODULES[@]}; do
LAST_SUB_COMMIT_HASHES+=($(cd "$SOURCES_DIR/$SUBMOD" && git log -1 --pretty=format:%H))
LAST_SUB_COMMIT_HASHES_ABBR+=($(cd "$SOURCES_DIR/$SUBMOD" && git log -1 --pretty=format:%h))
done
if [[ $(cd "$SOURCES_DIR" && git tag --points-at HEAD) ]]; then
CAS_VERSION_RELEASE="release"
elif [[ $(cd "$SOURCES_DIR" && git log -1 --pretty=format:%H)\
== $(cd "$SOURCES_DIR" && git log -1 --merges --pretty=format:%H) ]]; then
CAS_VERSION_RELEASE="master"
else
CAS_VERSION_RELEASE="devel"
fi
CAS_VERSION=$(printf "%02d.%02d.%01d.%04d.%s" $CAS_VERSION_MAIN $CAS_VERSION_MAJOR\
$CAS_VERSION_MINOR $CAS_VERSION_BUILD $CAS_VERSION_RELEASE)
mkdir -p $(dirname "$VERSION_FILE")
if ! touch "$VERSION_FILE"; then
error "couldn't create version file '$VERSION_FILE'"
fi
echo "CAS_VERSION_MAIN=$CAS_VERSION_MAIN" > "$VERSION_FILE"
echo "CAS_VERSION_MAJOR=$CAS_VERSION_MAJOR" >> "$VERSION_FILE"
echo "CAS_VERSION_MINOR=$CAS_VERSION_MINOR" >> "$VERSION_FILE"
echo "CAS_VERSION_BUILD=$CAS_VERSION_BUILD" >> "$VERSION_FILE"
echo "CAS_VERSION_RELEASE=$CAS_VERSION_RELEASE" >> "$VERSION_FILE"
echo "CAS_VERSION=$CAS_VERSION" >> "$VERSION_FILE"
echo "LAST_COMMIT_HASH=$LAST_COMMIT_HASH" >> "$VERSION_FILE"
echo "LAST_COMMIT_HASH_ABBR=$LAST_COMMIT_HASH_ABBR" >> "$VERSION_FILE"
echo "LAST_COMMIT_DATE=$LAST_COMMIT_DATE" >> "$VERSION_FILE"
echo "LAST_COMMIT_TIMESTAMP=$LAST_COMMIT_TIMESTAMP" >> "$VERSION_FILE"
echo "LAST_SUB_COMMIT_HASHES=(${LAST_SUB_COMMIT_HASHES[@]})" >> "$VERSION_FILE"
echo "LAST_SUB_COMMIT_HASHES_ABBR=(${LAST_SUB_COMMIT_HASHES_ABBR[@]})" >> "$VERSION_FILE"
FILE_CREATION_DATE=$(date --iso-8601=seconds)
FILE_CREATION_TIMESTAMP=$(date +%s)
echo "FILE_CREATION_DATE=$FILE_CREATION_DATE" >> "$VERSION_FILE"
echo "FILE_CREATION_TIMESTAMP=$FILE_CREATION_TIMESTAMP" >> "$VERSION_FILE"
elif [[ -r "$VERSION_FILE" ]]; then
. "$VERSION_FILE" >/dev/null
if [[ ! "$CAS_VERSION" ]]; then
error "'$VERSION_FILE' - wrong version file format; file does not contain CAS_VERSION"
fi
else
error "couldn't obtain CAS version - no git tree nor readable version file found"
fi
# Check if this script was called during building of OpenCAS...
if [[ "$1" == "build" ]]; then
if ! touch "$VERSION_FILE"; then
warning "couldn't edit version file '$VERSION_FILE'"
fi
# ...and if so, add (or substitute if exist) a build time to version file
CAS_BUILD_DATE=$(date --iso-8601=seconds)
CAS_BUILD_TIMESTAMP=$(date +%s)
if grep CAS_BUILD_DATE "$VERSION_FILE" &>/dev/null; then
sed -i "s/CAS_BUILD_DATE=.*/CAS_BUILD_DATE=$CAS_BUILD_DATE/" "$VERSION_FILE"
sed -i "s/CAS_BUILD_TIMESTAMP=.*/CAS_BUILD_TIMESTAMP=$CAS_BUILD_TIMESTAMP/" "$VERSION_FILE"
else
echo "CAS_BUILD_DATE=$CAS_BUILD_DATE" >> "$VERSION_FILE"
echo "CAS_BUILD_TIMESTAMP=$CAS_BUILD_TIMESTAMP" >> "$VERSION_FILE"
fi
fi

View File

@@ -1,552 +0,0 @@
#!/bin/bash
#
# Copyright(c) 2020-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
# To make additional packages creation possible
# through this script all you need to do is:
# - add 'case' command to set variable GENERATE_<NAME>="generate_<name>"
# - add function 'generate_<name>' to handle the task
# - add 'DEPENDENCIES_<NAME>' array if needed
# - update help!
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"))
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=(git mktemp rsync sed)
# Dependencies for particular packages creation:
DEPENDENCIES_TAR=(tar)
DEPENDENCIES_ZIP=(zip)
DEPENDENCIES_RPM=(rpmbuild tar)
DEPENDENCIES_SRPM=("${DEPENDENCIES_RPM[@]}")
DEPENDENCIES_DEB=(debuild dh fakeroot tar dkms)
DEPENDENCIES_DSC=("${DEPENDENCIES_DEB[@]}")
# List of relative submodule directories:
SUBMODULES=(
"ocf"
"test/functional/test-framework"
)
# Unset all variables that may be checked for existence:
unset ${!GENERATE_*} ARCHIVE_PREPARED DEBUG FAILED_DEPS OUTPUT_DIR RPM_BUILT\
SOURCES_DIR SUBMODULES_MISSING TAR_CREATED
usage() {
echo "Usage:"
echo " ./$THIS <commands> [options] <SOURCES_PATH>"
echo " ./$THIS -c|-h"
echo "where SOURCES_PATH is the root directory of OpenCAS sources"
}
print_help() {
echo "Generate OpenCAS packages."
echo "$(usage)"
echo
echo "This script generates various OpenCAS packages like"
echo "release archives (tar, zip) and RPMs (source and binary)."
echo
echo "Mandatory arguments to long options are mandatory for short options too."
echo
echo "Commands:"
echo " tar generate tar archive"
echo " zip generate zip archive"
echo " rpm generate RPM packages"
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;"
echo " default: 'SOURCES_PATH/packages/'"
echo " -d, --debug create all debug files and packages as well"
echo " -c, --clean clean all temporary files and folders that"
echo " may have been left around if $THIS ended"
echo " unexpectedly in the previous run"
echo " -h, --help print this help message"
echo
}
invalid_usage() {
echo -e "$THIS: $*\nTry './$THIS --help' for more information." >&2
exit 2
}
info() {
echo -e "\e[33m$*\e[0m"
}
error() {
echo -e "\e[31mERROR\e[0m: $THIS: $*" >&2
exit 1
}
clean() {
rm -rf "$TEMP_DIR"
if [ -d "$TEMP_DIR" ]; then
# Print only warning to not confuse the user by an error here
# if packages were created successfully and everything else
# went fine except cleaning temp directory at the end.
info "WARNING: Cleanup failed" >&2
fi
}
clean_all() {
info "Removing all temp files and dirs that may have been left around..."
rm -rf "/tmp/${TEMP_TEMPLATE}."*
if ls "/tmp/${TEMP_TEMPLATE}."* &>/dev/null; then
# This function on the other hand is called only by a '-c' option
# so we may throw an error here and exit.
error "cleanup failed"
fi
}
check_options() {
if [ ! "$SOURCES_DIR" ]; then
invalid_usage "no mandatory SOURCES_PATH provided"
elif [[ $(head -n 1 "$SOURCES_DIR/README.md" 2>/dev/null) != *Open*CAS*Linux* ]]; then
invalid_usage "'$SOURCES_DIR' does not point to the root directory of CAS sources"
elif [ ! "${!GENERATE_*}" ]; then
invalid_usage "nothing to do - no command provided"
fi
}
check_version() {
if ! (cd $(dirname "$CAS_VERSION_GEN") && ./$(basename "$CAS_VERSION_GEN")); then
error "failed to obtain CAS version"
fi
. "$VERSION_FILE"
VERSION_SHORT="${CAS_VERSION_MAIN}.$(printf %02d ${CAS_VERSION_MAJOR})"
if [ $CAS_VERSION_MINOR -ne 0 ]; then
VERSION_SHORT+=".${CAS_VERSION_MINOR}"
fi
if [[ "$VERSION_SHORT" < "$SUPPORTED_FROM_VERSION" ]]; then
echo "Sorry... this version of $CAS_NAME ($VERSION_SHORT) is not supported"\
"by $THIS. Use $CAS_NAME >= $SUPPORTED_FROM_VERSION"
exit 1
fi
for SUBMOD in ${SUBMODULES[@]}; do
if ! ls -A "$SOURCES_DIR/$SUBMOD/"* &>/dev/null; then
local SUBMODULES_MISSING+="'$SUBMOD'\n"
fi
done
if [ "$SUBMODULES_MISSING" ]; then
error "There are missing submodules:\n${SUBMODULES_MISSING}\nUpdate submodules and try again!"
fi
}
check_dependencies() {
echo "--- Checking for dependencies"
for package in ${!GENERATE_*}; do
local DEP_NAME="DEPENDENCIES_${package##*_}[@]"
DEPENDENCIES+=(${!DEP_NAME})
done
for DEP in ${DEPENDENCIES[@]}; do
if ! which $DEP &>/dev/null; then
local FAILED_DEPS+="$DEP "
fi
done
if [ "$FAILED_DEPS" ]; then
error "Dependencies not installed. You need to provide these programs first: $FAILED_DEPS"
fi
}
create_dir() {
mkdir -p "$*"
if [ ! -d "$*" ] || [ ! -w "$*" ]; then
error "no access to '$*'"
fi
}
create_temp() {
TEMP_DIR=$(mktemp -d -t ${TEMP_TEMPLATE}.XXXXXXXXXX)
if [ $? -ne 0 ]; then
error "couldn't create temporary directory"
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 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"
}
generate_tar() {
if [ ! "$TAR_CREATED" ]; then
archive_prepare
echo "--- Creating tar archive from current sources"
tar -C "$TEMP_DIR" -zcf "$TEMP_DIR/$SOURCES_TAR_NAME" "$CAS_FILENAME"
if [ $? -ne 0 ] || [ ! -f "$TEMP_DIR/$SOURCES_TAR_NAME" ]; then
rm -rf "$TEMP_DIR/$SOURCES_TAR_NAME"
error "couldn't create tar archive"
fi
TAR_CREATED="tar_created"
fi
if [ "$1" != "temp" ]; then
cp "$TEMP_DIR/$SOURCES_TAR_NAME" "$OUTPUT_DIR"
fi
}
generate_zip() {
archive_prepare
echo "--- Creating zip archive from current sources"
(cd "$TEMP_DIR" && zip -qr - "$CAS_FILENAME") > "$OUTPUT_DIR/$SOURCES_ZIP_NAME"
if [ $? -ne 0 ] || [ ! -f "$OUTPUT_DIR/$SOURCES_ZIP_NAME" ]; then
rm -rf "$OUTPUT_DIR/$SOURCES_ZIP_NAME"
error "couldn't create zip archive"
fi
}
rpm_create_tree() {
echo "--- Creating directory tree for building RPMs"
mkdir -p "$RPM_BUILD_DIR/"{BUILD,RPMS,SOURCES,SPECS,SRPMS}
if [ $? -ne 0 ] || [ ! -w "$RPM_BUILD_DIR" ]; then
error "couldn't create directory tree for building RPMs"
fi
}
rpm_obtain_sources() {
echo "--- Obtaining CAS sources for RPMs"
generate_tar temp
cp -v "$TEMP_DIR/$SOURCES_TAR_NAME" "$RPM_SOURCES_DIR"
if [ ! -f "$RPM_SOURCES_DIR/$SOURCES_TAR_NAME" ]; then
error "couldn't obtain $SOURCES_TAR_NAME sources tarball!"
fi
}
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
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"
fi
if [ ! -f "$RPM_SPECS_DIR/$CAS_NAME.spec" ]; then
error "couldn't create a SPEC file"
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
fi
rpm_create_tree
rpm_obtain_sources
rpm_spec_prepare
. $SYS_INFO
if [[ "$ID_LIKE" =~ suse|sles ]] && [ -d /usr/src/packages ]; then
info "INFO: It appears that you are using SUSE Linux."\
"In case of encountering error during building of RPM package,"\
"about missing files or directories in /usr/src/packages/,"\
"remove or rename '/usr/src/packages' folder to prevent"\
"rpmbuild to look for stuff in that location."
fi
if [ ! "$GENERATE_SRPM" ] && [ "$GENERATE_RPM" ]; then
echo "--- Building binary RPM packages"
(HOME="$TEMP_DIR"; rpmbuild -bb "$RPM_SPECS_DIR/$CAS_NAME.spec")
if [ $? -ne 0 ]; then
error "couldn't create RPM packages"
fi
mv -ft "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
fi
if [ "$GENERATE_SRPM" ] && [ ! "$GENERATE_RPM" ]; then
echo "--- Building source SRPM package"
(HOME="$TEMP_DIR"; rpmbuild -bs "$RPM_SPECS_DIR/$CAS_NAME.spec")
if [ $? -ne 0 ]; then
error "couldn't create SRPM package"
fi
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
fi
if [ "$GENERATE_SRPM" ] && [ "$GENERATE_RPM" ]; then
echo "--- Building source and binary RPM packages"
(HOME="$TEMP_DIR"; rpmbuild -ba "$RPM_SPECS_DIR/$CAS_NAME.spec")
if [ $? -ne 0 ]; then
error "couldn't create RPM packages"
fi
mv -ft "$OUTPUT_DIR" "$RPM_SRPMS_DIR"/*
mv -ft "$OUTPUT_DIR" "$RPM_RPMS_DIR/$ARCH"/*
fi
RPM_BUILT="rpm_built"
}
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"
fi
while (( $# )); do
case "$1" in
tar)
GENERATE_TAR="generate_tar"
;;
zip)
GENERATE_ZIP="generate_zip"
;;
rpm)
GENERATE_RPM="generate_rpm"
;;
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
invalid_usage "no output directory given after the '--output-dir' option"
fi
shift
;;
--debug|-d)
DEBUG="debug"
;;
--clean|-c)
clean_all
exit 0
;;
--help|-h)
print_help
exit 0
;;
*)
if [ -d "$1" ]; then
SOURCES_DIR=$(realpath "$1")
else
invalid_usage "option '$1' not recognized"
fi
;;
esac
shift
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:
RPM_BUILD_DIR="$TEMP_DIR/rpmbuild"
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:
CAS_VERSION_GEN="$SOURCES_DIR/utils/cas_version_gen"
check_version
# CAS naming convention:
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"
#
# Run the package generator script
#
info "\n=== Running OpenCAS '$CAS_VERSION' package generator ===\n"
echo -n "Packages that will be built: "
for package in ${!GENERATE_*}; do
echo -en "\e[33m${package##*_}\e[0m "
done
echo -e "\n"
check_dependencies
create_dir "$OUTPUT_DIR"
for package in ${!GENERATE_*}; do
${package,,}
done
echo -e "\n\e[32m=== ALL DONE ===\e[0m\n\nYou can find your fresh packages in '$OUTPUT_DIR'\n"

View File

@@ -1,11 +0,0 @@
PACKAGE_NAME="<CAS_NAME>-modules"
PACKAGE_VERSION="#MODULE_VERSION#"
BUILT_MODULE_NAME[0]="cas_disk"
BUILT_MODULE_NAME[1]="cas_cache"
BUILT_MODULE_LOCATION[0]="modules/cas_disk/"
BUILT_MODULE_LOCATION[1]="modules/cas_cache/"
DEST_MODULE_LOCATION[0]="/extra"
DEST_MODULE_LOCATION[1]="/extra"
PRE_BUILD="./configure"
MAKE[0]="make -j -C modules/ KERNEL_VERSION=$kernelver"
AUTOINSTALL=yes

View File

@@ -1,9 +0,0 @@
./.metadata/* usr/src/<CAS_NAME>-modules-<CAS_VERSION>/.metadata/
./modules/* usr/src/<CAS_NAME>-modules-<CAS_VERSION>/modules/
./ocf/* usr/src/<CAS_NAME>-modules-<CAS_VERSION>/ocf/
./utils/* usr/src/<CAS_NAME>-modules-<CAS_VERSION>/utils/
./configure.d/* usr/src/<CAS_NAME>-modules-<CAS_VERSION>/configure.d/
./configure usr/src/<CAS_NAME>-modules-<CAS_VERSION>/
./Makefile usr/src/<CAS_NAME>-modules-<CAS_VERSION>/
./LICENSE usr/src/<CAS_NAME>-modules-<CAS_VERSION>/
./version usr/src/<CAS_NAME>-modules-<CAS_VERSION>/

View File

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

View File

@@ -1,8 +0,0 @@
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

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

View File

@@ -1,17 +0,0 @@
<CAS_NAME> (<CAS_VERSION>-1) trusty; urgency=medium
* pckgen: automated package generation
-- <PACKAGE_MAINTAINER> <PACKAGE_DATE>
open-cas-linux (20.03.3.0303-1) trusty; urgency=medium
* Add DKMS support
-- Robert Baldyga <robert.baldyga@intel.com> Mon, 02 Nov 2020 18:47:04 +0200
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

@@ -1 +0,0 @@
12

View File

@@ -1,30 +0,0 @@
Source: <CAS_NAME>
Section: utils
Priority: optional
Maintainer: <PACKAGE_MAINTAINER>
Build-Depends: debhelper (>= 11), gawk, libelf-dev, linux-headers-generic, dkms
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}, debhelper (>= 9), dkms
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

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

View File

@@ -1,31 +0,0 @@
#!/usr/bin/make -f
# output every command that modifies files on the build system
#export DH_VERBOSE = 1
%:
dh $@ --with dkms
override_dh_auto_configure :
override_dh_auto_build :
(cd utils/; ./cas_version_gen build)
make -C casadm
override_dh_auto_install :
make -C casadm install_files DESTDIR="$(shell pwd)/debian/tmp"
make -C utils install_files DESTDIR="$(shell pwd)/debian/tmp"
# clean and generate version again before installing sources for DKMS
make distclean
(cd utils/; ./cas_version_gen)
override_dh_dkms :
dh_dkms -V $(DEB_VERSION_UPSTREAM)
override_dh_installsystemd :
dh_installsystemd --no-start
override_dh_missing :
override_dh_gencontrol :
dh_gencontrol -- -Vkver="$(shell uname -r)"

View File

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

View File

@@ -1,175 +0,0 @@
#
# Copyright(c) 2020-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
#
# 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.
#
%global __python %{__python3}
%define debug_package %{nil}
%define kver %(uname -r)
%define kver_filename k%{expand:%(kname="%{kver}"; echo "${kname%.*}" | sed -r "y/-/_/;")}
Name: <CAS_NAME>
Version: <CAS_VERSION>
Release: 1%{?dist}
Summary: Open Cache Acceleration Software
Group: System
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
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.
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.
%package modules_%{kver_filename}
Summary: Open Cache Acceleration Software kernel modules
Group: System
Requires: kmod
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 only CAS kernel modules.
%prep
%setup -q
%build
./configure
%make_build
%install
rm -rf $RPM_BUILD_ROOT
/usr/bin/make install_files DESTDIR=$RPM_BUILD_ROOT
%post
systemctl daemon-reload
systemctl -q enable open-cas-shutdown
systemctl -q enable open-cas
%preun
if [ $1 -eq 0 ]; then
systemctl -q disable open-cas-shutdown
systemctl -q disable open-cas
rm -rf /lib/opencas/{__pycache__,*.py[co]} &>/dev/null
fi
%postun
if [ $1 -eq 0 ]; then
systemctl daemon-reload
fi
%post modules_%{kver_filename}
depmod
. /etc/os-release
if [[ ! "$ID_LIKE" =~ suse|sles ]]; then
# Determine the exact location of installed modules to add them to weak-modules
for file in $(rpm -ql $(rpm -qa | grep <CAS_NAME>-modules)); do
if [[ "$file" =~ cas_.*\.ko$ ]]; then
# realpath to resolve any possible symlinks (needed for weak-modules)
modules+=( $(realpath "$file") )
fi
done
printf "%s\n" "${modules[@]}" | weak-modules --no-initramfs --add-modules
fi
%preun modules_%{kver_filename}
if [ $1 -eq 0 ]; then
. /etc/os-release
if [[ ! "$ID_LIKE" =~ suse|sles ]]; then
# Search for all CAS modules to remove them from weak-modules
find /lib/modules/*/extra/ -name "cas_*.ko" >/var/run/rpm-open-cas-linux-modules
fi
fi
%postun modules_%{kver_filename}
if [ $1 -eq 0 ]; then
. /etc/os-release
if [[ ! "$ID_LIKE" =~ suse|sles ]]; then
# realpath to resolve any possible symlinks (needed for weak-modules)
modules=( $(realpath $(cat /var/run/rpm-open-cas-linux-modules)) )
rm -f /var/run/rpm-open-cas-linux-modules
printf "%s\n" "${modules[@]}" | weak-modules --no-initramfs --remove-modules
fi
depmod
fi
%files
%defattr(-, root, root)
%license LICENSE
%doc README.md
%dir /etc/opencas/
%dir /lib/opencas/
%dir /var/lib/opencas
%config /etc/opencas/opencas.conf
/etc/opencas/ioclass-config.csv
/etc/dracut.conf.d/opencas.conf
/var/lib/opencas/cas_version
/lib/opencas/casctl
/lib/opencas/open-cas-loader
/lib/opencas/opencas.py
/lib/udev/rules.d/60-persistent-storage-cas-load.rules
/lib/udev/rules.d/60-persistent-storage-cas.rules
/sbin/casadm
/sbin/casctl
/usr/lib/systemd/system-shutdown/open-cas.shutdown
/usr/lib/systemd/system/open-cas-shutdown.service
/usr/lib/systemd/system/open-cas.service
/usr/share/man/man5/opencas.conf.5.gz
/usr/share/man/man8/casadm.8.gz
/usr/share/man/man8/casctl.8.gz
%ghost /var/log/opencas.log
%ghost /lib/opencas/opencas.pyc
%ghost /lib/opencas/opencas.pyo
%ghost /lib/opencas/__pycache__
%files modules_%{kver_filename}
%defattr(-, root, root)
/lib/modules/%{kver}/extra/cas_cache.ko
/lib/modules/%{kver}/extra/cas_disk.ko
%changelog
* Mon Feb 8 2021 Rafal Stefanowski <rafal.stefanowski@intel.com> - 21.03-1
- Improve python files handling
* Tue Jan 5 2021 Rafal Stefanowski <rafal.stefanowski@intel.com> - 20.12-1
- Fix resolving modules path for weak-modules
* 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
- Add cas_version file
- Join Release into Version
- Simplify prep setup
* Tue Feb 25 2020 Rafal Stefanowski <rafal.stefanowski@intel.com> - 20.3-1
- Minor improvements in SPEC file
- Update files list for releases > 20.1
* Thu Feb 06 2020 Rafal Stefanowski <rafal.stefanowski@intel.com> - 20.1-1
- Create this SPEC file for OpenCAS release 20.1