From 3112c82cff96cefe5964d1ef0190c9ca4c6156eb Mon Sep 17 00:00:00 2001 From: crims0n Date: Sat, 16 Jan 2021 21:19:20 +0300 Subject: [PATCH] added docker support --- .build_dir | 2 +- autoinstall | 65 +++++++++ install | 13 +- linux-live/config | 2 +- linux-live/minioslib | 223 +++++++++++++++++++------------ linux-live/pkglists/hostreq.list | 8 +- 6 files changed, 216 insertions(+), 97 deletions(-) create mode 100644 autoinstall diff --git a/.build_dir b/.build_dir index db990e2..46f7482 100644 --- a/.build_dir +++ b/.build_dir @@ -1 +1 @@ -/build/bionic +/build/focal diff --git a/autoinstall b/autoinstall new file mode 100644 index 0000000..a4cfe9d --- /dev/null +++ b/autoinstall @@ -0,0 +1,65 @@ +#!/bin/bash + +set -e # exit on error +set -o pipefail # exit on pipeline error +set -u # treat unset variable as error + +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +PARENT_DIR="$(dirname "$SCRIPT_DIR")" +ISO_DIR="$(dirname "$SCRIPT_DIR")"/iso + +. $SCRIPT_DIR/linux-live/minioslib || exit 1 +. $SCRIPT_DIR/linux-live/config || exit 1 + +OUTPUT="/dev/stdout" + +UNATTENDED="1" + +CMD=(setup_host build_bootstrap build_chroot build_live build_iso) + +# ============= main ================ + +BUILD_DIR="" + +common_variables + +console_colours + +allow_root_only + +create_livekitname_install_symlink + +create_completion + +create_backup + +# check number of args +if [[ $# == 0 || $# > 3 ]]; then help; fi + +# loop through args +dash_flag=false +start_index=0 +end_index=${#CMD[*]} +for ii in "$@"; do + if [[ $ii == "-" ]]; then + dash_flag=true + continue + fi + find_index $ii + if [[ $dash_flag == false ]]; then + start_index=$index + else + end_index=$(($index + 1)) + fi +done +if [[ $dash_flag == false ]]; then + end_index=$(($start_index + 1)) +fi + +#loop through the commands +for ((ii = $start_index; ii < $end_index; ii++)); do + setup_build_dir + ${CMD[ii]} +done + +echo -e "${BOLD}${LIGHTYELLOW}$0${ENDCOLOUR} - ${LIGHTGREEN}Command completed successfully!${ENDCOLOUR}" diff --git a/install b/install index b1d87a8..726b817 100755 --- a/install +++ b/install @@ -7,13 +7,18 @@ set -u # treat unset variable as error SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" PARENT_DIR="$(dirname "$SCRIPT_DIR")" ISO_DIR="$(dirname "$SCRIPT_DIR")"/iso -#ISO_DIR=$SCRIPT_DIR/iso -#ISO_DIR=/build/nfs/iso . $SCRIPT_DIR/linux-live/minioslib || exit 1 -#. $SCRIPT_DIR/linux-live/installlib || exit 1 . $SCRIPT_DIR/linux-live/config || exit 1 +# normal +#OUTPUT="/dev/stdout" +# log +OUTPUT="/var/log/$LIVEKITNAME.log" + +# don't change! use ./autoinstall instead +UNATTENDED="0" + CMD=(setup_host build_bootstrap build_chroot build_live build_iso) # ============= main ================ @@ -26,7 +31,7 @@ console_colours allow_root_only -create_livekitnameinstall_symlink +create_livekitname_install_symlink create_completion diff --git a/linux-live/config b/linux-live/config index 547ef8e..681ccbb 100644 --- a/linux-live/config +++ b/linux-live/config @@ -21,7 +21,7 @@ SYSTEMNAME="MiniOS" SYSTEMVER="2021" # -DISTRIBUTION="bionic" +DISTRIBUTION="focal" # DISTRIBUTION_ARCH="amd64" diff --git a/linux-live/minioslib b/linux-live/minioslib index 5822953..077bb4d 100644 --- a/linux-live/minioslib +++ b/linux-live/minioslib @@ -11,11 +11,6 @@ # ================================================================= function common_variables() { - # normal - # OUTPUT="/dev/stdout" - # log - OUTPUT="/var/log/$LIVEKITNAME.log" - # if = "1", creates a second iso with a constant filename # если ="1", создаёт второй iso с постоянным именем файла BUILD_TEST_ISO="1" @@ -147,7 +142,7 @@ function find_index() { help "Command not found : $1" } -function create_livekitnameinstall_symlink() { +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 @@ -181,19 +176,21 @@ function create_livekitnameinstall_symlink() { } function create_completion() { - 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 + 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 ompletion only works when using the ${CYAN}$LIVEKITNAME-install${ENDCOLOUR} command." - echo -e + 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 ompletion only works when using the ${CYAN}$LIVEKITNAME-install${ENDCOLOUR} command." + echo -e + fi fi fi } @@ -234,12 +231,16 @@ 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}" - 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 + 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 } @@ -251,29 +252,39 @@ function check_mounted() { function check_build_dir() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." - # ▼ должно быть только перенаправление ошибки! - if [ "$(ls -A $BUILD_DIR 2>>$OUTPUT)" != "" ]; 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 + 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 - 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}." + # ▼ должно быть только перенаправление ошибки! + 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 } @@ -284,31 +295,61 @@ function check_build_dir() { function setup_build_dir() { echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..." - 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 - 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 + if [ $UNATTENDED = "1" ]; then + BUILD_DIR="/build/$DISTRIBUTION" + 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 + BUILD_DIR=$PARENT_DIR/$DISTRIBUTION fi check_build_dir else - BUILD_DIR="$LAST_BUILD_DIR" - check_build_dir + 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 @@ -422,6 +463,12 @@ function create_apt_list() { function build_bootstrap() { current_process + if [ -f /.dockerenv ]; 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 } @@ -464,6 +511,12 @@ function copy_build_scripts() { function build_chroot() { current_process + if [ -f /.dockerenv ]; then + if [ ! -f /.minios-live ]; then + setup_host + fi + fi + chroot_mount_fs copy_build_scripts @@ -497,6 +550,12 @@ function build_chroot() { function build_live() { current_process + if [ -f /.dockerenv ]; then + if [ ! -f /.minios-live ]; then + setup_host + fi + fi + remove_log_file copy_build_scripts @@ -515,6 +574,12 @@ EOF function build_iso() { current_process + if [ -f /.dockerenv ]; then + if [ ! -f /.minios-live ]; then + setup_host + fi + fi + copy_build_scripts check_build_dir @@ -581,24 +646,6 @@ function build_iso() { exit 0 } -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 - read -r -p "$(echo -e ""Do you want to ${BOLD}${RED}remove content${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 -} - # ================================================================= # ================================================================= # ====================== INSTALL FUNCTIONS ======================== @@ -629,15 +676,21 @@ function chroot_setup_host() { function hostreq_pkg_list() { echo -e "${YELLOW}=====> installing required software for host system ...${ENDCOLOUR}" + $APT_CMD update >>$OUTPUT 2>&1 && + if [ -f /.dockerenv ]; then + touch /.minios-live + $APT_CMD install -y wget >>$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 + fi if [ -f $SCRIPT_DIR/linux-live/pkglists/hostreq.list ]; then - sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ - $APT_CMD update >>$OUTPUT 2>&1 && - $APT_CMD install -y \ - $(grep -vE "^\s*#" $SCRIPT_DIR/linux-live/pkglists/hostreq.list | tr "\n" " ") >>$OUTPUT 2>&1 + #sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ + $APT_CMD install -y \ + $(grep -vE "^\s*#" $SCRIPT_DIR/linux-live/pkglists/hostreq.list | tr "\n" " ") >>$OUTPUT 2>&1 else - sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ - $APT_CMD update >>$OUTPUT 2>&1 && - $APT_CMD install -y binutils debootstrap squashfs-tools xorriso grub-pc-bin grub-efi-$DISTRIBUTION_ARCH-bin mtools >>$OUTPUT 2>&1 + #sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \ + $APT_CMD install -y sudo debootstrap xorriso >>$OUTPUT 2>&1 fi } diff --git a/linux-live/pkglists/hostreq.list b/linux-live/pkglists/hostreq.list index 3fcfe29..9b09c87 100644 --- a/linux-live/pkglists/hostreq.list +++ b/linux-live/pkglists/hostreq.list @@ -1,8 +1,4 @@ # Приложения, необходимые хостовой системе для сборки. -#binutils +sudo debootstrap -#squashfs-tools -xorriso -#grub-pc-bin -#grub-efi-amd64-bin -#mtools \ No newline at end of file +xorriso \ No newline at end of file