make.sh new version

- script now more interactive
 - add sid repository for better testing support
 - spice better support - vmware demise
 - python2 end of life
This commit is contained in:
Lionel 2022-12-20 16:25:38 +01:00
parent 8ab794bfea
commit bf1819acfa
3 changed files with 321 additions and 174 deletions

View File

@ -2,7 +2,7 @@ sudo
screen screen
usbutils usbutils
file file
python2 #python2
python3 python3
python3-pip python3-pip
genisoimage genisoimage

View File

@ -1,3 +1,5 @@
qemu-guest-agent qemu-guest-agent
spice-vdagent spice-vdagent
open-vm-tools xserver-xorg-video-qxl
#open-vm-tools
#xserver-xorg-video-vmware

489
make.sh
View File

@ -1,16 +1,20 @@
#!/bin/bash #!/bin/bash
USER_HOME=$(eval echo ~${SUDO_USER})
if [ "$EUID" -ne 0 ]
then
echo "Please run as root"
exit 1
fi
baseDir=$(pwd) baseDir=$(pwd)
build=$baseDir/build build=$baseDir/build
config=$baseDir/config config=$baseDir/config
if [ "$EUID" -ne 0 ] debian_version=$(lsb_release -sc 2>/dev/null)
then
echo "Please run as root"
exit 1
fi
pack_list=(live cli disk net firmware dm-common xfce4 cinnamon gui libreoffice vm) pack_list=(live cli disk net firmware dm-common xfce4 cinnamon gui libreoffice vm)
@ -26,11 +30,24 @@ pack_forced=(live cli disk net firmware)
pack_default=(dm-common xfce4 gui) pack_default=(dm-common xfce4 gui)
nb_hooks=0
declare -a hook_checklist
for file in $config/hooks/live/*;
do
basename="$(basename -s ".hook.chroot" $file)"
hook_checklist+=($basename "" "ON")
((nb_hooks++))
#default all hook
hooks+="$basename "
done
_usage() _usage()
{ {
cat <<EOF cat <<EOF
-d use default pack -d use default setings
-v Specifie Debian codename -v force debian version
-o Specifie output folder -o Specifie output folder
-i if set create iso instead of only squashfs -i if set create iso instead of only squashfs
EOF EOF
@ -38,8 +55,8 @@ EOF
if [ -z "$1" ] if [ -z "$1" ]
then then
_usage _usage
exit 1 exit 1
fi fi
#export http_proxy="http://192.168.110.1:3142" #export http_proxy="http://192.168.110.1:3142"
@ -49,220 +66,345 @@ KERNEL_PARAM="boot=live components lang=fr_FR.UTF-8 locales=fr_FR.UTF-8 keyboard
_check() _check()
{ {
if [ -z "$out" ] if [ -z "$out" ]
then then
printf "\e[31mPlease specifie output folder\e[0m\n" printf "\e[31mPlease specifie output folder\e[0m\n"
_usage _usage
exit 1 exit 1
fi fi
if [ -z "$debian_version" ] if [ -d "$out" ]
then then
printf "\e[31mPlease specifie Debian codename\e[0m\n" printf "Write in \e[96m$out\e[0m folder\n"
_usage if [ "$(ls -A $out)" ]
exit 1 then
fi printf "\e[91m$out is not empty be careful\e[0m\n"
fi
if [ -d "$out" ] else
then printf "\e[31m$out is not a folder\e[0m\n"
printf "Write in \e[96m$out\e[0m folder\n" _usage
if [ "$(ls -A $out)" ] exit 1
then fi
printf "\e[91m$out is not empty be careful\e[0m\n"
fi
else
printf "\e[31m$out is not a folder\e[0m\n"
_usage
exit 1
fi
printf "Debian version of live system: \e[96m$debian_version\e[0m\n"
} }
_choose() _choose()
{ {
declare -a pack_checklist
size=$((${#pack_list[@]}-(${#pack_forced[@]})))
for pack in ${pack_list[@]}; do
[[ "${pack_forced[*]}" =~ "$pack" ]] && continue
[[ "${pack_default[*]}" =~ "$pack" ]] && status="ON" || status="OFF"
pack_checklist+=($pack "${pack_name[$pack]}" $status) RESULT=$(whiptail --title "Make debian live system" --inputbox "Specifie Debian codename" 10 70 $debian_version 3>&1 1>&2 2>&3)
done [[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit
RESULT=$(whiptail --title "Make debian live system" --checklist "Select pack list" 15 70 ${size} "${pack_checklist[@]}" 3>&1 1>&2 2>&3) debian_version=$RESULT
[[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit
pack=("${pack_forced[@]} $(echo $RESULT | xargs)") printf "Debian version of live system: \e[96m$debian_version\e[0m\n"
printf "Pack list: \e[96m${pack[*]}\e[0m\n" whiptail --title "Make debian live system" --yesno "Do you want to use sid ?" 7 70 --defaultno 3>&1 1>&2 2>&3
sid=$?
[[ $sid -eq 0 ]] && printf "Using \e[96msid\e[0m\\e[0m\n"
declare -a pack_checklist
size=$((${#pack_list[@]}-(${#pack_forced[@]})))
for pack in ${pack_list[@]}; do
[[ "${pack_forced[*]}" =~ "$pack" ]] && continue
[[ "${pack_default[*]}" =~ "$pack" ]] && status="ON" || status="OFF"
pack_checklist+=($pack "${pack_name[$pack]}" $status)
done
RESULT=$(whiptail --title "Make debian live system" --checklist "Select pack list" 15 70 ${size} "${pack_checklist[@]}" 3>&1 1>&2 2>&3)
[[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit
pack=("${pack_forced[@]} $(echo $RESULT | xargs)")
printf "Pack list: \e[96m${pack[*]}\e[0m\n"
nb_hooks=0 RESULT=$(whiptail --title "Make debian live system" --checklist "Select hooks to use" 15 70 ${nb_hooks} "${hook_checklist[@]}" 3>&1 1>&2 2>&3)
declare -a hook_checklist [[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit
for file in $config/hooks/live/*;
do
basename="$(basename -s ".hook.chroot" $file)"
hook_checklist+=($basename "" "ON")
((nb_hooks++))
done
#whiptail --separate-output --title "Make debian live system" --checklist "Select hooks to use" 15 70 ${nb_hooks} "${hook_checklist[@]}" hooks=$(echo $RESULT | xargs)
RESULT=$(whiptail --title "Make debian live system" --checklist "Select hooks to use" 15 70 ${nb_hooks} "${hook_checklist[@]}" 3>&1 1>&2 2>&3) printf "Hooks list: \e[96m${hooks[*]}\e[0m\n"
[[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit
hooks=$(echo $RESULT | xargs)
printf "Hooks list: \e[96m${hooks[*]}\e[0m\n"
# read -p "Continue ? " -n 1 -r
# echo
# if ! [[ $REPLY =~ ^[YyOo]$ ]]
# then
# echo "Cancel"
# exit
# fi
} }
_config() _config()
{ {
mkdir -p $build/config mkdir -p $build/config
cd $build cd $build
ln -sr $config/includes.chroot $build/config ln -sr $config/includes.chroot $build/config
ln -sr $config/packages.chroot $build/config ln -sr $config/packages.chroot $build/config
lb clean lb clean
lb clean --cache lb clean --cache
#--apt-http-proxy "http://192.168.110.1:3142" \ #--apt-http-proxy "http://192.168.110.1:3142" \
lb config noauto \ lb config noauto \
--architectures amd64 \ --architectures amd64 \
--distribution $debian_version \ --distribution $debian_version \
--binary-images iso-hybrid \ --binary-images iso-hybrid \
--archive-areas "main contrib non-free" \ --archive-areas "main contrib non-free" \
--debian-installer none \ --debian-installer none \
--apt-recommends false \ --apt-recommends false \
--updates true \ --updates true \
--security true \ --security true \
--source false \ --source false \
--backports false \ --backports false \
--memtest none \ --memtest none \
--bootappend-live "$KERNEL_PARAM" --bootappend-live "$KERNEL_PARAM"
rm $build/config/package-lists/* rm $build/config/package-lists/*
for file in ${pack[@]}; do for file in ${pack[@]}; do
ln -sr $config/package-lists/$file.list.chroot $build/config/package-lists/$file.list.chroot ln -sr $config/package-lists/$file.list.chroot $build/config/package-lists/$file.list.chroot
done done
for hook in ${hooks[@]}; do for hook in ${hooks[@]}; do
ln -sr $config/hooks/live/$hook.hook.chroot $build/config/hooks/live/$hook.hook.chroot ln -sr $config/hooks/live/$hook.hook.chroot $build/config/hooks/live/$hook.hook.chroot
done done
} }
_build() _build()
{ {
printf "\e[96mBootstrap new root filesystem\e[0m\n" printf "\e[96mBootstrap new root filesystem\e[0m\n"
lb bootstrap lb bootstrap
[[ $? -eq 0 ]] || exit [[ $? -eq 0 ]] || exit
printf "\e[96mBuild live OS file system\e[0m\n" #printf "\e[96mBuild live OS file system\e[0m\n"
lb chroot #lb chroot
[[ $? -eq 0 ]] || exit #[[ $? -eq 0 ]] || exit
# Write commit hash and build date printf "\e[96mBuild live OS file system\e[0m\n"
echo "$(git -C $baseDir log -1 --pretty='%cd %h %s' --date=format:"%F")" >> $build/chroot/etc/debian_version lb chroot_cache restore
echo "Build date: $(date +"%F %R")" >> $build/chroot/etc/debian_version [[ $? -eq 0 ]] || exit
lb chroot_prep install all mode-archives-chroot
[[ $? -eq 0 ]] || exit
lb chroot_devpts install
[[ $? -eq 0 ]] || exit
lb chroot_proc install
[[ $? -eq 0 ]] || exit
lb chroot_selinuxfs install
[[ $? -eq 0 ]] || exit
lb chroot_sysfs install
[[ $? -eq 0 ]] || exit
lb chroot_debianchroot install
[[ $? -eq 0 ]] || exit
lb chroot_dpkg install
[[ $? -eq 0 ]] || exit
lb chroot_tmpfs install
[[ $? -eq 0 ]] || exit
lb chroot_sysv-rc install
[[ $? -eq 0 ]] || exit
lb chroot_hosts install
[[ $? -eq 0 ]] || exit
lb chroot_resolv install
[[ $? -eq 0 ]] || exit
lb chroot_hostname install
[[ $? -eq 0 ]] || exit
lb chroot_apt install
[[ $? -eq 0 ]] || exit
lb chroot_archives chroot install
[[ $? -eq 0 ]] || exit
lb chroot_linux-image
[[ $? -eq 0 ]] || exit
lb chroot_firmware
[[ $? -eq 0 ]] || exit
lb chroot_preseed
[[ $? -eq 0 ]] || exit
lb chroot_includes_before_packages
[[ $? -eq 0 ]] || exit
[[ $sid -eq 0 ]] && _sid
lb chroot_package-lists install
[[ $? -eq 0 ]] || exit
lb chroot_install-packages install
[[ $? -eq 0 ]] || exit
lb chroot_package-lists live
[[ $? -eq 0 ]] || exit
lb chroot_install-packages live
[[ $? -eq 0 ]] || exit
lb chroot_includes_after_packages
[[ $? -eq 0 ]] || exit
lb chroot_hooks
[[ $? -eq 0 ]] || exit
lb chroot_hacks
[[ $? -eq 0 ]] || exit
lb chroot_interactive
[[ $? -eq 0 ]] || exit
lb chroot_prep remove all mode-archives-chroot
[[ $? -eq 0 ]] || exit
lb chroot_archives chroot remove
[[ $? -eq 0 ]] || exit
lb chroot_apt remove
[[ $? -eq 0 ]] || exit
lb chroot_hostname remove
[[ $? -eq 0 ]] || exit
lb chroot_resolv remove
[[ $? -eq 0 ]] || exit
lb chroot_hosts remove
[[ $? -eq 0 ]] || exit
lb chroot_sysv-rc remove
[[ $? -eq 0 ]] || exit
lb chroot_tmpfs remove
[[ $? -eq 0 ]] || exit
lb chroot_dpkg remove
[[ $? -eq 0 ]] || exit
lb chroot_debianchroot remove
[[ $? -eq 0 ]] || exit
lb chroot_sysfs remove
[[ $? -eq 0 ]] || exit
lb chroot_selinuxfs remove
[[ $? -eq 0 ]] || exit
lb chroot_proc remove
[[ $? -eq 0 ]] || exit
lb chroot_devpts remove
[[ $? -eq 0 ]] || exit
lb chroot_cache save
[[ $? -eq 0 ]] || exit
[[ $sid -eq 0 ]] && echo "deb http://deb.debian.org/debian sid main" >> $build/chroot/etc/apt/sources.list
# Write commit hash and build date
echo "$(git -C $baseDir log -1 --pretty='%cd %h %s' --date=format:"%F")" >> $build/chroot/etc/debian_version
echo "Build date: $(date +"%F %R")" >> $build/chroot/etc/debian_version
}
_sid()
{
printf "\e[96mAdd sid repository\e[0m\n"
echo "deb http://deb.debian.org/debian sid main" >> $build/chroot/etc/apt/sources.list.d/zz-sources.list
chroot $build/chroot apt update
cat <<EOF > $build/chroot/etc/apt/preferences.d/sid.pref
# testing pref :
# 100 <= P < 500: causes a version to be installed unless there is a
# version available belonging to some other distribution or the installed
# version is more recent
Package: *
Pin: release a=testing
Pin-Priority: 400
# unstable pref :
# 0 < P < 100: causes a version to be installed only if there is no
# installed version of the package
Package: *
Pin: release a=unstable
Pin-Priority: 50
EOF
}
_prep_mounts()
{
printf "\e[96mPreparing root filesystem\e[0m\n"
lb binary_chroot
[[ $? -eq 0 ]] || exit
# Chroot preparation component lists
# We deliberately exclude 'debianchroot'
CHROOT_PREP_MOUNTS="devpts proc selinuxfs sysfs"
CHROOT_PREP_OTHER="dpkg tmpfs sysv-rc hosts resolv hostname apt"
# Configuring chroot
lb chroot_prep install "${CHROOT_PREP_MOUNTS}"
[[ $? -eq 0 ]] || exit
lb chroot_prep install "${CHROOT_PREP_OTHER}" mode-apt-install-binary mode-archives-chroot
[[ $? -eq 0 ]] || exit
lb chroot_archives chroot install
[[ $? -eq 0 ]] || exit
}
_prep_umounts()
{
# Deconfiguring chroot
lb chroot_prep remove "${CHROOT_PREP_MOUNTS}"
[[ $? -eq 0 ]] || exit
lb chroot_prep remove "${CHROOT_PREP_OTHER}"
[[ $? -eq 0 ]] || exit
} }
_create_squashfs() _create_squashfs()
{ {
printf "\e[96mPreparing root filesystem\e[0m\n" printf "\e[96mBuilding root filesystem\e[0m\n"
lb binary_chroot lb binary_rootfs
[[ $? -eq 0 ]] || exit [[ $? -eq 0 ]] || exit
lb binary_linux-image
[[ $? -eq 0 ]] || exit
# Chroot preparation component lists printf "\e[96mCopy filesystem\e[0m\n"
# We deliberately exclude 'debianchroot' cp -v $build/chroot/{initrd.img,vmlinuz} $out/
CHROOT_PREP_MOUNTS="devpts proc selinuxfs sysfs" cp -v $build/binary/live/filesystem.squashfs $out/
CHROOT_PREP_OTHER="dpkg tmpfs sysv-rc hosts resolv hostname apt" chown $SUDO_UID:$SUDO_GID $out/{initrd.img,vmlinuz,filesystem.squashfs}
# Configuring chroot
lb chroot_prep install "${CHROOT_PREP_MOUNTS}"
lb chroot_prep install "${CHROOT_PREP_OTHER}" mode-apt-install-binary mode-archives-chroot
lb chroot_archives chroot install
printf "\e[96mBuilding root filesystem\e[0m\n"
lb binary_rootfs
printf "\e[96mPrepare images\e[0m\n"
lb binary_linux-image
lb binary_syslinux
# Deconfiguring chroot
lb chroot_prep remove "${CHROOT_PREP_MOUNTS}"
lb chroot_prep remove "${CHROOT_PREP_OTHER}"
printf "\e[96mCopy filesystem\e[0m\n"
cp $build/binary/live/{initrd.img,vmlinuz,filesystem.squashfs} $out/
chown $SUDO_UID:$SUDO_GID $out/{initrd.img,vmlinuz,filesystem.squashfs}
} }
_create_iso() _create_iso()
{ {
printf "\e[96mBuild binary (live disc) images\e[0m\n" printf "\e[96mPrepare image\e[0m\n"
lb binary lb binary_syslinux
[[ $? -eq 0 ]] || exit
lb binary_grub_cfg
[[ $? -eq 0 ]] || exit
lb binary_grub-efi
[[ $? -eq 0 ]] || exit
printf "\e[96mCopy ISO\e[0m\n" printf "\e[96mCreate image\e[0m\n"
lb binary_iso
[[ $? -eq 0 ]] || exit
if [ -d "$out" ] printf "\e[96mCopy image\e[0m\n"
then outiso="$out/live-${debian_version}-image.iso"
$out="$out/live-${debian_version}-image.iso" cp -v $build/live-image-amd64.hybrid.iso $outiso
fi chown $SUDO_UID:$SUDO_GID $outiso
cp $build/live-image-amd64.hybrid.iso $out
chown $SUDO_UID:$SUDO_GID $out
} }
_delete() _delete()
{ {
printf "\e[96mDelete $build\e[0m\n" printf "\e[96mDelete $build\e[0m\n"
rm -r $build rm -r $build
} }
while getopts "dv:o:i" OPTION; do while getopts "dv:o:i" OPTION; do
case $OPTION in case $OPTION in
d) d)
default=true default=true
;; ;;
v) v)
debian_version=${OPTARG} debian_version=${OPTARG}
;; ;;
o) o)
out="$(realpath ${OPTARG})" out="$(realpath ${OPTARG})"
;; ;;
i) i)
iso=true iso=true
;; ;;
*) *)
_usage _usage
exit 1 exit 1
;; ;;
esac esac
done done
_check _check
@ -271,9 +413,12 @@ _config
_build _build
mkdir -p $build/chroot/etc/skel/.ssh mkdir -p $build/chroot/etc/skel/.ssh
cp -v /home/lionel/.ssh/{config,key_rsa_majalis,key_rsa_majalis.pub} $build/chroot/etc/skel/.ssh cp -v $USER_HOME/.ssh/{config,key_rsa_majalis,key_rsa_majalis.pub} $build/chroot/etc/skel/.ssh
sudo -u $SUDO_USER ssh-keygen -H -F netdldata.net > $build/chroot/etc/skel/.ssh/known_hosts ssh-keygen -f $USER_HOME/.ssh/known_hosts -q -H -F netdldata.net > $build/chroot/etc/skel/.ssh/known_hosts
[[ $iso = true ]] && _create_iso || _create_squashfs _prep_mounts
_create_squashfs
[[ $iso = true ]] && _create_iso
_prep_umounts
_delete _delete