2023-06-22 16:21:16 +02:00
|
|
|
#!/bin/bash -ex
|
2022-10-01 22:33:11 +02:00
|
|
|
|
|
|
|
IMAGE_NAME=$1
|
|
|
|
|
2023-01-23 20:23:32 +01:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
ONLY_IF_DATASET_MODIF=false
|
|
|
|
else
|
|
|
|
ONLY_IF_DATASET_MODIF=true
|
|
|
|
fi
|
|
|
|
|
2022-10-01 22:33:11 +02:00
|
|
|
if [ -z "$IMAGE_NAME" ]; then
|
|
|
|
echo "PAS DE NOM DE MODULE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# root dir configuration
|
|
|
|
RISOTTO_DIR="/var/lib/risotto"
|
|
|
|
RISOTTO_IMAGE_DIR="$RISOTTO_DIR/images"
|
|
|
|
# image configuration
|
|
|
|
IMAGE_BASE_RISOTTO_BASE_DIR="$RISOTTO_IMAGE_DIR/image_bases"
|
2022-12-21 16:35:58 +01:00
|
|
|
IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP="$RISOTTO_IMAGE_DIR/tmp/$IMAGE_NAME"
|
2022-10-01 22:33:11 +02:00
|
|
|
IMAGE_NAME_RISOTTO_IMAGE_DIR="$RISOTTO_IMAGE_DIR/$IMAGE_NAME"
|
2023-01-23 20:23:32 +01:00
|
|
|
IMAGE_DIR_RECIPIENT_IMAGE="$RISOTTO_DIR/images_files/$IMAGE_NAME"
|
2022-10-01 22:33:11 +02:00
|
|
|
|
|
|
|
|
2022-12-21 16:35:58 +01:00
|
|
|
rm -f /var/log/risotto/build_image.log
|
2023-01-23 20:23:32 +01:00
|
|
|
mkdir -p "$RISOTTO_IMAGE_DIR" "$RISOTTO_IMAGE_DIR/tmp/"
|
2022-10-01 22:33:11 +02:00
|
|
|
PKG=""
|
|
|
|
BASE_DIR=""
|
|
|
|
for script in $(ls "$IMAGE_DIR_RECIPIENT_IMAGE"/preinstall/*.sh 2> /dev/null); do
|
|
|
|
. "$script"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$OS_NAME" ]; then
|
|
|
|
echo "NO OS NAME DEFINED"
|
2022-12-21 16:35:58 +01:00
|
|
|
exit 1
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
if [ -z "$RELEASEVER" ]; then
|
|
|
|
echo "NO RELEASEVER DEFINED"
|
2022-12-21 16:35:58 +01:00
|
|
|
exit 1
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
if [ -z "$INSTALL_TOOL" ]; then
|
|
|
|
echo "NO INSTALL TOOL DEFINED"
|
2022-12-21 16:35:58 +01:00
|
|
|
exit 1
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
BASE_NAME="$OS_NAME-$RELEASEVER"
|
|
|
|
BASE_DIR="$IMAGE_BASE_RISOTTO_BASE_DIR/$BASE_NAME"
|
2022-12-21 16:35:58 +01:00
|
|
|
TMP_BASE_DIR="$IMAGE_BASE_RISOTTO_BASE_DIR/tmp/$BASE_NAME"
|
2022-10-01 22:33:11 +02:00
|
|
|
BASE_PKGS_FILE="$IMAGE_BASE_RISOTTO_BASE_DIR-$BASE_NAME.pkgs"
|
|
|
|
BASE_LOCK="$IMAGE_BASE_RISOTTO_BASE_DIR-$BASE_NAME.build"
|
|
|
|
|
|
|
|
|
|
|
|
function dnf_opt_base() {
|
|
|
|
INSTALL_DIR=$1
|
2022-12-21 16:35:58 +01:00
|
|
|
echo "--setopt=install_weak_deps=False --setopt=fastestmirror=True --nodocs --noplugins --installroot=$INSTALL_DIR --releasever $RELEASEVER"
|
2022-10-01 22:33:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dnf_opt() {
|
|
|
|
INSTALL_DIR=$1
|
|
|
|
INSTALL_PKG=$2
|
2022-12-21 16:35:58 +01:00
|
|
|
OPT=$(dnf_opt_base "$INSTALL_DIR")
|
2022-10-01 22:33:11 +02:00
|
|
|
echo "$OPT install $INSTALL_PKG"
|
|
|
|
}
|
|
|
|
function new_package_base() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
2022-12-21 16:35:58 +01:00
|
|
|
OPT=$(dnf_opt "$TMP_BASE_DIR" "$BASE_PKG")
|
2022-10-01 22:33:11 +02:00
|
|
|
dnf --assumeno $OPT | grep ^" " > "$BASE_PKGS_FILE".new
|
|
|
|
else
|
2022-12-21 16:35:58 +01:00
|
|
|
debootstrap --include="$BASE_PKG" --variant=minbase "$RELEASEVER" "$TMP_BASE_DIR" >> /var/log/risotto/build_image.log
|
|
|
|
chroot "$TMP_BASE_DIR" dpkg-query -f '${binary:Package} ${source:Version}\n' -W > "$BASE_PKGS_FILE".new
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
function install_base() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
2022-12-21 16:35:58 +01:00
|
|
|
OPT=$(dnf_opt "$TMP_BASE_DIR" "$BASE_PKG")
|
2022-10-01 22:33:11 +02:00
|
|
|
dnf --assumeyes $OPT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function new_package() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
2022-12-21 16:35:58 +01:00
|
|
|
OPT=$(dnf_opt_base "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP")
|
2023-02-27 14:03:56 +01:00
|
|
|
set +e
|
2022-12-21 16:35:58 +01:00
|
|
|
dnf --assumeno $OPT update >> /var/log/risotto/build_image.log
|
2023-02-27 14:03:56 +01:00
|
|
|
set -e
|
2022-12-21 16:35:58 +01:00
|
|
|
OPT=$(dnf_opt "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" "$PKG")
|
2022-10-01 22:33:11 +02:00
|
|
|
dnf --assumeno $OPT | grep ^" " > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new
|
|
|
|
else
|
2022-12-21 16:35:58 +01:00
|
|
|
chroot "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" apt update >> /var/log/risotto/build_image.log 2>&1
|
|
|
|
chroot "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" apt install --no-install-recommends --yes $PKG -s 2>/dev/null|grep ^"Inst " > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
function install_pkg() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
2022-12-21 16:35:58 +01:00
|
|
|
OPT=$(dnf_opt "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" "$PKG")
|
2022-10-01 22:33:11 +02:00
|
|
|
dnf --assumeyes $OPT
|
|
|
|
else
|
2023-02-27 14:03:56 +01:00
|
|
|
if [ "$ONLY_IF_DATASET_MODIF" = true ]; then
|
|
|
|
chroot "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" apt update
|
|
|
|
fi
|
2022-12-21 16:35:58 +01:00
|
|
|
chroot "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" bash -c "export DEBIAN_FRONTEND=noninteractive; apt install --no-install-recommends --yes $PKG"
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-12-21 16:35:58 +01:00
|
|
|
if [ ! -f "$BASE_LOCK" ] || [ ! -d "$BASE_DIR" ]; then
|
2022-10-01 22:33:11 +02:00
|
|
|
echo " - reinstallation de l'image de base"
|
|
|
|
new_package_base
|
2023-01-23 20:23:32 +01:00
|
|
|
diff -u "$BASE_PKGS_FILE" "$BASE_PKGS_FILE".new &> /dev/null && NEW_BASE=false || NEW_BASE=true
|
2022-12-21 16:35:58 +01:00
|
|
|
if [ ! -d "$BASE_DIR" ] || [ "$NEW_BASE" = true ]; then
|
2022-10-01 22:33:11 +02:00
|
|
|
mkdir -p "$IMAGE_BASE_RISOTTO_BASE_DIR"
|
2022-12-21 16:35:58 +01:00
|
|
|
rm -rf "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP"
|
2022-10-01 22:33:11 +02:00
|
|
|
install_base
|
|
|
|
if [ -f "$BASE_PKGS_FILE" ]; then
|
|
|
|
mv "$BASE_PKGS_FILE" "$BASE_PKGS_FILE".old
|
|
|
|
fi
|
|
|
|
mv "$BASE_PKGS_FILE".new "$BASE_PKGS_FILE"
|
2022-12-21 16:35:58 +01:00
|
|
|
rm -rf "$BASE_DIR"
|
|
|
|
mv "$TMP_BASE_DIR" "$BASE_DIR"
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
touch "$BASE_LOCK"
|
|
|
|
fi
|
|
|
|
|
2022-12-21 16:35:58 +01:00
|
|
|
rm -rf "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP"
|
|
|
|
cp --reflink=auto -a "$BASE_DIR/" "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP"
|
2022-10-01 22:33:11 +02:00
|
|
|
if [ -n "$COPR" ]; then
|
|
|
|
#FIXME signature...
|
|
|
|
mkdir -p "$REPO_DIR"
|
|
|
|
cd "$REPO_DIR"
|
|
|
|
wget -q "$COPR"
|
|
|
|
cd - > /dev/null
|
|
|
|
fi
|
|
|
|
if [ "$FUSION" = true ]; then
|
2022-12-21 16:35:58 +01:00
|
|
|
dnf -y install "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$RELEASEVER.noarch.rpm" --installroot="$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" >> /var/log/risotto/build_image.log
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs ] && [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs ]; then
|
|
|
|
echo " - différence(s) avec les paquets de base"
|
|
|
|
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs "$BASE_PKGS_FILE" && INSTALL=false || INSTALL=true
|
2022-12-21 16:35:58 +01:00
|
|
|
[ ! -d "$IMAGE_NAME_RISOTTO_IMAGE_DIR" ] && INSTALL=true
|
2022-10-01 22:33:11 +02:00
|
|
|
else
|
|
|
|
INSTALL=true
|
|
|
|
fi
|
2022-12-21 16:35:58 +01:00
|
|
|
|
2023-01-23 20:23:32 +01:00
|
|
|
if [ "$ONLY_IF_DATASET_MODIF" = false ] || [ ! -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs ]; then
|
|
|
|
new_package
|
|
|
|
else
|
|
|
|
cp --reflink=auto "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new
|
|
|
|
fi
|
2022-10-01 22:33:11 +02:00
|
|
|
if [ "$INSTALL" = false ]; then
|
|
|
|
echo " - différence(s) avec les paquets de l'image"
|
|
|
|
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new && INSTALL=false || INSTALL=true
|
|
|
|
fi
|
|
|
|
find "$IMAGE_DIR_RECIPIENT_IMAGE" -type f -exec md5sum '{}' \; > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum.new
|
|
|
|
if [ "$INSTALL" = false ]; then
|
2023-01-23 20:23:32 +01:00
|
|
|
echo " - différence(s) du dataset"
|
2022-10-01 22:33:11 +02:00
|
|
|
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum.new && INSTALL=false || INSTALL=true
|
|
|
|
fi
|
|
|
|
if [ "$INSTALL" = true ]; then
|
|
|
|
echo " - installation"
|
2022-12-21 16:35:58 +01:00
|
|
|
if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".version ]; then
|
|
|
|
VERSION=$(cat "$IMAGE_NAME_RISOTTO_IMAGE_DIR".version)
|
2022-10-01 22:33:11 +02:00
|
|
|
else
|
|
|
|
VERSION=0
|
|
|
|
fi
|
2023-01-23 20:23:32 +01:00
|
|
|
if [ -d "$IMAGE_NAME_RISOTTO_IMAGE_DIR" ]; then
|
|
|
|
cd "$IMAGE_NAME_RISOTTO_IMAGE_DIR"
|
|
|
|
make_changelog "$IMAGE_NAME" "$VERSION" "$OS_NAME" "$RELEASEVER" > "$IMAGE_NAME_RISOTTO_IMAGE_DIR"_"$RELEASEVER"_"$VERSION"_changelog.md
|
|
|
|
cd - > /dev/null
|
|
|
|
fi
|
2022-10-01 22:33:11 +02:00
|
|
|
install_pkg
|
|
|
|
sleep 2
|
|
|
|
|
|
|
|
for script in $(ls $IMAGE_DIR_RECIPIENT_IMAGE/postinstall/*.sh 2> /dev/null); do
|
|
|
|
. "$script"
|
|
|
|
done
|
|
|
|
|
2022-12-21 16:35:58 +01:00
|
|
|
ROOT=$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP make_volatile /etc
|
2022-10-01 22:33:11 +02:00
|
|
|
if [ ! "$?" = 0 ]; then
|
|
|
|
echo "make_volatile failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-12-21 16:35:58 +01:00
|
|
|
rm -rf "$IMAGE_NAME_RISOTTO_IMAGE_DIR"
|
|
|
|
mv "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP" "$IMAGE_NAME_RISOTTO_IMAGE_DIR"
|
|
|
|
cp --reflink=auto -f "$BASE_PKGS_FILE" "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs
|
2022-10-01 22:33:11 +02:00
|
|
|
mv -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs
|
|
|
|
mv -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum.new "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum
|
|
|
|
VERSION=$((VERSION + 1))
|
2022-12-21 16:35:58 +01:00
|
|
|
echo "$VERSION" > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".version
|
2022-10-01 22:33:11 +02:00
|
|
|
fi
|
2022-12-21 16:35:58 +01:00
|
|
|
rm -rf "$IMAGE_NAME_RISOTTO_IMAGE_DIR_TMP"
|
2022-10-01 22:33:11 +02:00
|
|
|
|
|
|
|
echo " => OK"
|
|
|
|
exit 0
|