Commit 90053262 authored by Ophélie Gagnard's avatar Ophélie Gagnard

obs/generic: Add generic OBS packaging.

lunzip is used as a basic example.
parent 61940634
ifeq ($(SOFTWARE_NAME),)
$(error Please, source your env before calling make! -> source software_name/env.sh)
endif
generic:
SOFTWARE_NAME=$(SOFTWARE_NAME) _generic/build-scripts/10tarball_directory.sh
SOFTWARE_NAME=$(SOFTWARE_NAME) _generic/build-scripts/20obs.sh
clean:
rm -rf tarballs/$(SOFTWARE_NAME)_*
clean_all:
rm -rf tarballs
rm -rf home:*
.PHONY: generic clean clean_all
####################################################
# Sourced in 10tarball_directory.sh and 20obs.sh
####################################################
### The user MUST define the following variables
# SOFTWARE_NAME -> the name of the software, which is the directory in obs/
# MAINTAINER_NAME
# MAINTAINER_EMAIL
# OBS_USER
### The user CAN define the following variables
## Debian packaging information
SOFTWARE_VERSION=${SOFTWARE_VERSION:-1}
DEBIAN_REVISION=${DEBIAN_REVISION:-1}
# For the version format, see: https://www.debian.org/doc/manuals/debian-faq/pkg-basics.en.html#pkgname
# here, in <foo>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
# VersionNumber is SOFTWARE_VERSION, DebianRevisionNumber is DEBIAN_REVISION
# note: the architecture is added when building the package (here: in OBS)
COMPOUND_VERSION=${COMPOUND_VERSION:-${SOFTWARE_VERSION}-${DEBIAN_REVISION}}
# This is the directory you want your package to install your software in.
# Use "/" for building an official distribution package.
TARGET_DIR="${TARGET_DIR:-/opt/$SOFTWARE_NAME}"
TARGET_DIR=$(realpath -m "$TARGET_DIR")
## Distribution information
# Source package
PACKAGE_SECTION=${PACKAGE_SECTION:-utils}
PACKAGE_PRIORITY=${PACKAGE_PRIORITY:-optional}
PACKAGE_BUILD_DEPENDENCIES=${PACKAGE_BUILD_DEPENDENCIES:-debhelper (>= 4.1.16), chrpath, python (>= 2.7),}
# Binary package
PACKAGE_ARCHITECTURE=${PACKAGE_ARCHITECTURE:-any}
PACKAGE_DEPENDENCIES=${PACKAGE_DEPENDENCIES:-\$\{misc:Depends\}, \$\{shlibs:Depends\},}
PACKAGE_CONFLICTS=${PACKAGE_CONFLICTS:-}
PACKAGE_SHORT_DESCRIPTION=${PACKAGE_SHORT_DESCRIPTION:-Package for ${SOFTWARE_NAME}.}
# Changelog
PACKAGE_DISTRIBUTION_VALUE=${PACKAGE_DISTRIBUTION_VALUE:-UNRELEASED}
PACKAGE_URGENCY=${PACKAGE_URGENCY:-medium}
## Buildout file and version
GIT_REPOSITORY=${GIT_REPOSITORY:-https://lab.nexedi.com/nexedi/slapos}
GIT_BRANCH_OR_COMMIT=${GIT_BRANCH_OR_COMMIT:-master}
BUILDOUT_RELATIVE_PATH=${BUILDOUT_RELATIVE_PATH:-software/$SOFTWARE_NAME/software.cfg}
## Versions
SETUPTOOLS_VERSION=${SETUPTOOLS_VERSION:-63.2.0}
ZC_BUILDOUT_VERSION=${ZC_BUILDOUT_VERSION:-2.7.1+slapos019}
## OBS information
# Get the user from osc configuration file.
OBS_PROJECT=${OBS_PROJECT:-home:$OBS_USER}
OBS_PACKAGE=${OBS_PACKAGE:-$SOFTWARE_NAME}
# OBS_COMMIT_MSG can be used, a prompt will be asked if empty or undefined
### The user CANNOT define the following variables
CURRENT_DATE="$(date -R)"
SOFTWARE_AND_VERSION="${SOFTWARE_NAME}_${COMPOUND_VERSION}"
ARCHIVE_EXT=.tar.gz
INITIAL_DIR=$(pwd)
TARBALL_DIR="$INITIAL_DIR/_tarballs/$SOFTWARE_AND_VERSION"
COMPILATION_FILES_GENERIC_DIR="$INITIAL_DIR/_generic/compilation"
COMPILATION_FILES_SOFTWARE_DIR="$INITIAL_DIR/$SOFTWARE_NAME/compilation"
BUILD_DIR="$TARBALL_DIR/build"
RUN_BUILDOUT_DIR="$BUILD_DIR/$TARGET_DIR"
DISTRIB_FILES_GENERIC_DIR="$INITIAL_DIR/_generic/distributions"
DISTRIB_FILES_SOFTWARE_DIR="$INITIAL_DIR/$SOFTWARE_NAME/distributions"
BUILDOUT_DIR="$TARBALL_DIR/slapos_repository"
BUILDOUT_ENTRY_POINT="$BUILDOUT_DIR/$BUILDOUT_RELATIVE_PATH"
BUILDOUT_ENTRY_POINT=$(realpath -m "$BUILDOUT_ENTRY_POINT")
OBS_DIR="$INITIAL_DIR/$OBS_PROJECT/$OBS_PACKAGE"
## Regular expressions for templates
NAME_REGEX="s|%SOFTWARE_NAME%|$SOFTWARE_NAME|g;s|%SOFTWARE_AND_VERSION%|$SOFTWARE_AND_VERSION|g"
VERSION_REGEX="s|%SOFTWARE_VERSION%|$SOFTWARE_VERSION|g;s|%DEBIAN_REVISION%|$DEBIAN_REVISION|g;s|%COMPOUND_VERSION%|$COMPOUND_VERSION|g"
BUILDOUT_REGEX="s|%SETUPTOOLS_VERSION%|$SETUPTOOLS_VERSION|g;s|%ZC_BUILDOUT_VERSION%|$ZC_BUILDOUT_VERSION|g;s|%ZC_RECIPE_EGG_VERSION%|$ZC_RECIPE_EGG_VERSION|g"
DIR_REGEX="s|%TARGET_DIR%|$TARGET_DIR|g;s|%BUILD_DIR%|$BUILD_DIR|g;s|%RUN_BUILDOUT_DIR%|$RUN_BUILDOUT_DIR|g"
PATH_REGEX="s|%BUILDOUT_ENTRY_POINT%|$BUILDOUT_ENTRY_POINT|g"
DISTRIB_REGEX="s|%MAINTAINER_NAME%|$MAINTAINER_NAME|g;s|%MAINTAINER_EMAIL%|$MAINTAINER_EMAIL|g;s|%CURRENT_DATE%|$CURRENT_DATE|g;s|%PACKAGE_SECTION%|$PACKAGE_SECTION|g;s|%PACKAGE_PRIORITY%|$PACKAGE_PRIORITY|g;s|%PACKAGE_BUILD_DEPENDENCIES%|$PACKAGE_BUILD_DEPENDENCIES|g;s|%PACKAGE_ARCHITECTURE%|$PACKAGE_ARCHITECTURE|g;s|%PACKAGE_DEPENDENCIES%|$PACKAGE_DEPENDENCIES|g;s|%PACKAGE_CONFLICTS%|$PACKAGE_CONFLICTS|g;s|%PACKAGE_SHORT_DESCRIPTION%|$PACKAGE_SHORT_DESCRIPTION|g;s|%PACKAGE_DISTRIBUTION_VALUE%|$PACKAGE_DISTRIBUTION_VALUE|g;s|%PACKAGE_URGENCY%|$PACKAGE_URGENCY|g;s|%PACKAGE_CHANGE_DETAILS%|$PACKAGE_CHANGE_DETAILS|g;s|%PACKAGE_DIRECTORIES%|$PACKAGE_DIRECTORIES|g"
ALL_REGEX=$NAME_REGEX";"$VERSION_REGEX";"$BUILDOUT_REGEX";"$DIR_REGEX";"$PATH_REGEX";"$DISTRIB_REGEX
copy_and_solve_templates () {
if [ ! -d "$1" ]; then
echo "INFO: copy_and_solve_templates(): The source directory does not exist, returning."
echo "$1"
return 0
elif [ ! -d "$2" ]; then
echo "ERROR: copy_and_solve_templates(): The target directory does not exist, returning."
echo "$2"
return 1
fi
for descriptor in "$1"/*; do
cp -r "$descriptor" "$2"
for template_path in $(find "$2/${descriptor##$1/}" -name *.in -type f); do
sed "$ALL_REGEX" "$template_path" > "${template_path%.in}"
rm "$template_path"
done
done
}
#!/bin/bash
set -e
source _generic/build-scripts/00env.sh
# BUILD TREE
### Clean the tarball directory
rm -rf "$TARBALL_DIR"
### Retrieve the buildout directory.
mkdir -p "$TARBALL_DIR"
git clone "$GIT_REPOSITORY" "$BUILDOUT_DIR"
cd "$BUILDOUT_DIR"
git checkout "$GIT_BRANCH_OR_COMMIT"
cd "$INITIAL_DIR"
### Prepare the build directories
mkdir -p "$RUN_BUILDOUT_DIR"/{eggs,extends-cache,download-cache/dist}
# COMPILATION FILES
### Prepare the compilation files
# copy compilation files and override the files from _generic
# with the one from <software_name>
copy_and_solve_templates "$COMPILATION_FILES_GENERIC_DIR" "$TARBALL_DIR"
copy_and_solve_templates "$COMPILATION_FILES_SOFTWARE_DIR" "$TARBALL_DIR"
mv "$TARBALL_DIR/local_buildout.cfg" "$RUN_BUILDOUT_DIR/buildout.cfg"
# BUILDOUT: BOOTSTRAPING AND RUN
### Download the bootstrap script
mkdir -p "$RUN_BUILDOUT_DIR"
cd "$RUN_BUILDOUT_DIR"
wget https://bootstrap.pypa.io/bootstrap-buildout.py
### Run buildout
# Note: it creates a lot of things in $RUN_BUILDOUT_DIR/eggs/ and uses software_release/ at some point
# bootstrap buildout (creates $RUN_BUILDOUT_DIR/bin/buildout)
python2.7 -S bootstrap-buildout.py \
--buildout-version "$ZC_BUILDOUT_VERSION" \
--setuptools-version "$SETUPTOOLS_VERSION" \
--setuptools-to-dir eggs -f http://www.nexedi.org/static/packages/source/slapos.buildout/
# backup $RUN_BUILDOUT_DIR/bin/buildout (to be restored for OBS)
cp bin/buildout bin/backup.buildout
# run $RUN_BUILDOUT_DIR/bin/buildout (note that it modifies itself via rebootstrapping when compiling python)
./bin/buildout -v
### Backup $TARBALL_DIR for debugging or other purpose
# add "backup." before the directory name pointed to by $TARBALL_DIR
BACKUP_DIR="$TARBALL_DIR"/../backup."$SOFTWARE_AND_VERSION"
rm -rf "$BACKUP_DIR"
cp -r "$TARBALL_DIR" "$BACKUP_DIR"
#!/bin/bash
set -e
source _generic/build-scripts/00env.sh
# DISTRIBUTION FILES
### Prepare the distribution files in $OBS_DIR
osc checkout "$OBS_PROJECT" "$OBS_PACKAGE" || true
cd "$OBS_DIR"
osc update
osc rm -f "$SOFTWARE_AND_VERSION$ARCHIVE_EXT" "$SOFTWARE_AND_VERSION".dsc
cd "$INITIAL_DIR"
# copy compilation files and override the files from _generic
# with the one from <software_name>
copy_and_solve_templates "$DISTRIB_FILES_GENERIC_DIR" "$OBS_DIR"
mv "$OBS_DIR"/_generic.dsc "$OBS_DIR/$SOFTWARE_AND_VERSION.dsc"
copy_and_solve_templates "$DISTRIB_FILES_SOFTWARE_DIR" "$OBS_DIR"
# ARCHIVES FILES
### Finalize the tarball directory preparation
# switch to the buildout wrapper for OBS
mv "$TARBALL_DIR/obs_buildout.cfg" "$RUN_BUILDOUT_DIR/buildout.cfg"
# save the local $TARBALL_DIR path so that it is replaced by the $TARBALL_DIR path from OBS' VM
echo "$TARBALL_DIR" > "$TARBALL_DIR"/local_tarball_directory_path
# add a stamp so that OBS does not clean the local preparation before compiling
touch "$TARBALL_DIR/clean-stamp"
# restore bin/buildout
# note: when installing python, buildout "rebootstraps" itself to use the installed python:
# it modifies its own shebang, which would fail on OBS' VM (no such file or directory)
if [ -f "$RUN_BUILDOUT_DIR"/bin/backup.buildout ]; then
mv "$RUN_BUILDOUT_DIR"/bin/backup.buildout "$RUN_BUILDOUT_DIR"/bin/buildout
fi
# clean the compilation related files
rm -rf "$RUN_BUILDOUT_DIR"/{.installed.cfg,parts}
### Prepare the archives for OBS
# -C option allows to give tar an absolute path without archiving the directory from / (i.e. home/user/[...])
tar czf "$OBS_DIR/$SOFTWARE_AND_VERSION$ARCHIVE_EXT" -C "$INITIAL_DIR/_tarballs" "$SOFTWARE_AND_VERSION"
tar czf "$OBS_DIR/debian$ARCHIVE_EXT" -C "$OBS_DIR" debian
# OBS COMMIT
cd "$OBS_DIR"
osc add *.dsc *"$ARCHIVE_EXT"
if [ -n "$OBS_COMMIT_MSG" ]; then
osc commit -m "$OBS_COMMIT_MSG"
else
osc commit
fi
build:
makefile-scripts/build.sh
clean: clean-stamp
clean-stamp:
makefile-scripts/clean.sh
install: build
makefile-scripts/install.sh
.PHONY: build install clean
[buildout]
rootdir = %TARGET_DIR%
destdir = %BUILD_DIR%
builddir = %RUN_BUILDOUT_DIR%
extends =
%BUILDOUT_ENTRY_POINT%
versions = versions
extends-cache = extends-cache
download-cache = download-cache
[versions]
setuptools = %SETUPTOOLS_VERSION%
zc.buildout = %ZC_BUILDOUT_VERSION%
#!/bin/bash
set -e
source makefile-scripts/compilation-env.sh
echo "Fixing buildout path to "$TARBALL_DIR" rather than "$OLD_TARBALL_DIR" for buildout"
cd "$RUN_BUILDOUT_DIR"
sed -i "s#$OLD_TARBALL_DIR#$TARBALL_DIR#g" buildout.cfg bin/*
bin/buildout -v
touch clean-stamp
#!/bin/bash
set -e
source makefile-scripts/compilation-env.sh
rm -rf "$BUILD_DIR"
# This templates are replaced by build-scripts/10tarball_directory.sh
# according to the values and regular expressions defined in
# build-scripts/00env.sh and build-scripts/custom-env/NAME_env.sh
TARGET_DIR="%TARGET_DIR%"
TARBALL_DIR="$(pwd)"
BUILD_DIR="$TARBALL_DIR"/build
INSTALL_DIR="$DESTDIR""$TARGET_DIR"
RUN_BUILDOUT_DIR="$BUILD_DIR""$TARGET_DIR"
# get the path of the BUILD_DIR of the first build (performed to prepare the cache for OBS)
OLD_TARBALL_DIR="$(cat local_tarball_directory_path)"
TARBALL_DIR=$(realpath -m "$TARBALL_DIR")
BUILD_DIR=$(realpath -m "$BUILD_DIR")
INSTALL_DIR=$(realpath -m "$INSTALL_DIR")
RUN_BUILDOUT_DIR=$(realpath -m "$RUN_BUILDOUT_DIR")
OLD_TARBALL_DIR=$(realpath -m "$OLD_TARBALL_DIR")
#!/bin/bash
set -e
source makefile-scripts/compilation-env.sh
mkdir -p "$INSTALL_DIR/bin"
mkdir -p "$INSTALL_DIR/etc"
mkdir -p "$INSTALL_DIR/include"
mkdir -p "$INSTALL_DIR/lib"
mkdir -p "$INSTALL_DIR/sbin"
mkdir -p "$INSTALL_DIR/usr/share"
# no "-r" option to "cp" because there must not be subdirectories in /bin
# https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s04.html
# https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s13.html
cp "$RUN_BUILDOUT_DIR/parts/"*/bin/* "$INSTALL_DIR/bin" || true
cp -r "$RUN_BUILDOUT_DIR/parts/"*/etc/* "$INSTALL_DIR/etc" || true
cp -r "$RUN_BUILDOUT_DIR/parts/"*/include/* "$INSTALL_DIR/include" || true
cp -r "$RUN_BUILDOUT_DIR/parts/"*/lib/* "$INSTALL_DIR/lib" || true
cp -r "$RUN_BUILDOUT_DIR/parts/"*/sbin/* "$INSTALL_DIR/sbin" || true
cp -r "$RUN_BUILDOUT_DIR/parts/"*/share/* "$INSTALL_DIR/usr/share" || true
rm -f clean-stamp
[buildout]
rootdir = %TARGET_DIR%
destdir = %BUILD_DIR%
builddir = %RUN_BUILDOUT_DIR%
extends =
%BUILDOUT_ENTRY_POINT%
versions = versions
extends-cache = extends-cache
download-cache = download-cache
[versions]
setuptools = %SETUPTOOLS_VERSION%
zc.buildout = %ZC_BUILDOUT_VERSION%
Format: 3.0 (quilt)
Source: %SOFTWARE_NAME%
Architecture: %PACKAGE_ARCHITECTURE%
Version: %COMPOUND_VERSION%
Build-Depends: %PACKAGE_BUILD_DEPENDENCIES%
%SOFTWARE_NAME% (%COMPOUND_VERSION%) %PACKAGE_DISTRIBUTION_VALUE%; urgency=%PACKAGE_URGENCY%
* Development release.
-- %MAINTAINER_NAME% <%MAINTAINER_EMAIL%> %CURRENT_DATE%
Source: %SOFTWARE_NAME%
Maintainer: %MAINTAINER_NAME% <%MAINTAINER_EMAIL%>
Section: %PACKAGE_SECTION%
Priority: %PACKAGE_PRIORITY%
Build-Depends: %PACKAGE_BUILD_DEPENDENCIES%
Package: %SOFTWARE_NAME%
Architecture: %PACKAGE_ARCHITECTURE%
Depends: %PACKAGE_DEPENDENCIES%
Conflicts: %PACKAGE_CONFLICTS%
Description: %PACKAGE_SHORT_DESCRIPTION%
#!/usr/bin/make -f
#export DH_VERBOSE = 1
%:
dh $@
[buildout]
rootdir = %TARGET_DIR%
destdir = %BUILD_DIR%
builddir = %RUN_BUILDOUT_DIR%
extends =
%BUILDOUT_ENTRY_POINT%
versions = versions
extends-cache = extends-cache
download-cache = download-cache
[versions]
setuptools = %SETUPTOOLS_VERSION%
zc.buildout = %ZC_BUILDOUT_VERSION%
[buildout]
rootdir = %TARGET_DIR%
destdir = %BUILD_DIR%
builddir = %RUN_BUILDOUT_DIR%
extends =
%BUILDOUT_ENTRY_POINT%
versions = versions
extends-cache = extends-cache
download-cache = download-cache
[versions]
setuptools = %SETUPTOOLS_VERSION%
zc.buildout = %ZC_BUILDOUT_VERSION%
export SOFTWARE_NAME=lunzip
export MAINTAINER_NAME="Ophelie"
export MAINTAINER_EMAIL="ophelie.gagnard@nexedi.com"
export OBS_USER=oph.nxd
export TARGET_DIR="/"
export BUILDOUT_RELATIVE_PATH=component/lunzip/buildout.cfg
export SETUPTOOLS_VERSION=44.1.1
export ZC_BUILDOUT_VERSION=2.7.1+slapos016
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment