From afe7725c1bd489855571edd87a09dc3f87c12221 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 2 Jul 2015 17:01:26 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Mise=20en=20place=20hooks=20debian=20+=20d?= =?UTF-8?q?=C3=A9but=20script=20check-install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check-install.sh | 71 ++++++++++++++++++++++++++++++ lib/build.sh | 65 ++++++++++++++++++++++----- lib/install.sh | 3 ++ package-project.sh | 8 ++-- src-example/scripts/pre-install.sh | 3 ++ src-example/tamarin.json | 2 +- 6 files changed, 135 insertions(+), 17 deletions(-) create mode 100755 check-install.sh create mode 100644 lib/install.sh create mode 100644 src-example/scripts/pre-install.sh diff --git a/check-install.sh b/check-install.sh new file mode 100755 index 0000000..5132de5 --- /dev/null +++ b/check-install.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + + + +source ./lib/util.sh + +function show_usage { + echo + echo "Usage: $0 " + echo + echo "Paramètres: " + echo + echo " - Chemin vers le paquet Debian dont on doit vérifier l'installation" + echo " - Nom de l'image Docker à utiliser comme environnement pour tester l'installation" + echo +} + +function create_container { + + # Escape image name + escaped_basename=$(echo "$BASE_IMAGE" | sed 's/[^a-z0-9\-\_\.]/\_/gi') + # Generate container tag + container_tag="tamarin:${escaped_basename}_$(date +%s)" + # Create temporary dir for the Dockerfile + temp_dir="$(mktemp -d)" + + # Create Dockerfile + cat << EOF > "$temp_dir/Dockerfile" + FROM $BASE_IMAGE + + ENV DEBIAN_FRONTEND noninteractive + + RUN apt-get update + + ADD ./lib /root/.tamarin + RUN chmod +x /root/.tamarin/install.sh + + VOLUME /deb + + ENTRYPOINT ["/root/.tamarin/install.sh"] + +EOF + + # Build image + tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 1>&2 + + # Delete temporary folder + rm -rf "$temp_dir" + + # Return newly created container's tag + echo $container_tag + +} + +function main { + container_tag=$(create_container) + docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$DEB_DIR:/deb" "$container_tag" "/deb/$DEB_NAME" +} + +# Test for arguments +if [ -z "$1" ] || [ -z "$2" ]; then + show_usage + exit 1 +fi + +DEB_PATH=$(readlink -f "$1") +DEB_NAME=$(basename "$DEB_PATH") +DEB_DIR=$(dirname "$DEB_PATH") +BASE_IMAGE="$2" + +main diff --git a/lib/build.sh b/lib/build.sh index c8a327a..dd64277 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -49,12 +49,11 @@ function exec_hook { } -function create_debian_metadata { +function create_debian_control_file { - build_dir="${1}" - mkdir -p "${build_dir}/DEBIAN" + debian_dir="${1}" - control_file="${build_dir}/DEBIAN/control" + control_file="${debian_dir}/control" touch "${control_file}" package_name=$(get_project_opt .name) @@ -69,8 +68,8 @@ function create_debian_metadata { package_priority=$(get_project_opt .priority) echo "Priority: ${package_priority:-optional}" >> "${control_file}" - package_arch=$(get_project_opt .priority) - echo "Architecture: ${package_arch:-any}" >> "${control_file}" + package_arch=$(get_project_opt .package_arch) + echo "Architecture: ${package_arch:-all}" >> "${control_file}" dependencies=$( get_project_opt ".dependencies | .[\"${DISTRIB}\"] | @sh" | sed "s/' '/, /g" | sed "s/'//g" ) @@ -86,6 +85,49 @@ function create_debian_metadata { } +function create_debian_hooks { + + debian_dir="${1}" + + pre_install="$(get_project_opt .hooks.preInstall)" + if [ ! -z "${pre_install}" ]; then + cp "${SRC_DIR}/${pre_install}" "${debian_dir}/preinst" + chmod +x "${debian_dir}/preinst" + fi + + post_install="$(get_project_opt .hooks.postInstall)" + if [ ! -z "${post_install}" ]; then + cp "${SRC_DIR}/${post_install}" "${debian_dir}/postinst" + chmod +x "${debian_dir}/postinst" + fi + + pre_remove="$(get_project_opt .hooks.preRemove)" + if [ ! -z "${pre_remove}" ]; then + cp "${SRC_DIR}/${pre_remove}" "${debian_dir}/prerm" + chmod +x "${debian_dir}/prerm" + fi + + post_remove="$(get_project_opt .hooks.postRemove)" + if [ ! -z "${post_remove}" ]; then + cp "${SRC_DIR}/${post_remove}" "${debian_dir}/postrm" + chmod +x "${debian_dir}/postrm" + fi + +} + +function create_debian_metadata { + + build_dir="${1}" + debian_dir="${build_dir}/DEBIAN" + + # Ensure debian dir exists + mkdir -p "${debian_dir}" + + create_debian_control_file "${debian_dir}" + create_debian_hooks "${debian_dir}" + +} + function build_project { project_name="$(get_project_opt '.name')" @@ -107,8 +149,11 @@ function build_project { exec_hook "preBuild" "${build_dir}" + # Ensure $DIST_DIR exists + mkdir -p "${DIST_DIR}" + cd "${build_dir}/.." - dpkg-deb --build "${project_name}" + dpkg-deb --build "${project_name}" ${DIST_DIR} info "Package created ! (${build_dir}/${project_name}.deb)" @@ -117,14 +162,10 @@ function build_project { exit 1 fi - cd / + cd ${SRC_DIR} exec_hook "postBuild" "${build_dir}" - # Copie du paquet nouvellement créé dans le répertoire "dist" - mkdir -p "${DIST_DIR}" - cp "${build_dir}/../${project_name}.deb" "${DIST_DIR}/${project_name}.deb" - } function main { diff --git a/lib/install.sh b/lib/install.sh new file mode 100644 index 0000000..3bd48a8 --- /dev/null +++ b/lib/install.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +dpkg --install "$1" || apt-get install -f diff --git a/package-project.sh b/package-project.sh index 042e865..450d7b3 100755 --- a/package-project.sh +++ b/package-project.sh @@ -22,7 +22,7 @@ function create_container { # Escape image name escaped_basename=$(echo "$BASE_IMAGE" | sed 's/[^a-z0-9\-\_\.]/\_/gi') # Generate container tag - container_tag="bricklayer:${escaped_basename}_$(date +%s)" + container_tag="tamarin:${escaped_basename}_$(date +%s)" # Create temporary dir for the Dockerfile temp_dir="$(mktemp -d)" @@ -38,13 +38,13 @@ function create_container { RUN apt-get update &&\ apt-get install jq - ADD ./lib /bricklayer - RUN chmod +x /bricklayer/build.sh + ADD ./lib /root/.tamarin + RUN chmod +x /root/.tamarin/build.sh VOLUME /src VOLUME /dist - CMD /bricklayer/build.sh + CMD /root/.tamarin/build.sh EOF # Build image diff --git a/src-example/scripts/pre-install.sh b/src-example/scripts/pre-install.sh new file mode 100644 index 0000000..b7007f7 --- /dev/null +++ b/src-example/scripts/pre-install.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "Test pre-install" diff --git a/src-example/tamarin.json b/src-example/tamarin.json index 74245fa..565ecf9 100644 --- a/src-example/tamarin.json +++ b/src-example/tamarin.json @@ -9,7 +9,7 @@ "hooks": { "preBuild": "./scripts/pre-build.sh", "postBuild": "./scripts/post-build.sh", - "preInstall": "", + "preInstall": "./scripts/pre-install.sh", "preRemove": "", "postInstall": "", "postRemove": "" From ab10d602158d220c6b6d9419a4a52d0485a529b6 Mon Sep 17 00:00:00 2001 From: William Petit Date: Sat, 4 Jul 2015 13:28:43 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Ajout=20script=20de=20v=C3=A9rification=20d?= =?UTF-8?q?'installation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check-install.sh | 19 ++++++++++++++++--- lib/build.sh | 8 +++----- lib/install.sh | 11 ++++++++++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/check-install.sh b/check-install.sh index 5132de5..2faa228 100755 --- a/check-install.sh +++ b/check-install.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash - - source ./lib/util.sh function show_usage { @@ -24,13 +22,16 @@ function create_container { # Create temporary dir for the Dockerfile temp_dir="$(mktemp -d)" + # Link lib folder + ln -s $(readlink -f ./lib) "$temp_dir/lib" + # Create Dockerfile cat << EOF > "$temp_dir/Dockerfile" FROM $BASE_IMAGE ENV DEBIAN_FRONTEND noninteractive - RUN apt-get update + RUN apt-get update && apt-get install --yes gdebi-core ADD ./lib /root/.tamarin RUN chmod +x /root/.tamarin/install.sh @@ -53,8 +54,20 @@ EOF } function main { + + # Create container image container_tag=$(create_container) + + # Run container and install package docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$DEB_DIR:/deb" "$container_tag" "/deb/$DEB_NAME" + + # Check for return + if [ $? != 0 ]; then + fatal "Installation did not complete correctly !" + fi + + info "Installation complete." + } # Test for arguments diff --git a/lib/build.sh b/lib/build.sh index dd64277..8c08aba 100755 --- a/lib/build.sh +++ b/lib/build.sh @@ -43,8 +43,7 @@ function exec_hook { # If the script did not execute properly, we stop here if [ $? != 0 ]; then - error "The '${hook_name}' hook script did not finished properly !" - exit 1 + fatal "The '${hook_name}' hook script did not finished properly !" fi } @@ -68,7 +67,7 @@ function create_debian_control_file { package_priority=$(get_project_opt .priority) echo "Priority: ${package_priority:-optional}" >> "${control_file}" - package_arch=$(get_project_opt .package_arch) + 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" ) @@ -158,8 +157,7 @@ function build_project { info "Package created ! (${build_dir}/${project_name}.deb)" if [ $? != 0 ]; then - error "The build process has not completed successfuly !" - exit 1 + fatal "The build process has not completed successfuly !" fi cd ${SRC_DIR} diff --git a/lib/install.sh b/lib/install.sh index 3bd48a8..775793c 100644 --- a/lib/install.sh +++ b/lib/install.sh @@ -1,3 +1,12 @@ #!/usr/bin/env bash -dpkg --install "$1" || apt-get install -f +set -e + +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "${DIR}/util.sh" + +info "Updating packages definition..." +apt-get update + +info "Installing package $1..." +gdebi --n "$1" From 735575a961932ad4b54421a7ef05195f9f9fab16 Mon Sep 17 00:00:00 2001 From: William Petit Date: Sat, 4 Jul 2015 18:42:08 +0200 Subject: [PATCH 3/3] Fix include bug + add lintian package validation in check-install script --- check-install.sh | 7 ++++--- lib/install.sh | 3 +++ package-project.sh | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/check-install.sh b/check-install.sh index 2faa228..4a84594 100755 --- a/check-install.sh +++ b/check-install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -source ./lib/util.sh +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$DIR/lib/util.sh" function show_usage { echo @@ -23,7 +24,7 @@ function create_container { temp_dir="$(mktemp -d)" # Link lib folder - ln -s $(readlink -f ./lib) "$temp_dir/lib" + ln -s $(readlink -f "$DIR/lib") "$temp_dir/lib" # Create Dockerfile cat << EOF > "$temp_dir/Dockerfile" @@ -31,7 +32,7 @@ function create_container { ENV DEBIAN_FRONTEND noninteractive - RUN apt-get update && apt-get install --yes gdebi-core + RUN apt-get update && apt-get install --yes gdebi-core lintian ADD ./lib /root/.tamarin RUN chmod +x /root/.tamarin/install.sh diff --git a/lib/install.sh b/lib/install.sh index 775793c..e2724d2 100644 --- a/lib/install.sh +++ b/lib/install.sh @@ -5,6 +5,9 @@ set -e DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) source "${DIR}/util.sh" +info "Analysing package $1..." +lintian "$1" + info "Updating packages definition..." apt-get update diff --git a/package-project.sh b/package-project.sh index 450d7b3..d68f264 100755 --- a/package-project.sh +++ b/package-project.sh @@ -2,7 +2,8 @@ set -e -source ./lib/util.sh +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source "$DIR/lib/util.sh" function show_usage { echo @@ -27,7 +28,7 @@ function create_container { temp_dir="$(mktemp -d)" # Link lib folder - ln -s $(readlink -f ./lib) "$temp_dir/lib" + ln -s $(readlink -f "$DIR/lib") "$temp_dir/lib" # Create Dockerfile cat << EOF > "$temp_dir/Dockerfile"