2022-05-04 10:29:03 +02:00
|
|
|
#!/bin/bash -e
|
2022-03-08 19:42:28 +01:00
|
|
|
|
|
|
|
HOST_NAME=$1
|
|
|
|
IMAGE_NAME=$2
|
|
|
|
|
|
|
|
if [ -z "$IMAGE_NAME" ]; then
|
|
|
|
echo "PAS DE NOM DE MODULE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
. config.sh
|
|
|
|
|
|
|
|
rm -rf "$IMAGE_NAME_RISOTTO_IMAGE_DIR" tmp
|
|
|
|
mkdir -p "$RISOTTO_IMAGE_DIR"
|
|
|
|
PKG=""
|
|
|
|
BASE_DIR=""
|
2022-05-04 10:29:03 +02:00
|
|
|
for script in $(ls $IMAGE_NAME/manual/preinstall/*.sh 2> /dev/null); do
|
2022-03-08 19:42:28 +01:00
|
|
|
. "$script"
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$OS_NAME" ]; then
|
|
|
|
echo "NO OS NAME DEFINED"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ -z "$RELEASEVER" ]; then
|
|
|
|
echo "NO RELEASEVER DEFINED"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ -z "$INSTALL_TOOL" ]; then
|
|
|
|
echo "NO INSTALL TOOL DEFINED"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
BASE_NAME="$OS_NAME-$RELEASEVER"
|
|
|
|
BASE_DIR="$IMAGE_BASE_RISOTTO_BASE_DIR/$BASE_NAME"
|
|
|
|
BASE_TAR="$IMAGE_BASE_RISOTTO_BASE_DIR-$BASE_NAME".tar
|
|
|
|
BASE_PKGS_FILE="$IMAGE_BASE_RISOTTO_BASE_DIR-$BASE_NAME.pkgs"
|
|
|
|
BASE_LOCK="$IMAGE_BASE_RISOTTO_BASE_DIR-$BASE_NAME.build"
|
|
|
|
|
|
|
|
function dnf_opt() {
|
|
|
|
INSTALL_DIR=$1
|
|
|
|
INSTALL_PKG=$2
|
|
|
|
echo "--setopt=install_weak_deps=False --nodocs --noplugins --installroot=$INSTALL_DIR --releasever $RELEASEVER install $INSTALL_PKG"
|
|
|
|
}
|
|
|
|
function new_package_base() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
|
|
|
OPT=$(dnf_opt "$BASE_DIR" "$BASE_PKG")
|
|
|
|
dnf --assumeno $OPT | grep ^" " > "$BASE_PKGS_FILE".new
|
|
|
|
else
|
2022-05-04 10:29:03 +02:00
|
|
|
debootstrap --include="$BASE_PKG" --variant=minbase "$RELEASEVER" "$BASE_DIR" > /dev/null
|
2022-03-08 19:42:28 +01:00
|
|
|
chroot "$BASE_DIR" dpkg-query -f '${binary:Package} ${source:Version}\n' -W > "$BASE_PKGS_FILE".new
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function install_base() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
|
|
|
OPT=$(dnf_opt "$BASE_DIR" "$BASE_PKG")
|
|
|
|
dnf --assumeyes $OPT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function new_package() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
|
|
|
OPT=$(dnf_opt "$IMAGE_NAME_RISOTTO_IMAGE_DIR" "$PKG")
|
|
|
|
dnf --assumeno $OPT | grep ^" " > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new
|
|
|
|
else
|
|
|
|
chroot "$IMAGE_NAME_RISOTTO_IMAGE_DIR" apt install --no-install-recommends --yes $PKG -s 2>/dev/null|grep ^"Inst " > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function install_pkg() {
|
|
|
|
if [ "$INSTALL_TOOL" = "dnf" ]; then
|
|
|
|
OPT=$(dnf_opt "$IMAGE_NAME_RISOTTO_IMAGE_DIR" "$PKG")
|
|
|
|
dnf --assumeyes $OPT
|
|
|
|
else
|
|
|
|
chroot "$IMAGE_NAME_RISOTTO_IMAGE_DIR" apt install --no-install-recommends --yes $PKG
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [ ! -f "$BASE_LOCK" ]; then
|
2022-05-04 10:29:03 +02:00
|
|
|
echo " - reinstallation de l'image de base"
|
2022-03-08 19:42:28 +01:00
|
|
|
rm -rf "$BASE_DIR"
|
|
|
|
new_package_base
|
|
|
|
diff -u "$BASE_PKGS_FILE" "$BASE_PKGS_FILE".new && NEW_BASE=false || NEW_BASE=true
|
|
|
|
if [ ! -f "$BASE_TAR" ] || [ "$NEW_BASE" = true ]; then
|
|
|
|
mkdir -p "$IMAGE_BASE_RISOTTO_BASE_DIR"
|
|
|
|
install_base
|
|
|
|
cd "$IMAGE_BASE_RISOTTO_BASE_DIR"
|
|
|
|
tar cf "$BASE_TAR" "$BASE_NAME"
|
2022-05-04 10:29:03 +02:00
|
|
|
cd - > /dev/null
|
2022-03-08 19:42:28 +01:00
|
|
|
if [ -f "$BASE_PKGS_FILE" ]; then
|
|
|
|
mv "$BASE_PKGS_FILE" "$BASE_PKGS_FILE".old
|
|
|
|
fi
|
|
|
|
mv "$BASE_PKGS_FILE".new "$BASE_PKGS_FILE"
|
|
|
|
rm -rf "$IMAGE_BASE_RISOTTO_BASE_DIR"
|
|
|
|
fi
|
|
|
|
rm -rf "$BASE_DIR"
|
|
|
|
touch "$BASE_LOCK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
tar xf "$BASE_TAR"
|
|
|
|
mv "$BASE_NAME" "$IMAGE_NAME_RISOTTO_IMAGE_DIR"
|
|
|
|
if [ -n "$COPR" ]; then
|
|
|
|
#FIXME signature...
|
|
|
|
mkdir -p "$REPO_DIR"
|
|
|
|
cd "$REPO_DIR"
|
2022-05-04 10:29:03 +02:00
|
|
|
wget -q "$COPR"
|
|
|
|
cd - > /dev/null
|
2022-03-08 19:42:28 +01:00
|
|
|
fi
|
2022-04-08 18:52:43 +02:00
|
|
|
if [ "$FUSION" = true ]; then
|
|
|
|
dnf -y install "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$RELEASEVER.noarch.rpm" --installroot="$IMAGE_NAME_RISOTTO_IMAGE_DIR"
|
|
|
|
fi
|
2022-03-08 19:42:28 +01:00
|
|
|
|
|
|
|
# FIXME verifier s'il y a des modifs sur pre/post
|
|
|
|
if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs ] && [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs ]; then
|
2022-05-04 10:29:03 +02:00
|
|
|
echo " - différence(s) avec les paquets de base"
|
2022-03-08 19:42:28 +01:00
|
|
|
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs "$BASE_PKGS_FILE" && NEW_BASE=false || NEW_BASE=true
|
|
|
|
else
|
|
|
|
NEW_BASE=true
|
|
|
|
fi
|
|
|
|
new_package
|
|
|
|
if [ "$NEW_BASE" = false ]; then
|
2022-05-04 10:29:03 +02:00
|
|
|
echo " - différence(s) avec les paquets de l'image"
|
2022-03-08 19:42:28 +01:00
|
|
|
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new && INSTALL=false || INSTALL=true
|
|
|
|
else
|
|
|
|
INSTALL=true
|
|
|
|
fi
|
2022-05-04 10:29:03 +02:00
|
|
|
find $IMAGE_NAME/manual -type f -exec md5sum '{}' \; > "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum.new
|
|
|
|
if [ "$NEW_BASE" = false ]; then
|
|
|
|
diff -u "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum.new && INSTALL=false || INSTALL=true
|
|
|
|
fi
|
2022-03-08 19:42:28 +01:00
|
|
|
if [ "$INSTALL" = true ]; then
|
2022-05-04 10:29:03 +02:00
|
|
|
echo " - installation"
|
2022-03-08 19:42:28 +01:00
|
|
|
if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR"_"$RELEASEVER".version ]; then
|
|
|
|
VERSION=$(cat "$IMAGE_NAME_RISOTTO_IMAGE_DIR"_"$RELEASEVER".version)
|
|
|
|
else
|
|
|
|
VERSION=0
|
|
|
|
fi
|
|
|
|
mkdir tmp
|
2022-04-08 18:52:43 +02:00
|
|
|
ORI_DIR=$PWD
|
2022-03-08 19:42:28 +01:00
|
|
|
cd tmp
|
|
|
|
if [ ! "$VERSION" = 0 ]; then
|
|
|
|
tar xf "$IMAGE_NAME_RISOTTO_IMAGE_NAME"
|
2022-04-08 18:52:43 +02:00
|
|
|
if [ "$INSTALL_TOOL" = "apt" ]; then
|
|
|
|
chown _apt "$IMAGE_NAME"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
mkdir "$IMAGE_NAME"
|
2022-03-08 19:42:28 +01:00
|
|
|
fi
|
2022-04-08 18:52:43 +02:00
|
|
|
cd "$IMAGE_NAME"
|
|
|
|
../../make_changelog "$IMAGE_NAME" "$VERSION" "$OS_NAME" "$RELEASEVER" > "$IMAGE_NAME_RISOTTO_IMAGE_DIR"_"$RELEASEVER"_"$VERSION"_changelog.md
|
|
|
|
cd $ORI_DIR
|
2022-03-08 19:42:28 +01:00
|
|
|
rm -rf tmp
|
|
|
|
install_pkg
|
|
|
|
sleep 2
|
|
|
|
|
2022-05-04 10:29:03 +02:00
|
|
|
for script in $(ls $IMAGE_NAME/manual/postinstall/*.sh 2> /dev/null); do
|
2022-03-08 19:42:28 +01:00
|
|
|
. "$script"
|
|
|
|
done
|
|
|
|
|
|
|
|
CONTAINER=$IMAGE_NAME ./make_volatile /etc
|
|
|
|
if [ ! "$?" = 0 ]; then
|
|
|
|
echo "make_volatile failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd "$RISOTTO_IMAGE_DIR"
|
|
|
|
#7zr a "$IMAGE_NAME".7z "$IMAGE_NAME"
|
|
|
|
if [ -f "$IMAGE_NAME_RISOTTO_IMAGE_NAME" ]; then
|
|
|
|
mv -f "$IMAGE_NAME_RISOTTO_IMAGE_NAME" "$IMAGE_NAME_RISOTTO_IMAGE_NAME".old
|
|
|
|
fi
|
|
|
|
tar cf "$IMAGE_NAME_RISOTTO_IMAGE_NAME" "$IMAGE_NAME"
|
|
|
|
sha256sum "$IMAGE_NAME_RISOTTO_IMAGE_NAME" > "$IMAGE_NAME_RISOTTO_IMAGE_NAME".sha
|
2022-05-04 10:29:03 +02:00
|
|
|
cd - > /dev/null
|
2022-03-08 19:42:28 +01:00
|
|
|
cp -f "$BASE_PKGS_FILE" "$IMAGE_NAME_RISOTTO_IMAGE_DIR".base.pkgs
|
|
|
|
mv -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs.new "$IMAGE_NAME_RISOTTO_IMAGE_DIR".pkgs
|
2022-05-04 10:29:03 +02:00
|
|
|
mv -f "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum.new "$IMAGE_NAME_RISOTTO_IMAGE_DIR".md5sum
|
2022-03-08 19:42:28 +01:00
|
|
|
VERSION=$((VERSION + 1))
|
|
|
|
echo "$VERSION" > "$IMAGE_NAME_RISOTTO_IMAGE_DIR"_"$RELEASEVER".version
|
|
|
|
fi
|
|
|
|
rm -rf "$IMAGE_NAME_RISOTTO_IMAGE_DIR"
|
2022-05-04 10:29:03 +02:00
|
|
|
echo " => OK"
|
2022-03-08 19:42:28 +01:00
|
|
|
exit 0
|