#!/bin/bash # Functions library :: for install scripts # Author: crims0n. # # ================================================================= # ================================================================= # ========================= VARIABLES ============================= # ================================================================= # ================================================================= function common_variables() { # CONTAINER_TYPE="0" set +u if [ -z $container ]; then container="" fi set -u : 'if [ -f /.dockerenv ] || [ "$container" = "podman" ]; then OUTPUT="/dev/stdout" #CONTAINER="docker" fi' if [ -f /.dockerenv ] || [ "$container" = "podman" ] && [ ! -d /opt/minios-live ] && [ ! -f /.minios-live-container ]; then CONTAINER_TYPE="1" fi if [[ (-f /.dockerenv || "$container" = "podman") && (-d /opt/minios-live || -f /.minios-live-container) ]]; then CONTAINER_TYPE="2" fi } # ================================================================= # ================================================================= # ===================== COMMON FUNCTIONS ========================== # ================================================================= # ================================================================= function current_process() { echo -e "${LIGHTYELLOW}=====> running ${CYAN}${CMD[ii]}${ENDCOLOUR}${LIGHTYELLOW} ...${ENDCOLOUR}" } # ================================================================= # beautiful console # красивая консоль # ================================================================= function console_colours() { RED="\e[31m" GREEN="\e[32m" YELLOW="\e[33m" BLUE="\e[34m" MAGENTA="\e[35m" CYAN="\e[36m" LIGHTGRAY="\e[37m" DARKGRAY="\e[90m" LIGHTRED="\e[91m" LIGHTGREEN="\e[92m" LIGHTYELLOW="\e[93m" LIGHTBLUE="\e[94m" LIGHTMAGENTA="\e[95m" LIGHTCYAN="\e[96m" BOLD="\e[1m" DIM="\e[2m" UNDERLINED="\e[4m" BLINK="\e[5m" REVERSE="\e[7m" HIDDEN="\e[8m" ENDCOLOUR="\e[0m" } # ================================================================= # help functions # функции помощи # ================================================================= function help() { # if $1 is set, use $1 as headline message in help() if grep 'LANG="ru_RU.UTF-8"' /etc/default/locale >>$OUTPUT; then if [ -z ${1+x} ]; then echo -e "${LIGHTYELLOW}Этот скрипт собирает загружаемый ISO образ $SYSTEMNAME.${ENDCOLOUR}" echo -e else echo -e $1 echo fi echo -e "Поддерживаемые команды : ${CYAN}${CMD[*]}${ENDCOLOUR}" echo -e echo -e "Синтаксис: ${MAGENTA}$0${ENDCOLOUR} [start_cmd] [-] [end_cmd]" if [ -L /usr/bin/$LIVEKITNAME-install ] && [ "$0" != "/usr/bin/$LIVEKITNAME-install" ]; then echo -e "\t${CYAN}$LIVEKITNAME-install${ENDCOLOUR} [start_cmd] [-] [end_cmd]" fi echo -e "\tзапуск от start_cmd до end_cmd" echo -e "\tесли start_cmd опущен, выполняются все команды, начиная с первой" echo -e "\tесли end_cmd опущен, выполняются все команды до последней" echo -e "\tвведите одну команду, чтобы запустить определенную команду" echo -e "\tвведите '-' как единственный аргумент для запуска всех команд" echo -e "\t" echo -e "\tПримеры:${LIGHTYELLOW}$0 build_bootstrap - build_chroot${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 - build_chroot${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 build_bootstrap -${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 build_iso${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 -${ENDCOLOUR}" exit 0 else if [ -z ${1+x} ]; then echo -e "${LIGHTYELLOW}This script builds bootable $SYSTEMNAME ISO image.${ENDCOLOUR}" echo -e else echo -e $1 echo fi echo -e "Supported commands : ${CYAN}${CMD[*]}${ENDCOLOUR}" echo -e echo -e "Syntax: ${MAGENTA}$0${ENDCOLOUR} [start_cmd] [-] [end_cmd]" if [ -L /usr/bin/$LIVEKITNAME-install ] && [ "$0" != "/usr/bin/$LIVEKITNAME-install" ]; then echo -e "\t${CYAN}$LIVEKITNAME-install${ENDCOLOUR} [start_cmd] [-] [end_cmd]" fi echo -e "\trun from start_cmd to end_cmd" echo -e "\tif start_cmd is omitted, start from first command" echo -e "\tif end_cmd is omitted, end with last command" echo -e "\tenter single cmd to run the specific command" echo -e "\tenter '-' as only argument to run all commands" echo -e "\t" echo -e "\tExamples:${LIGHTYELLOW}$0 build_bootstrap - build_chroot${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 - build_chroot${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 build_bootstrap -${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 build_iso${ENDCOLOUR}" echo -e "\t\t${LIGHTYELLOW}$0 -${ENDCOLOUR}" exit 0 fi } function find_index() { local ret local i for ((i = 0; i < ${#CMD[*]}; i++)); do if [ "${CMD[i]}" == "$1" ]; then index=$i return fi done help "Command not found : $1" } function create_livekitname_install_symlink() { if [ -L /usr/bin/$LIVEKITNAME-install ]; then if [ "$(readlink /usr/bin/$LIVEKITNAME-install)" != "$SCRIPT_DIR/install" ]; then rm -f /usr/bin/$LIVEKITNAME-install ln -s $SCRIPT_DIR/install /usr/bin/$LIVEKITNAME-install if grep 'LANG="ru_RU.UTF-8"' /etc/default/locale >>$OUTPUT; then echo -e "Символическая ссылка ${MAGENTA}/usr/bin/$LIVEKITNAME-install${ENDCOLOUR} была обновлена." echo -e "Теперь она указывает на ${MAGENTA}$SCRIPT_DIR/install${ENDCOLOUR}." else echo -e "The ${MAGENTA}/usr/bin/$LIVEKITNAME-install${ENDCOLOUR} symbolic link has been updated." echo -e "It now points to ${MAGENTA}$SCRIPT_DIR/install${ENDCOLOUR}." fi fi if [ "$0" != "/usr/bin/$LIVEKITNAME-install" ]; then if grep 'LANG="ru_RU.UTF-8"' /etc/default/locale >>$OUTPUT; then echo -e "Вы можете использовать команду ${CYAN}$LIVEKITNAME-install${ENDCOLOUR} для запуска этой программы." else echo -e "You can use the ${CYAN}$LIVEKITNAME-install${ENDCOLOUR} command to run this program." fi fi else ln -s $SCRIPT_DIR/install /usr/bin/$LIVEKITNAME-install if grep 'LANG="ru_RU.UTF-8"' /etc/default/locale >>$OUTPUT; then echo -e "Символическая ссылка ${MAGENTA}/usr/bin/$LIVEKITNAME-install${ENDCOLOUR} была добавлена" echo -e "для ${MAGENTA}$SCRIPT_DIR/install${ENDCOLOUR}." else echo -e "The ${MAGENTA}/usr/bin/$LIVEKITNAME-install${ENDCOLOUR} symbolic link has been added" echo -e "for ${MAGENTA}$SCRIPT_DIR/install${ENDCOLOUR}." fi fi } function create_completion() { if [ -d /etc/bash_completion.d ]; then if [ ! -f /etc/bash_completion.d/$LIVEKITNAME-install ] || ! grep "${CMD[*]}" /etc/bash_completion.d/$LIVEKITNAME-install >>$OUTPUT; then cat </etc/bash_completion.d/$LIVEKITNAME-install #/usr/bin/env bash complete -W "${CMD[*]}" $LIVEKITNAME-install EOF fi if [ "$0" != "/usr/bin/$LIVEKITNAME-install" ]; then if grep 'LANG="ru_RU.UTF-8"' /etc/default/locale >>$OUTPUT; then echo -e "Дополнение команд работает только при использовании команды ${CYAN}$LIVEKITNAME-install${ENDCOLOUR}." echo -e else echo -e "Command completion only works when using the ${CYAN}$LIVEKITNAME-install${ENDCOLOUR} command." echo -e fi fi fi } # ================================================================= # only allow 'root' to run the script # разрешаем запуск скрипта только пользователю 'root' # ================================================================= function allow_root_only() { if [ $(id -u) -ne 0 ]; then echo -e "${BOLD}${RED}This script should be run as 'root'!${ENDCOLOUR}" exit 1 fi export HOME=/root export LC_ALL=C } # ================================================================= # check that we are inside chroot # проверяем, что мы внутри chroot # ================================================================= function check_is_in_chroot() { if [ $(stat -c %i /)="2" ]; then echo -e "${BOLD}${RED}This script should be run inside chroot only!${ENDCOLOUR}" exit 1 fi } # ================================================================= # check if filesystems are unmounted inside chroot # проверяем, размонтированы ли файловые системы внутри chroot # ================================================================= function check_mounted() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if grep -qs "$BUILD_DIR/dev" /proc/mounts || grep -qs "$BUILD_DIR/run" /proc/mounts || grep -qs "$BUILD_DIR/proc" /proc/mounts || grep -qs "$BUILD_DIR/sys" /proc/mounts || grep -qs "$BUILD_DIR/dev/pts" /proc/mounts || grep -qs "$BUILD_DIR/tmp" /proc/mounts; then echo -e "${BOLD}${LIGHTYELLOW}Сhroot contains mounted filesystems.${ENDCOLOUR}" if [ "$UNATTENDED" = "1" ]; then chroot_umount_fs else read -r -p "$(echo -e ""Do you want to ${GREEN}unmount them${ENDCOLOUR}? [${BOLD}${GREEN}Y${ENDCOLOUR}/n])" response response=${response,,} if [[ "$response" =~ ^(no|n)$ ]]; then exit 1 else chroot_umount_fs fi fi fi } # ================================================================= # check if the folder where the installation will be performed is empty # проверяем, пуста ли папка, в которую будет производиться установка # ================================================================= function check_build_dir() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ "$UNATTENDED" = "1" ]; then #echo -e "${RED}!!!Unattended installation!!!${ENDCOLOUR}" BUILD_DIR="/build/$DISTRIBUTION" echo -e "The working directory is ${MAGENTA}$BUILD_DIR${ENDCOLOUR}." if [ "$(ls -A $BUILD_DIR)" != "" ]; then cleanup check_mounted fi else # ▼ должно быть только перенаправление ошибки! if [ "$(ls -A $BUILD_DIR)" != "" ]; then echo -e "${MAGENTA}$BUILD_DIR${ENDCOLOUR} is not empty." cleanup check_mounted if [ ! -d "$BUILD_DIR" ]; then mkdir -p $BUILD_DIR fi BUILD_DIR="$( cd $BUILD_DIR pwd )" echo $BUILD_DIR >$SCRIPT_DIR/.build_dir && chmod 644 $SCRIPT_DIR/.build_dir echo -e "The working directory is ${MAGENTA}$BUILD_DIR${ENDCOLOUR}." else mkdir -p $BUILD_DIR check_mounted BUILD_DIR="$( cd $BUILD_DIR pwd )" echo $BUILD_DIR >$SCRIPT_DIR/.build_dir && chmod 644 $SCRIPT_DIR/.build_dir echo -e "The working directory is ${MAGENTA}$BUILD_DIR${ENDCOLOUR}." fi fi } # ================================================================= # configure the build folder # настраиваем папку для сборки # ================================================================= function setup_build_dir() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ "$UNATTENDED" = "1" ] && [ "$BUILD_DIR" = "" ]; then BUILD_DIR="/build/$DISTRIBUTION" check_build_dir else if [ "$BUILD_DIR" = "" ]; then if [ ! -f "$SCRIPT_DIR/.build_dir" ]; then echo "Enter the address of the working directory where we will build the system" read -r -p "$(echo -e "(Default is ${MAGENTA}$PARENT_DIR/$DISTRIBUTION${ENDCOLOUR}): ")" response BUILD_DIR=${response,,} if [ "$BUILD_DIR" = "" ]; then BUILD_DIR=$PARENT_DIR/$DISTRIBUTION fi check_build_dir else LAST_BUILD_DIR=$(cat "$SCRIPT_DIR/.build_dir") echo -e "Last time you used the build directory ${MAGENTA}$LAST_BUILD_DIR${ENDCOLOUR}." read -r -p "$(echo -e ""Do you want to use it again? [${BOLD}${GREEN}Y${ENDCOLOUR}/n])" response response=${response,,} if [[ "$response" =~ ^(no|n)$ ]]; then echo "Enter the address of the working directory where we will build the system" read -r -p "$(echo -e "(Default is ${MAGENTA}$PARENT_DIR/$DISTRIBUTION${ENDCOLOUR}): ")" response BUILD_DIR=${response,,} if [ "$BUILD_DIR" = "" ]; then BUILD_DIR=$PARENT_DIR/$DISTRIBUTION fi check_build_dir else BUILD_DIR="$LAST_BUILD_DIR" check_build_dir fi fi fi fi } function cleanup() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ "${CMD[ii]}" = "setup_host" ] || [ "${CMD[ii]}" = "build_bootstrap" ] || [ "${CMD[ii]}" = "build_chroot" ]; then if [ "$UNATTENDED" = "1" ]; then check_mounted rm -rf $BUILD_DIR if [ -d "$BUILD_DIR" ]; then cleanup fi else read -r -p "$(echo -e ""Do you want to ${BOLD}${RED}completely remove content${ENDCOLOUR} of ${MAGENTA}$BUILD_DIR${ENDCOLOUR}? [y/${BOLD}${GREEN}N${ENDCOLOUR}])" response response=${response,,} if [[ "$response" =~ ^(yes|y)$ ]]; then check_mounted rm -rf $BUILD_DIR if [ -d "$BUILD_DIR" ]; then cleanup fi else echo -e "${MAGENTA}$BUILD_DIR${ENDCOLOUR} should be empty to continue." exit 1 fi fi fi } # ================================================================= # mount filesystems inside chroot # монтируем файловые системы внутри chroot # ================================================================= function chroot_mount_fs() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." #if [ ! -d $BUILD_DIR/dev ]; then # mkdir $BUILD_DIR/dev #fi check_mounted : 'if [ -f /.dockerenv ] || [ "$container" = "podman" ]; then ln -s /dev $BUILD_DIR/dev ln -s /run $BUILD_DIR/run ln -s /proc $BUILD_DIR/proc ln -s /sys $BUILD_DIR/sys ln -s /tmp $BUILD_DIR/tmp else' mount --bind /dev $BUILD_DIR/dev mount --bind /run $BUILD_DIR/run mount none -t proc $BUILD_DIR/proc mount none -t sysfs $BUILD_DIR/sys mount none -t devpts $BUILD_DIR/dev/pts mount none -t tmpfs $BUILD_DIR/tmp #fi } # ================================================================= # unmount filesystems inside chroot # размонтируем файловые системы внутри chroot # ================================================================= function chroot_umount_fs() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." : 'if [ -f /.dockerenv ] || [ "$container" = "podman" ]; then set +e rm -f $BUILD_DIR/dev >>$OUTPUT 2>&1 rm -f $BUILD_DIR/run >>$OUTPUT 2>&1 rm -f $BUILD_DIR/proc >>$OUTPUT 2>&1 rm -f $BUILD_DIR/sys >>$OUTPUT 2>&1 rm -f $BUILD_DIR/tmp >>$OUTPUT 2>&1 set -e else' set +e umount $BUILD_DIR/proc >>$OUTPUT 2>&1 umount $BUILD_DIR/sys >>$OUTPUT 2>&1 umount $BUILD_DIR/dev/pts >>$OUTPUT 2>&1 umount $BUILD_DIR/tmp >>$OUTPUT 2>&1 umount $BUILD_DIR/dev >>$OUTPUT 2>&1 umount $BUILD_DIR/run >>$OUTPUT 2>&1 set -e #fi check_mounted } function remove_log_file() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ -f $LOGPATH/$LIVEKITNAME.log ]; then rm -f $LOGPATH/$LIVEKITNAME.log fi if [ -f $BUILD_DIR/$LIVEKITNAME.log ]; then rm -f $BUILD_DIR/$LIVEKITNAME.log fi } function create_backup() { if [ $CREATE_BACKUP = "1" ]; then echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ ! -f $SCRIPT_DIR/.script_version ]; then cat "1" >$SCRIPT_DIR/.script_version >>$OUTPUT 2>&1 chmod 644 $SCRIPT_DIR/.script_version >>$OUTPUT 2>&1 fi DATE=$(date +%Y%m%d_%H%M) CHANGED="0" rm -rf $SCRIPT_DIR/iso >>$OUTPUT 2>&1 rm -f $SCRIPT_DIR/.build_dir >>$OUTPUT 2>&1 rm -f $SCRIPT_DIR/*.log >>$OUTPUT 2>&1 if [ ! -d $PARENT_DIR/minios-live-current ]; then CHANGED="1" mkdir -p $PARENT_DIR/minios-live-current (cd $SCRIPT_DIR && cp --parents -afr * $PARENT_DIR/minios-live-current) else for file in $(find $SCRIPT_DIR -path $SCRIPT_DIR/.git -prune -false -o -type f | sed "s,$SCRIPT_DIR/,,g" | sed "s,.script_version,,g"); do if ! cmp $SCRIPT_DIR/$file $PARENT_DIR/minios-live-current/$file >>$OUTPUT 2>&1; then CHANGED="1" echo -e "$file has been modified since last backup." >>$OUTPUT 2>&1 echo -e "Copying $SCRIPT_DIR/$file to $PARENT_DIR/minios-live-current/$file..." >>$OUTPUT 2>&1 cp -f $SCRIPT_DIR/$file $PARENT_DIR/minios-live-current/$file >>$OUTPUT 2>&1 fi done fi if [ $CHANGED = "1" ]; then SCRIPT_VERSION=$(cat $SCRIPT_DIR/.script_version) echo $(($SCRIPT_VERSION + 1)) >$SCRIPT_DIR/.script_version echo $(($SCRIPT_VERSION + 1)) >$PARENT_DIR/minios-live-current/.script_version cd $SCRIPT_DIR >>$OUTPUT 2>&1 rm -f $PARENT_DIR/minios-live-current.tar.gz tar -czf $PARENT_DIR/minios-live-current.tar.gz ./ >>$OUTPUT 2>&1 cp $PARENT_DIR/minios-live-current.tar.gz $PARENT_DIR/minios-live-v$SCRIPT_VERSION-$DATE.tar.gz >>$OUTPUT 2>&1 fi fi } function new_run() { DATE=$(date +"%Y.%m.%d %H:%M") echo "" echo "=================================================================" >>$OUTPUT 2>&1 echo "=================================================================" >>$OUTPUT 2>&1 echo "============================ NEW RUN ============================" >>$OUTPUT 2>&1 echo "======================== $DATE =======================" >>$OUTPUT 2>&1 echo "=================================================================" >>$OUTPUT 2>&1 echo "======= If during the installation you get an error that ========" >>$OUTPUT 2>&1 echo "=== /dev/stdout is not available, try using a bionic or xenial ==" >>$OUTPUT 2>&1 echo "================= based container to install. ===================" >>$OUTPUT 2>&1 echo "=================================================================" >>$OUTPUT 2>&1 echo "=================================================================" >>$OUTPUT 2>&1 echo "" } # ================================================================= # ================================================================= # ====================== HOST FUNCTIONS =========================== # ================================================================= # ================================================================= function create_apt_list() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ ! -f $SCRIPT_DIR/linux-live/aptsources/$DISTRIBUTION.list ]; then cp -f $SCRIPT_DIR/linux-live/aptsources/sources.list $SCRIPT_DIR/linux-live/aptsources/$DISTRIBUTION.list sed -i "s,distro,$DISTRIBUTION,g" $SCRIPT_DIR/linux-live/aptsources/$DISTRIBUTION.list sed -i "s,http://ru.archive.ubuntu.com/ubuntu,$DISTRIBUTION_URL,g" $SCRIPT_DIR/linux-live/aptsources/$DISTRIBUTION.list fi } function build_bootstrap() { current_process if [ $CONTAINER_TYPE = "1" ]; then if [ ! -f /.minios-live ]; then setup_host fi fi export DEBIAN_FRONTEND=noninteractive debootstrap --arch=$DISTRIBUTION_ARCH --variant=$DISTRIBUTION_VARIANT $DISTRIBUTION $BUILD_DIR $DISTRIBUTION_URL >>$OUTPUT 2>>$OUTPUT } function copy_build_scripts() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." if [ ! -d $BUILD_DIR/linux-live ]; then mkdir -p $BUILD_DIR/linux-live (cd $SCRIPT_DIR/linux-live && cp --parents -afr * $BUILD_DIR/linux-live) else #for file in $(ls $SCRIPT_DIR/linux-live -p | grep -v /); do for file in $(find $SCRIPT_DIR/linux-live -type f | sed "s,$SCRIPT_DIR/linux-live/,,g"); do if ! cmp $SCRIPT_DIR/linux-live/$file $BUILD_DIR/linux-live/$file >>$OUTPUT 2>&1; then echo -e "$file has been modified since last build run." >>$OUTPUT 2>&1 echo -e "Copying $SCRIPT_DIR/linux-live/$file to $BUILD_DIR/linux-live/$file..." >>$OUTPUT 2>&1 cp -f $SCRIPT_DIR/linux-live/$file $BUILD_DIR/linux-live/$file >>$OUTPUT 2>&1 fi done fi chmod +x $BUILD_DIR/linux-live/build chmod +x $BUILD_DIR/linux-live/install_chroot if [ "$DEV_SYSTEM" = "1" ]; then if [ ! -d $BUILD_DIR/opt/minios-live ]; then mkdir -p $BUILD_DIR/opt/minios-live (cd $SCRIPT_DIR && cp --parents -afr * $BUILD_DIR/opt/minios-live) else for file in $(find $SCRIPT_DIR -path $SCRIPT_DIR/.git -prune -false -o -type f | sed "s,$SCRIPT_DIR/,,g"); do if ! cmp $SCRIPT_DIR/$file $BUILD_DIR/opt/minios-live/$file >>$OUTPUT 2>&1; then echo -e "$file has been modified since last build run." >>$OUTPUT 2>&1 echo -e "Copying $SCRIPT_DIR/$file to $BUILD_DIR/opt/minios-live/$file..." >>$OUTPUT 2>&1 cp -f $SCRIPT_DIR/$file $BUILD_DIR/opt/minios-live/$file >>$OUTPUT 2>&1 fi done fi fi } function preserve_environment_variables() { if [ -d /opt/minios-live ]; then chroot $BUILD_DIR /usr/bin/env \ OUTPUT=$OUTPUT \ LOGPATH=$LOGPATH \ BUILD_TEST_ISO=$BUILD_TEST_ISO \ CREATE_BACKUP=$CREATE_BACKUP \ DEBIAN_FRONTEND_TYPE=$DEBIAN_FRONTEND_TYPE \ APT_CMD=$APT_CMD \ APT_OPTIONS=$APT_OPTIONS \ LIVE_TYPE=$LIVE_TYPE fi } function build_chroot() { current_process if [ $CONTAINER_TYPE = "1" ]; then if [ ! -f /.minios-live ]; then setup_host fi fi chroot_mount_fs copy_build_scripts create_apt_list if [ "$OUTPUT"="$LOGPATH/$LIVEKITNAME.log" ] && [ -f /$LIVEKITNAME.log ]; then mv -f /$LIVEKITNAME.log $BUILD_DIR/$LIVEKITNAME.log fi if [ "$OUTPUT"="$LOGPATH/$LIVEKITNAME.log" ] && [ -f $BUILD_DIR/$LIVEKITNAME.log ]; then echo "===========================================" >>$BUILD_DIR/$LIVEKITNAME.log 2>&1 echo "===========================================" >>$BUILD_DIR/$LIVEKITNAME.log 2>&1 echo "=============== CHROOT LOG ================" >>$BUILD_DIR/$LIVEKITNAME.log 2>&1 echo "===========================================" >>$BUILD_DIR/$LIVEKITNAME.log 2>&1 echo "===========================================" >>$BUILD_DIR/$LIVEKITNAME.log 2>&1 fi cp -f $SCRIPT_DIR/linux-live/aptsources/$DISTRIBUTION.list $BUILD_DIR/etc/apt/sources.list if [ -d /opt/minios-live ] || [ -f /.minios-live-container ]; then chroot $BUILD_DIR /usr/bin/env \ OUTPUT=$OUTPUT \ LOGPATH=$LOGPATH \ BUILD_TEST_ISO=$BUILD_TEST_ISO \ CREATE_BACKUP=$CREATE_BACKUP \ DEBIAN_FRONTEND_TYPE=$DEBIAN_FRONTEND_TYPE \ APT_CMD=$APT_CMD \ APT_OPTIONS=$APT_OPTIONS \ LIVE_TYPE=$LIVE_TYPE /linux-live/install_chroot - else chroot $BUILD_DIR /linux-live/install_chroot - fi chroot_umount_fs if [ "$OUTPUT"="$LOGPATH/$LIVEKITNAME.log" ] && [ -f $BUILD_DIR/$LIVEKITNAME.log ]; then mv -f $BUILD_DIR/$LIVEKITNAME.log $SCRIPT_DIR/$LIVEKITNAME.log if [ -f $SCRIPT_DIR/$LIVEKITNAME.log ]; then echo -e "Installation log was saved to ${MAGENTA}$SCRIPT_DIR/$LIVEKITNAME.log${ENDCOLOUR}" fi fi } function build_live() { current_process if [ $CONTAINER_TYPE = "1" ]; then if [ ! -f /.minios-live ]; then setup_host fi fi remove_log_file if [ $LIVE_TYPE = "linux-live" ]; then copy_build_scripts check_build_dir chroot $BUILD_DIR mount none -t proc /proc : 'chroot $BUILD_DIR /bin/bash -x <$PARENT_DIR/image/install/memtest86 #rm -f $PARENT_DIR/image/install/memtest86-usb.zip # grub touch $PARENT_DIR/image/ubuntu cat <$PARENT_DIR/image/isolinux/grub.cfg search --set=root --file /ubuntu insmod all_video set default="0" set timeout=10 menuentry "Try MiniOS without installing (persistent live)" { linux /casper/vmlinuz boot=casper quiet splash persistent --- initrd /casper/initrd } menuentry "Try MiniOS without installing (live)" { linux /casper/vmlinuz boot=casper quiet splash --- initrd /casper/initrd } menuentry "Try MiniOS without installing (persistent live to ram)" { linux /casper/vmlinuz boot=casper toram quiet splash persistent --- initrd /casper/initrd } menuentry "Try MiniOS without installing (live to ram)" { linux /casper/vmlinuz boot=casper toram quiet splash --- initrd /casper/initrd } menuentry "Install MiniOS" { linux /casper/vmlinuz boot=casper only-ubiquity quiet splash --- initrd /casper/initrd } menuentry "Install MiniOS (from ram)" { linux /casper/vmlinuz boot=casper only-ubiquity toram quiet splash --- initrd /casper/initrd } menuentry "Check disc for defects" { linux /casper/vmlinuz boot=casper integrity-check quiet splash --- initrd /casper/initrd } menuentry "Test memory Memtest86+ (BIOS)" { linux16 /install/memtest86+ } menuentry "Test memory Memtest86 (UEFI, long load time)" { insmod part_gpt insmod search_fs_uuid insmod chain loopback loop /install/memtest86 chainloader (loop,gpt1)/efi/boot/BOOTX64.efi } EOF # generate manifest sudo chroot $BUILD_DIR dpkg-query -W --showformat='${Package} ${Version}\n' | sudo tee $PARENT_DIR/image/casper/filesystem.manifest sudo cp -v $PARENT_DIR/image/casper/filesystem.manifest $PARENT_DIR/image/casper/filesystem.manifest-desktop sudo sed -i '/ubiquity/d' $PARENT_DIR/image/casper/filesystem.manifest-desktop sudo sed -i '/casper/d' $PARENT_DIR/image/casper/filesystem.manifest-desktop sudo sed -i '/discover/d' $PARENT_DIR/image/casper/filesystem.manifest-desktop sudo sed -i '/laptop-detect/d' $PARENT_DIR/image/casper/filesystem.manifest-desktop sudo sed -i '/os-prober/d' $PARENT_DIR/image/casper/filesystem.manifest-desktop # compress rootfs sudo mksquashfs $BUILD_DIR $PARENT_DIR/image/casper/filesystem.squashfs -noappend -comp lz4 -b 1048576 printf $(sudo du -sx --block-size=1 $BUILD_DIR | cut -f1) >$PARENT_DIR/image/casper/filesystem.size # create diskdefines cat <$PARENT_DIR/image/README.diskdefines #define DISKNAME $SYSTEMNAME #define TYPE binary #define TYPEbinary 1 #define ARCH $DISTRIBUTION_ARCH #define ARCH$DISTRIBUTION_ARCH 1 #define DISKNUM 1 #define DISKNUM1 1 #define TOTALNUM 0 #define TOTALNUM0 1 EOF # create iso image pushd $PARENT_DIR/image grub-mkstandalone \ --format=x86_64-efi \ --output=isolinux/bootx64.efi \ --locales="" \ --fonts="" \ "boot/grub/grub.cfg=isolinux/grub.cfg" ( cd isolinux && dd if=/dev/zero of=efiboot.img bs=1M count=10 && sudo mkfs.vfat efiboot.img && LC_CTYPE=C mmd -i efiboot.img efi efi/boot && LC_CTYPE=C mcopy -i efiboot.img ./bootx64.efi ::efi/boot/ ) grub-mkstandalone \ --format=i386-pc \ --output=isolinux/core.img \ --install-modules="linux16 linux normal iso9660 biosdisk memdisk search tar ls" \ --modules="linux16 linux normal iso9660 biosdisk search" \ --locales="" \ --fonts="" \ "boot/grub/grub.cfg=isolinux/grub.cfg" cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img >isolinux/bios.img sudo /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v -e 'md5sum.txt' -e 'bios.img' -e 'efiboot.img' > md5sum.txt)" popd fi } function build_iso() { current_process if [ $CONTAINER_TYPE = "1" ]; then if [ ! -f /.minios-live ]; then setup_host fi fi check_build_dir if [ $LIVE_TYPE = "linux-live" ]; then copy_build_scripts if [ "$UNATTENDED" = "1" ]; then BUILD_DIR="/build/$DISTRIBUTION" fi if [ "$BUILD_DIR" = "" ]; then LAST_BUILD_DIR=$(cat "$SCRIPT_DIR/.build_dir") >>$OUTPUT 2>&1 BUILD_DIR=$LAST_BUILD_DIR fi LIVEKITDATA=$(cat $BUILD_DIR/tmp/livekitdata) cd $BUILD_DIR$LIVEKITDATA if [ ! -d $ISO_DIR ]; then mkdir -p $ISO_DIR fi mkdir -p $ISO_DIR >>$OUTPUT 2>&1 VER=$SYSTEMVER DATE=$(date +%Y%m%d_%H%M) DIR=$BUILD_DIR$LIVEKITDATA ISO=$ISO_DIR/$LIVEKITNAME-$DISTRIBUTION-$DISTRIBUTION_ARCH-$COMP_TYPE-$DATE.iso B="-b boot/syslinux/isolinux.bin -c boot/syslinux/boot.cat" C="-no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot" # ▼ должно быть только перенаправление ошибки! if [ -x "$(which xorriso 2>>$OUTPUT)" ]; then M="xorriso -as mkisofs -isohybrid-mbr $DIR/boot/syslinux/isohdpfx.bin" D=" -isohybrid-gpt-basdat -e" # ▼ должно быть только перенаправление ошибки! elif [ -x "$(which genisoimage 2>>$OUTPUT)" ]; then M=genisoimage D="-efi-boot" else M=mkisofs D="-eltorito-platform 0xEF -eltorito-boot" fi E="EFI/boot/efiboot.img -no-emul-boot" VER="$SYSTEMNAME $VER" if [ REMOVE_OLD_ISO = "1" ]; then rm $ISO_DIR/$LIVEKITNAME-$DISTRIBUTION-$DISTRIBUTION_ARCH-$COMP_TYPE-*.iso >>$OUTPUT 2>&1 fi if ! $M -hide-rr-moved -f -r -J -l -V "$VER" -A "$VER" \ $B $C $D $E -o $ISO $DIR then exit 1 fi echo ">>> $ISO created" # xorriso has hybridization built-in if [ "$(echo $M | cut -d" " -f1)" != "xorriso" ]; then # ▼ должно быть только перенаправление ошибки! if [ -x "$(which isohybrid 2>>$OUTPUT)" ]; then isohybrid -uefi $ISO else echo ">>> No isohybrid to hybridize this ISO" fi fi if [ $BUILD_TEST_ISO = "1" ]; then if cp -f $ISO_DIR/$LIVEKITNAME-$DISTRIBUTION-$DISTRIBUTION_ARCH-$COMP_TYPE-$DATE.iso $ISO_DIR/$LIVEKITNAME.iso; then echo ">>> $ISO_DIR/$LIVEKITNAME.iso created" fi fi exit 0 elif [ $LIVE_TYPE = "ubuntu" ]; then #VER=$SYSTEMVER DATE=$(date +%Y%m%d_%H%M) ISO=$ISO_DIR/$LIVEKITNAME-$DISTRIBUTION-$DISTRIBUTION_ARCH-$COMP_TYPE-$DATE.iso cd $PARENT_DIR/image sudo xorriso \ -as mkisofs \ -iso-level 3 \ -full-iso9660-filenames \ -volid "$SYSTEMNAME" \ -eltorito-boot boot/grub/bios.img \ -no-emul-boot \ -boot-load-size 4 \ -boot-info-table \ --eltorito-catalog boot/grub/boot.cat \ --grub2-boot-info \ --grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \ -eltorito-alt-boot \ -e EFI/efiboot.img \ -no-emul-boot \ -append_partition 2 0xef isolinux/efiboot.img \ -output "$ISO" \ -m "isolinux/efiboot.img" \ -m "isolinux/bios.img" \ -graft-points \ "/EFI/efiboot.img=isolinux/efiboot.img" \ "/boot/grub/bios.img=isolinux/bios.img" \ "." fi } # ================================================================= # ================================================================= # ====================== INSTALL FUNCTIONS ======================== # ================================================================= # ================================================================= function setup_host() { current_process if [ $CONTAINER_TYPE != "2" ]; then hostreq_pkg_list fi } function chroot_setup_host() { current_process echo $LIVEKITNAME >/etc/hostname prereq_pkg_list #configure machine id dbus-uuidgen >/etc/machine-id >>$OUTPUT 2>&1 ln -fs /etc/machine-id /var/lib/dbus/machine-id >>$OUTPUT 2>&1 # don't understand why, but multiple sources indicate this dpkg-divert --local --rename --add /sbin/initctl >>$OUTPUT 2>&1 ln -s /bin/true /sbin/initctl >>$OUTPUT 2>&1 } function hostreq_pkg_list() { echo -e "${YELLOW}=====> installing required software for host system ...${ENDCOLOUR}" $APT_CMD update >>$OUTPUT 2>&1 # we need this only for trusty container : 'if [ $CONTAINER_TYPE = "1" ]; then touch /.minios-live $APT_CMD install -y wget patch >>$OUTPUT 2>&1 cd ~ wget -c http://ru.archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_1.0.123ubuntu2_all.deb >>$OUTPUT 2>&1 dpkg -i ~/debootstrap_1.0.123ubuntu2_all.deb >>$OUTPUT 2>&1 cat <<'EOF' >/usr/share/debootstrap/functions.diff --- functions 2020-10-23 20:42:16.000000000 +0300 +++ functions.new 2021-01-16 23:22:25.612064306 +0300 @@ -1176,7 +1176,9 @@ umount_on_exit /dev/shm umount_on_exit /proc umount_on_exit /proc/bus/usb - umount "$TARGET/proc" 2>/dev/null || true + if [ ! -h "$TARGET/proc" ]; then + umount "$TARGET/proc" 2>/dev/null || true + fi # some container environment are used at second-stage, it already treats /proc and so on if [ -z "$(ls -A "$TARGET/proc")" ]; then EOF cd /usr/share/debootstrap/ patch >$OUTPUT 2>&1 else #sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD install -y sudo debootstrap xorriso >>$OUTPUT 2>&1 fi } function prereq_pkg_list() { echo -e "${YELLOW}=====> installing prerequested software for chroot system ...${ENDCOLOUR}" if [ $DEBIAN_FRONTEND_TYPE = "noninteractive" ]; then if [ -f $SCRIPT_DIR/pkglists/prereq.list ]; then $APT_CMD update >>$OUTPUT 2>&1 && echo -e "${YELLOW}=====> upgrading chroot system ...${ENDCOLOUR}" && $APT_CMD upgrade $APT_OPTIONS >>$OUTPUT 2>&1 && echo -e "${YELLOW}=====> installing packages ...${ENDCOLOUR}" && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/prereq.list | tr "\n" " ") >>$OUTPUT 2>&1 else # we need to install systemd first, to configure machine id $APT_CMD update >>$OUTPUT 2>&1 && echo -e "${YELLOW}=====> upgrading chroot system ...${ENDCOLOUR}" && $APT_CMD upgrade $APT_OPTIONS >dev/null && echo -e "${YELLOW}=====> installing packages ...${ENDCOLOUR}" && $APT_CMD install $APT_OPTIONS sudo libterm-readline-gnu-perl systemd-sysv >>$OUTPUT 2>&1 fi elif [ $DEBIAN_FRONTEND_TYPE = "dialog" ]; then if [ -f $SCRIPT_DIR/pkglists/prereq.list ]; then $APT_CMD update >>$OUTPUT 2>&1 && echo -e "${YELLOW}=====> upgrading chroot system ...${ENDCOLOUR}" && $APT_CMD upgrade $APT_OPTIONS >>$OUTPUT 2>&1 && echo -e "${YELLOW}=====> installing packages ...${ENDCOLOUR}" && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/prereq.list | tr "\n" " ") else # we need to install systemd first, to configure machine id $APT_CMD update >>$OUTPUT 2>&1 && echo -e "${YELLOW}=====> upgrading chroot system ...${ENDCOLOUR}" && $APT_CMD upgrade $APT_OPTIONS >dev/null && echo -e "${YELLOW}=====> installing packages ...${ENDCOLOUR}" && $APT_CMD install $APT_OPTIONS sudo libterm-readline-gnu-perl systemd-sysv fi fi } function main_pkg_list() { echo -e "${YELLOW}=====> installing main packages for chroot system ...${ENDCOLOUR}" if [ $DEBIAN_FRONTEND_TYPE = "noninteractive" ]; then if [ -f $SCRIPT_DIR/pkglists/main.list ]; then sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/main.list | tr "\n" " ") >>$OUTPUT 2>&1 else sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS ubuntu-minimal resolvconf xz-utils linux-image-generic >>$OUTPUT 2>&1 fi if [ $LIVE_TYPE = "ubuntu" ]; then if [ -f $SCRIPT_DIR/pkglists/ubuntu-main.list ]; then sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-main.list | tr "\n" " ") >>$OUTPUT 2>&1 fi if [ -f $SCRIPT_DIR/pkglists/ubuntu-gui.list ]; then sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-gui.list | tr "\n" " ") >>$OUTPUT 2>&1 fi if [ -f $SCRIPT_DIR/pkglists/ubuntu-ubiquity.list ]; then sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-ubiquity.list | tr "\n" " ") >>$OUTPUT 2>&1 fi fi elif [ $DEBIAN_FRONTEND_TYPE = "dialog" ]; then if [ -f $SCRIPT_DIR/pkglists/main.list ]; then $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/main.list | tr "\n" " ") else $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS ubuntu-minimal resolvconf xz-utils linux-image-generic fi if [ $LIVE_TYPE = "ubuntu" ]; then if [ -f $SCRIPT_DIR/pkglists/ubuntu-main.list ]; then $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-main.list | tr "\n" " ") fi if [ -f $SCRIPT_DIR/pkglists/ubuntu-gui.list ]; then $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-gui.list | tr "\n" " ") fi if [ -f $SCRIPT_DIR/pkglists/ubuntu-ubiquity.list ]; then $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-ubiquity.list | tr "\n" " ") fi fi fi } function other_pkg_list() { echo -e "${YELLOW}=====> installing other packages for chroot system ...${ENDCOLOUR}" if [ $DEBIAN_FRONTEND_TYPE = "noninteractive" ]; then if [ $LIVE_TYPE = "ubuntu" ]; then #$APT_CMD install $APT_OPTIONS tasksel >>$OUTPUT 2>&1 #tasksel install xubuntu-core #$APT_CMD autoremove $APT_OPTIONS tasksel >>$OUTPUT 2>&1 if [ -f $SCRIPT_DIR/pkglists/ubuntu-other.list ]; then sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-other.list | tr "\n" " ") >>$OUTPUT 2>&1 fi fi if [ -f $SCRIPT_DIR/pkglists/other.list ]; then sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/other.list | tr "\n" " ") >>$OUTPUT 2>&1 fi elif [ $DEBIAN_FRONTEND_TYPE = "dialog" ]; then if [ $LIVE_TYPE = "ubuntu" ]; then #$APT_CMD install $APT_OPTIONS tasksel >>$OUTPUT 2>&1 #tasksel install xubuntu-core #$APT_CMD autoremove $APT_OPTIONS tasksel >>$OUTPUT 2>&1 if [ -f $SCRIPT_DIR/pkglists/ubuntu-other.list ]; then $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/ubuntu-other.list | tr "\n" " ") fi fi if [ -f $SCRIPT_DIR/pkglists/other.list ]; then $APT_CMD update >>$OUTPUT 2>&1 && $APT_CMD install $APT_OPTIONS \ $(grep -vE "^\s*#" $SCRIPT_DIR/pkglists/other.list | tr "\n" " ") fi fi } function chroot_pkg_install() { current_process main_pkg_list other_pkg_list if [ $DEBIAN_FRONTEND_TYPE = "noninteractive" ]; then # configure console and keyboard cat </etc/default/console-setup # CONFIGURATION FILE FOR SETUPCON # Consult the console-setup(5) manual page. ACTIVE_CONSOLES="/dev/tty[1-6]" CHARMAP="UTF-8" CODESET="guess" FONTFACE="Fixed" FONTSIZE="8x16" VIDEOMODE= # The following is an example how to use a braille font # FONT='lat9w-08.psf.gz brl-8x8.psf' EOF cat </etc/default/keyboard # KEYBOARD CONFIGURATION FILE # Consult the keyboard(5) manual page. XKBMODEL="pc105" XKBLAYOUT="us,ru" XKBVARIANT="," XKBOPTIONS="grp:alt_shift_toggle,grp_led:scroll" BACKSPACE="guess" EOF dpkg-reconfigure -f noninteractive console-setup >>$OUTPUT 2>&1 # configure timezone and locale echo "Europe/Moscow" >/etc/timezone && dpkg-reconfigure -f noninteractive tzdata >>$OUTPUT 2>&1 && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen && echo 'LANG="ru_RU.UTF-8"' >/etc/default/locale && dpkg-reconfigure -f noninteractive locales >>$OUTPUT 2>&1 && update-locale LANG=ru_RU.UTF-8 >>$OUTPUT 2>&1 # configure resolvconf if grep resolvconf $SCRIPT_DIR/pkglists/main.list >>$OUTPUT 2>&1 || grep resolvconf $SCRIPT_DIR/pkglists/other.list || [ $DISTRIBUTION != "xenial" ] >>$OUTPUT 2>&1; then echo "resolvconf resolvconf/linkify-resolvconf boolean true" | debconf-set-selections dpkg-reconfigure resolvconf >>$OUTPUT 2>&1 fi elif [ $DEBIAN_FRONTEND_TYPE = "dialog" ]; then dpkg-reconfigure console-setup # configure timezone and locale dpkg-reconfigure tzdata dpkg-reconfigure locales dpkg-reconfigure localepurge localepurge # configure resolvconf if grep resolvconf $SCRIPT_DIR/pkglists/main.list >>$OUTPUT 2>&1 || grep resolvconf $SCRIPT_DIR/pkglists/other.list || [ $DISTRIBUTION != "xenial" ] >>$OUTPUT 2>&1; then dpkg-reconfigure resolvconf fi # network manager cat </etc/NetworkManager/NetworkManager.conf [main] rc-manager=resolvconf plugins=ifupdown,keyfile dns=dnsmasq [ifupdown] managed=false EOF dpkg-reconfigure network-manager fi # remove unused $APT_CMD autoremove $APT_OPTIONS >>$OUTPUT 2>&1 # clean up apt cache $APT_CMD clean $APT_OPTIONS >>$OUTPUT 2>&1 } function chroot_configure() { current_process if [ $LIVE_TYPE = "linux-live" ]; then (cd /linux-live/rootcopy && cp --parents -afr * /) echo "Set up password for user 'root'" >>$OUTPUT 2>&1 echo root:toor | chpasswd >>$OUTPUT 2>&1 echo "Set up user 'live'" >>$OUTPUT 2>&1 adduser --gecos '' live --disabled-password >>$OUTPUT 2>&1 echo "Set up password for user 'live'" >>$OUTPUT 2>&1 echo live:evil | chpasswd >>$OUTPUT 2>&1 addgroup live adm >>$OUTPUT 2>&1 addgroup live sudo >>$OUTPUT 2>&1 cat </etc/sudoerd.d/90-minios # live user is default user in minios. # It needs passwordless sudo functionality. live ALL=(ALL) NOPASSWD:ALL EOF echo "Enable dhclient.service autostart." >>$OUTPUT 2>&1 cat </lib/systemd/system/dhclient.service [Unit] Description=DHCP Client Documentation=man:dhclient(8) Wants=network.target After=network-pre.target systemd-sysctl.service systemd-modules-load.service Before=network.target shutdown.target network-online.target ConditionPathExists=!/run/initramfs/net.up.flag [Service] Type=forking ExecStart=-/bin/sh -c 'udevadm settle && dhclient -nw' PIDFile=/run/dhclient.pid [Install] WantedBy=multi-user.target WantedBy=network-online.target EOF systemctl enable dhclient >>$OUTPUT 2>&1 if [ -f /etc/systemd/system/multi-user.target.wants/grub-initrd-fallback.service ]; then echo "Disable grub-initrd-fallback.service autostart." >>$OUTPUT 2>&1 systemctl disable grub-initrd-fallback.service >>$OUTPUT 2>&1 fi elif [ $LIVE_TYPE = "ubuntu" ]; then (cd /linux-live/rootcopy-ubuntu && cp --parents -afr * /) #rm /etc/alternatives/default.plymouth #rm /etc/alternatives/text.plymouth update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/minios-logo/minios-logo.plymouth 200 update-alternatives --config default.plymouth --skip-auto #ln -s /usr/share/plymouth/themes/minios-logo/minios-logo.plymouth /etc/alternatives/default.plymouth #ln -s /usr/share/plymouth/themes/minios-logo/minios-text.plymouth /etc/alternatives/text.plymouth update-initramfs -u rm /usr/share/xfce4/backdrops/xubuntu-wallpaper.png ln -s /usr/share/backgrounds/MiniOS.png /usr/share/xfce4/backdrops/xubuntu-wallpaper.png : 'echo "Set up user 'ubuntu'" >>$OUTPUT 2>&1 adduser --gecos '' ubuntu --disabled-password >>$OUTPUT 2>&1 echo "Set up password for user 'ubuntu'" >>$OUTPUT 2>&1 echo ubuntu:ubuntu | chpasswd >>$OUTPUT 2>&1 addgroup ubuntu adm >>$OUTPUT 2>&1 addgroup ubuntu sudo >>$OUTPUT 2>&1 addgroup ubuntu lpadmin >>$OUTPUT 2>&1 addgroup ubuntu plugdev >>$OUTPUT 2>&1 addgroup ubuntu dip >>$OUTPUT 2>&1 #addgroup ubuntu samba >>$OUTPUT 2>&1' #sed -i "s,managed=false,managed=true,g" /etc/NetworkManager/NetworkManager.conf fi if grep openssh-server $SCRIPT_DIR/pkglists/main.list >>$OUTPUT 2>&1 || grep openssh-server $SCRIPT_DIR/pkglists/other.list >>$OUTPUT 2>&1; then echo "Enable ssh.service autostart." >>$OUTPUT 2>&1 cat </lib/systemd/system/ssh-keygen.service [Unit] Description=Generate sshd keys Before=ssh.service [Service] Type=oneshot ExecStart=/usr/bin/ssh-keygen -A RemainAfterExit=true StandardOutput=journal [Install] WantedBy=multi-user.target EOF systemctl enable ssh-keygen >>$OUTPUT 2>&1 systemctl enable ssh >>$OUTPUT 2>&1 fi } function chroot_finish_up() { current_process # truncate machine id (why??) truncate -s 0 /etc/machine-id >>$OUTPUT 2>&1 # remove diversion (why??) rm /sbin/initctl >>$OUTPUT 2>&1 dpkg-divert --rename --remove /sbin/initctl >>$OUTPUT 2>&1 # remove ssh config #rm -f /etc/ssh/ssh_host* # clean up useless stuff rm -rf /tmp/* ~/.bash_history >>$OUTPUT 2>&1 find /var/log/ -type f | xargs rm -f >>$OUTPUT 2>&1 rm -f /etc/ssh/ssh_host* rm -f /var/backups/* >>$OUTPUT 2>&1 rm -f /var/cache/ldconfig/* >>$OUTPUT 2>&1 rm -f /var/cache/debconf/* >>$OUTPUT 2>&1 rm -f /var/cache/fontconfig/* >>$OUTPUT 2>&1 rm -f /var/cache/apt/archives/*.deb >>$OUTPUT 2>&1 rm -f /var/cache/apt/*.bin >>$OUTPUT 2>&1 rm -f /var/cache/debconf/*-old >>$OUTPUT 2>&1 rm -f /var/lib/apt/extended_states >>$OUTPUT 2>&1 rm -f /var/lib/apt/lists/*Packages >>$OUTPUT 2>&1 rm -f /var/lib/apt/lists/*Translation* >>$OUTPUT 2>&1 rm -f /var/lib/apt/lists/*InRelease >>$OUTPUT 2>&1 rm -f /var/lib/apt/lists/deb.* >>$OUTPUT 2>&1 rm -f /var/lib/dpkg/*-old >>$OUTPUT 2>&1 } if [ grep ]; then echo fi