Tamarin/check-install

83 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "$DIR/lib/util.sh"
function show_usage {
echo
2015-08-05 15:49:04 +02:00
echo "Usage: $0 deb_file [image]"
echo
echo "Paramètres: "
echo
2015-08-05 15:49:04 +02:00
echo " - deb_file Chemin vers le paquet Debian dont on doit vérifier l'installation"
echo " - image Optionnel - Nom de l'image Docker à utiliser comme environnement pour tester l'installation. Défaut: debian:jessie"
echo
}
function create_container {
# Escape image name
2015-08-05 15:49:04 +02:00
local 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
2015-08-05 15:49:04 +02:00
local temp_dir="$(mktemp -d)"
# Link lib folder
ln -s $(readlink -f "$DIR/lib") "$temp_dir/lib"
# Create Dockerfile
cat << EOF > "$temp_dir/Dockerfile"
FROM $BASE_IMAGE
ENV DEBIAN_FRONTEND noninteractive
2015-07-04 18:51:57 +02:00
RUN apt-get update && apt-get install --yes gdebi-core
ADD ./lib /root/.tamarin
RUN chmod +x /root/.tamarin/install.sh
VOLUME /deb
ENTRYPOINT ["/root/.tamarin/install.sh"]
EOF
# Build image
2015-08-05 15:49:04 +02:00
tar -C "$temp_dir" -czh . | docker build -t "$container_tag" - 2> >(error) 1> >(info)
# Delete temporary folder
rm -rf "$temp_dir"
}
function main {
# Create container image
2015-08-05 15:49:04 +02:00
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
2015-08-05 15:49:04 +02:00
if [ -z "$1" ]; then
show_usage
exit 1
fi
DEB_PATH=$(readlink -f "$1")
DEB_NAME=$(basename "$DEB_PATH")
DEB_DIR=$(dirname "$DEB_PATH")
2015-08-05 15:49:04 +02:00
BASE_IMAGE="${2:-debian:jessie}"
main