diff --git a/config/package-lists/cli.list.chroot b/config/package-lists/cli.list.chroot index ad31a3f..091646f 100644 --- a/config/package-lists/cli.list.chroot +++ b/config/package-lists/cli.list.chroot @@ -2,7 +2,7 @@ sudo screen usbutils file -python2 +#python2 python3 python3-pip genisoimage diff --git a/config/package-lists/vm.list.chroot b/config/package-lists/vm.list.chroot index caf28bf..a4beed3 100644 --- a/config/package-lists/vm.list.chroot +++ b/config/package-lists/vm.list.chroot @@ -1,3 +1,5 @@ qemu-guest-agent spice-vdagent -open-vm-tools +xserver-xorg-video-qxl +#open-vm-tools +#xserver-xorg-video-vmware diff --git a/make.sh b/make.sh index fbc45f5..b916493 100755 --- a/make.sh +++ b/make.sh @@ -1,16 +1,20 @@ #!/bin/bash +USER_HOME=$(eval echo ~${SUDO_USER}) + +if [ "$EUID" -ne 0 ] +then + echo "Please run as root" + exit 1 +fi + baseDir=$(pwd) build=$baseDir/build config=$baseDir/config -if [ "$EUID" -ne 0 ] -then - echo "Please run as root" - exit 1 -fi +debian_version=$(lsb_release -sc 2>/dev/null) 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) + +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() { - cat <&1 1>&2 2>&3) + [[ "$?" = 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) - [[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit + debian_version=$RESULT - 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 - declare -a hook_checklist - for file in $config/hooks/live/*; - do - basename="$(basename -s ".hook.chroot" $file)" - hook_checklist+=($basename "" "ON") - ((nb_hooks++)) - done + RESULT=$(whiptail --title "Make debian live system" --checklist "Select hooks to use" 15 70 ${nb_hooks} "${hook_checklist[@]}" 3>&1 1>&2 2>&3) + [[ "$?" = 1 ]] && printf "\e[91mCancel\e[0m\n" && exit - #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) - [[ "$?" = 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 + printf "Hooks list: \e[96m${hooks[*]}\e[0m\n" } _config() { - mkdir -p $build/config + mkdir -p $build/config - cd $build + cd $build - ln -sr $config/includes.chroot $build/config - ln -sr $config/packages.chroot $build/config + ln -sr $config/includes.chroot $build/config + ln -sr $config/packages.chroot $build/config - lb clean - lb clean --cache + lb clean + lb clean --cache - #--apt-http-proxy "http://192.168.110.1:3142" \ - lb config noauto \ - --architectures amd64 \ - --distribution $debian_version \ - --binary-images iso-hybrid \ - --archive-areas "main contrib non-free" \ - --debian-installer none \ - --apt-recommends false \ - --updates true \ - --security true \ - --source false \ - --backports false \ - --memtest none \ - --bootappend-live "$KERNEL_PARAM" + #--apt-http-proxy "http://192.168.110.1:3142" \ + lb config noauto \ + --architectures amd64 \ + --distribution $debian_version \ + --binary-images iso-hybrid \ + --archive-areas "main contrib non-free" \ + --debian-installer none \ + --apt-recommends false \ + --updates true \ + --security true \ + --source false \ + --backports false \ + --memtest none \ + --bootappend-live "$KERNEL_PARAM" - rm $build/config/package-lists/* + rm $build/config/package-lists/* - for file in ${pack[@]}; do - ln -sr $config/package-lists/$file.list.chroot $build/config/package-lists/$file.list.chroot - done + for file in ${pack[@]}; do + ln -sr $config/package-lists/$file.list.chroot $build/config/package-lists/$file.list.chroot + done - for hook in ${hooks[@]}; do - ln -sr $config/hooks/live/$hook.hook.chroot $build/config/hooks/live/$hook.hook.chroot - done + for hook in ${hooks[@]}; do + ln -sr $config/hooks/live/$hook.hook.chroot $build/config/hooks/live/$hook.hook.chroot + done } _build() { - - printf "\e[96mBootstrap new root filesystem\e[0m\n" - lb bootstrap - [[ $? -eq 0 ]] || exit + + printf "\e[96mBootstrap new root filesystem\e[0m\n" + lb bootstrap + [[ $? -eq 0 ]] || exit - printf "\e[96mBuild live OS file system\e[0m\n" - lb chroot - [[ $? -eq 0 ]] || exit + #printf "\e[96mBuild live OS file system\e[0m\n" + #lb chroot + #[[ $? -eq 0 ]] || exit - # 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 + printf "\e[96mBuild live OS file system\e[0m\n" + lb chroot_cache restore + [[ $? -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 < $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() { - printf "\e[96mPreparing root filesystem\e[0m\n" - lb binary_chroot - [[ $? -eq 0 ]] || exit + printf "\e[96mBuilding root filesystem\e[0m\n" + lb binary_rootfs + [[ $? -eq 0 ]] || exit + lb binary_linux-image + [[ $? -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}" - 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} + printf "\e[96mCopy filesystem\e[0m\n" + cp -v $build/chroot/{initrd.img,vmlinuz} $out/ + cp -v $build/binary/live/filesystem.squashfs $out/ + chown $SUDO_UID:$SUDO_GID $out/{initrd.img,vmlinuz,filesystem.squashfs} } _create_iso() { - printf "\e[96mBuild binary (live disc) images\e[0m\n" - lb binary + printf "\e[96mPrepare image\e[0m\n" + 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" ] - then - $out="$out/live-${debian_version}-image.iso" - fi - - cp $build/live-image-amd64.hybrid.iso $out - - chown $SUDO_UID:$SUDO_GID $out + printf "\e[96mCopy image\e[0m\n" + outiso="$out/live-${debian_version}-image.iso" + cp -v $build/live-image-amd64.hybrid.iso $outiso + chown $SUDO_UID:$SUDO_GID $outiso } + _delete() { - printf "\e[96mDelete $build\e[0m\n" - rm -r $build + printf "\e[96mDelete $build\e[0m\n" + rm -r $build } while getopts "dv:o:i" OPTION; do - case $OPTION in - d) - default=true - ;; - v) - debian_version=${OPTARG} - ;; - o) - out="$(realpath ${OPTARG})" - ;; - i) - iso=true - ;; - *) - _usage - exit 1 - ;; - esac + case $OPTION in + d) + default=true + ;; + v) + debian_version=${OPTARG} + ;; + o) + out="$(realpath ${OPTARG})" + ;; + i) + iso=true + ;; + *) + _usage + exit 1 + ;; + esac done _check @@ -271,9 +413,12 @@ _config _build 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 -sudo -u $SUDO_USER ssh-keygen -H -F netdldata.net > $build/chroot/etc/skel/.ssh/known_hosts - -[[ $iso = true ]] && _create_iso || _create_squashfs +cp -v $USER_HOME/.ssh/{config,key_rsa_majalis,key_rsa_majalis.pub} $build/chroot/etc/skel/.ssh +ssh-keygen -f $USER_HOME/.ssh/known_hosts -q -H -F netdldata.net > $build/chroot/etc/skel/.ssh/known_hosts + + _prep_mounts +_create_squashfs +[[ $iso = true ]] && _create_iso +_prep_umounts _delete