2015-07-02 17:01:26 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2015-07-04 18:42:08 +02:00
|
|
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
source "$DIR/lib/util.sh"
|
2015-07-02 17:01:26 +02:00
|
|
|
|
|
|
|
function show_usage {
|
|
|
|
echo
|
2015-08-05 15:49:04 +02:00
|
|
|
echo "Usage: $0 deb_file [image]"
|
2015-07-02 17:01:26 +02:00
|
|
|
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"
|
2015-07-02 17:01:26 +02:00
|
|
|
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')
|
2015-07-02 17:01:26 +02:00
|
|
|
# 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)"
|
2015-07-02 17:01:26 +02:00
|
|
|
|
2015-07-04 13:28:43 +02:00
|
|
|
# Link lib folder
|
2015-07-04 18:42:08 +02:00
|
|
|
ln -s $(readlink -f "$DIR/lib") "$temp_dir/lib"
|
2015-07-04 13:28:43 +02:00
|
|
|
|
2015-07-02 17:01:26 +02:00
|
|
|
# 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
|
2015-07-02 17:01:26 +02:00
|
|
|
|
|
|
|
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)
|
2015-07-02 17:01:26 +02:00
|
|
|
|
|
|
|
# Delete temporary folder
|
|
|
|
rm -rf "$temp_dir"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function main {
|
2015-07-04 13:28:43 +02:00
|
|
|
|
|
|
|
# Create container image
|
2015-08-05 15:49:04 +02:00
|
|
|
create_container
|
2015-07-04 13:28:43 +02:00
|
|
|
|
|
|
|
# Run container and install package
|
2015-07-02 17:01:26 +02:00
|
|
|
docker run -e "DISTRIB=$BASE_IMAGE" --rm -v="$DEB_DIR:/deb" "$container_tag" "/deb/$DEB_NAME"
|
2015-07-04 13:28:43 +02:00
|
|
|
|
|
|
|
# Check for return
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
fatal "Installation did not complete correctly !"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Installation complete."
|
|
|
|
|
2015-07-02 17:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Test for arguments
|
2015-08-05 15:49:04 +02:00
|
|
|
if [ -z "$1" ]; then
|
2015-07-02 17:01:26 +02:00
|
|
|
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}"
|
2015-07-02 17:01:26 +02:00
|
|
|
|
|
|
|
main
|