Base nouveau process d'empaquetage

This commit is contained in:
2015-08-04 17:45:10 +02:00
parent 977776da2e
commit 51198bb298
5 changed files with 62 additions and 38 deletions

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
#set -x
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${DIR}/util.sh"
@ -9,7 +11,9 @@ SRC_DIR="${BASE_DIR}/src"
function get_project_opt {
filter=${1}
manifest_path=${SRC_DIR}/tamarin.json
jq -r "${filter}" ${manifest_path} | sed 's/null//g'
if [ -e "${manifest_path}" ]; then
jq -r "${filter}" ${manifest_path} | sed 's/null//g'
fi
}
function get_build_dir {
@ -25,10 +29,15 @@ function exec_hook {
hook_name=${1}
build_dir=${2}
hook_script="${SRC_DIR}/$(get_project_opt .hooks.${hook_name})"
hook_script="$(get_project_opt .hooks.${hook_name} | sed 's/null//')"
# Test hook script existence
if [ ! -f "${hook_script}" ]; then
# if [ ! -f "${hook_script}" ]; then
# info "No ${hook_name} hook."
# return
# fi
if [ -z "${hook_script}" ]; then
info "No ${hook_name} hook."
return
fi
@ -36,10 +45,10 @@ function exec_hook {
info "Executing ${hook_name} hook..."
# Ensure the hook script is executable
chmod +x "${hook_script}"
#chmod +x "${hook_script}"
# Execute hook in a subshell
( cd ${SRC_DIR} && DESTDIR="${build_dir}" SRCDIR="${SRC_DIR}" exec "${hook_script}" )
( cd ${SRC_DIR} && DESTDIR="${build_dir}" SRCDIR="${SRC_DIR}" ${hook_script} )
# If the script did not execute properly, we stop here
if [ $? != 0 ]; then
@ -70,7 +79,18 @@ function create_debian_control_file {
package_arch=$(get_project_opt .arch)
echo "Architecture: ${package_arch:-all}" >> "${control_file}"
dependencies=$( get_project_opt ".dependencies | .[\"${DISTRIB}\"] | @sh" | sed "s/' '/, /g" | sed "s/'//g" )
dependencies=$(get_project_opt ".dependencies | .[\"${DISTRIB}\"]")
if [ ! -z "${dependencies}" ]; then
dependencies=""
for depKey in $(get_project_opt ".dependencies | .[\"${DISTRIB}\"] | keys | @sh"); do
depKey=$(echo ${depKey} | sed "s/^'\(.*\)'$/\1/");
depValue=$(get_project_opt ".dependencies | .[\"${DISTRIB}\"] | .[\"${depKey}\"]" | sed "s/^'\(.*\)'$/\1/")
dependencies="${depKey} ($depValue), ${dependencies}"
done
fi
dependencies=$(echo ${dependencies} | sed 's/,$//')
debug "Package dependencies: ${dependencies:-None}"
@ -119,7 +139,8 @@ function create_debian_changelog {
debian_dir="${1}"
changelog="${debian_dir}/changelog"
logs="$(get_project_opt '.changelog | map(.+"\n") | add')"
logs="$(get_project_opt '.changelog' | sed 's/null//')"
logs="$(echo ${logs:-[]} | jq 'map(.+"\n") | add' | sed 's/null/No information/g')"
package_name=$(get_project_opt .name)
package_version=$(get_project_opt .version)
maintainer=$(get_project_opt .maintainer)
@ -133,7 +154,7 @@ function create_debian_changelog {
echo >> "${changelog}"
echo "-- ${maintainer} $(date -R)" >> "${changelog}"
echo "-- ${maintainer:-Unknown} $(date -R)" >> "${changelog}"
}
@ -153,40 +174,43 @@ function create_debian_metadata {
function build_project {
project_name="$(get_project_opt '.name')"
info "Building project '${PROJECT_NAME}'..."
info "Building project '${project_name}'..."
build_dir="$(get_build_dir "${project_name}")"
build_dir="$(get_build_dir '${PROJECT_NAME}')"
debug "Build dir: ${build_dir}"
# We don't generate Debian metadata files if a debian directory is present
if [ ! -d "${SRC_DIR}/DEBIAN" ] && [ ! -d "${SRC_DIR}/debian" ]; then
if [ ! -d "${SRC_DIR}/debian" ]; then
info "No Debian directory detected in sources."
info "Generating Debian metadata files from manifest..."
info "Generating Debian metadata files from Tamarin manifest..."
create_debian_metadata "${build_dir}"
else
info "A Debian directory is already present in sources."
fi
exec_hook "preBuild" "${build_dir}"
exec_hook "prebuild" "${build_dir}"
# Ensure $DIST_DIR exists
mkdir -p "${DIST_DIR}"
cd "${build_dir}/.."
dpkg-deb --build "${project_name}" ${DIST_DIR}
info "Package created ! (${build_dir}/${project_name}.deb)"
cd ${SRC_DIR}
dpkg-buildpackage -us -uc
if [ $? != 0 ]; then
fatal "The build process has not completed successfuly !"
fi
cd ${SRC_DIR}
# Create new directory
mkdir -p "${DIST_DIR}/${PROJECT_NAME}/"
exec_hook "postBuild" "${build_dir}"
# Move generated files
mv ../*.deb "${DIST_DIR}/${PROJECT_NAME}/"
mv ../*.changes "${DIST_DIR}/${PROJECT_NAME}/"
mv ../*.dsc "${DIST_DIR}/${PROJECT_NAME}/"
mv ../*.tar.xz "${DIST_DIR}/${PROJECT_NAME}/"
exec_hook "postbuild" "${build_dir}"
}
@ -194,7 +218,7 @@ function main {
manifest_path=${SRC_DIR}/tamarin.json
if [ ! -f "${manifest_path}" ] && [ ! -d "${SRC_DIR}/debian" ] && [ ! -d "${SRC_DIR}/DEBIAN" ]; then
if [ ! -f "${manifest_path}" ] && [ ! -d "${SRC_DIR}/debian" ]; then
fatal "There is no 'tamarin.json' nor debian packaging files in the project directory !"
fi

View File

@ -0,0 +1 @@
#!/bin/bash