diff options
| -rwxr-xr-x | iso/mkiso.sh | 114 | ||||
| -rw-r--r-- | iso/root/.profile | 2 | ||||
| -rwxr-xr-x | iso/root/installer.sh | 229 | ||||
| -rw-r--r-- | src/bootstrap.sh | 1 | 
4 files changed, 276 insertions, 70 deletions
| diff --git a/iso/mkiso.sh b/iso/mkiso.sh index 855c9dd..84a9782 100755 --- a/iso/mkiso.sh +++ b/iso/mkiso.sh @@ -1,20 +1,31 @@  #!/bin/sh  ISO_NAME="xilinux-$(date -u +%Y%m%d)" -ISO_LABEL="xilinux" +ISO_LABEL="XILINUX"  PUBLISHER="davidovski"  SYSLINUX_VER=6.04-pre1 -XI_ARGS="" +XI_ARGS="-yq" -chroot=/tmp/chroot -isoroot=/tmp/iso -iso_pkgs="linux linux-firmware base dracut grub mksh xipkg squashfs-tools lvm2 cryptsetup networkmanager stty xitui neofetch" +WORKDIR=/tmp/xiiso + +chroot=$WORKDIR/chroot +isoroot=$WORKDIR/iso +iso_pkgs="linux linux-firmware base dracut grub mksh xipkg squashfs-tools lvm2 cryptsetup networkmanager stty xitui neofetch vim nano gnupg dosfstools" + +cmdline="splash console=tty0 console=ttyS0,9600 root=live:CDLABEL=$ISO_LABEL rd.live.dir=/ rd.live.squashimg=filesystem.squashfs rd.live.debug=1 quiet" + +grub_mod="all_video disk part_gpt part_msdos linux normal configfile search search_label efi_gop fat iso9660 cat echo ls test true help gzio" + +mkdir -p $WORKDIR  create_basesystem () {      xi $XI_ARGS sync      xi $XI_ARGS -r "$chroot" bootstrap      xi $XI_ARGS -r "$chroot" install "$iso_pkgs" +} + +configure_system() {      cat > $chroot/etc/resolv.conf << EOF  nameserver 80.80.80.80 @@ -34,13 +45,18 @@ EOF      cat > $chroot/etc/conf.d/agetty << EOF  agetty_options="--autologin root --noclear"  EOF + +    xichroot $chroot rc-update add networkmanager  }  build_initramfs () {      kernel_version=$(ls $chroot/usr/lib/modules | tail -1) +    export kernel_version +      mkdir -p "$chroot"/var/tmp      xichroot "$chroot" dracut --nomdadmconf --nolvmconf --xz --add dmsquash-live --add bash --add convertfs --add pollcdrom --force --kver $kernel_version +  }  create_isoroot() { @@ -54,40 +70,94 @@ create_isoroot() {  install_syslinux () {      curl https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/Testing/$(echo $SYSLINUX_VER | cut -d'-' -f1)/syslinux-$SYSLINUX_VER.tar.xz > syslinux-$SYSLINUX_VER.tar.xz -    tar -C /tmp -xf syslinux-$SYSLINUX_VER.tar.xz +    tar -C $WORKDIR -xf syslinux-$SYSLINUX_VER.tar.xz      #cp syslinux-$SYSLINUX_VER -    cp /tmp/syslinux-$SYSLINUX_VER/bios/core/isolinux.bin $isoroot/isolinux/isolinux.bin -    cp /tmp/syslinux-$SYSLINUX_VER/bios/com32/elflink/ldlinux/ldlinux.c32 $isoroot/isolinux/ldlinux.c32 -} +    cp $WORKDIR/syslinux-$SYSLINUX_VER/bios/core/isolinux.bin $isoroot/isolinux/isolinux.bin +    cp $WORKDIR/syslinux-$SYSLINUX_VER/bios/com32/elflink/ldlinux/ldlinux.c32 $isoroot/isolinux/ldlinux.c32 -build_iso () {      cat > $isoroot/isolinux/isolinux.cfg << EOF  default 1  label 1      kernel /vmlinuz -    append initrd=/initrd.img splash console=tty0 console=ttyS0,9600 root=live:CDLABEL=xilinux rd.live.dir=/ rd.live.squashimg=filesystem.squashfs rd.live.debug=1 quiet +    append initrd=/initrd.img $cmdline +EOF +} + +build_grub_efi () { +    mkdir -p $isoroot/boot/grub +    cat > $isoroot/boot/grub/grub.cfg << EOF +    set timeout_style=hidden +    set timeout=0 +    menuentry "XiLinux" { +        linux	/vmlinuz $cmdline +        initrd	/initrd.img +    } +EOF +    cksum=$(md5sum $isoroot/boot/grub/grub.cfg | cut -d' ' -f1) + +    mkdir -p $isoroot/efi/boot + +    cat > $WORKDIR/grub_early.$cksum.cfg << EOF +	search --no-floppy --set=root --label "$ISO_LABEL" +	set prefix=(\$root)/boot/grub  EOF -    mksquashfs $chroot $isoroot/filesystem.squashfs -noappend -no-progress -e "/proc/*" -e "/dev/*" -e "/sys/*" -    genisoimage -r -V "$ISO_LABEL" -cache-inodes -J -l \ -        -allow-limited-size -udf \ -        -b isolinux/isolinux.bin -c isolinux/boot.cat \ -        -no-emul-boot -boot-load-size 4 -boot-info-table \ -        -p "$PUBLISHER <xi@davidovski.xyz>" \ -        -A "$ISO_LABEL" -o "$ISO_NAME.iso" $isoroot +    grub-mkimage \ +		--config="$WORKDIR/grub_early.$cksum.cfg" \ +		--prefix="/boot/grub" \ +		--output="$isoroot/efi/boot/bootx64.efi" \ +		--format="x86_64-efi" \ +		--compression="xz" \ +        $grub_mod + +    mformat -i $isoroot/boot/grub/efi.img -C -f 1440 -N 0 :: +    mcopy -i $isoroot/boot/grub/efi.img -s $isoroot/efi :: +} + +build_iso () { +    mksquashfs $chroot $isoroot/filesystem.squashfs -noappend -no-progress -e "/proc/*" -e "/dev/*" -e "/sys/*"  +    xorrisofs -output ${ISO_NAME}.iso \ +            -joliet \ +            -rational-rock \ +            -sysid LINUX \ +            -volid "$ISO_LABEL" \ +            -eltorito-boot isolinux/isolinux.bin \ +            -eltorito-catalog isolinux/boot.cat \ +            -no-emul-boot \ +            -boot-load-size 4 \ +            -boot-info-table \ +            -eltorito-alt-boot \ +            -e boot/grub/efi.img \ +            -no-emul-boot \ +            -isohybrid-gpt-basdat \ +            -follow-links \ +            $isoroot + + +    printf "ISO written to $ISO_NAME.iso\n"  }  [ "$#" = 0 ] && { +    steps="      create_basesystem +    configure_system      build_initramfs      create_isoroot -    install_syslinux +    install_syslinux  +    build_grub_efi       build_iso +    "  } || { -    for task in $*; do -        $task -    done +    steps="$*"  } + +for step in $steps; do +    $step || { +        printf "%s\n" "${RED}An error occured!" +        exit 1 +    } +done + diff --git a/iso/root/.profile b/iso/root/.profile index 6e29f99..44ccbe7 100644 --- a/iso/root/.profile +++ b/iso/root/.profile @@ -3,7 +3,7 @@ splash () {      echo "Welcome to xilinux"  } -[ "$(fgconsole 2>/dev/null)" = "1" ] && $HOME/installer.sh +[ "$(tty)" = "/dev/tty1" ] && $HOME/installer.sh  splash diff --git a/iso/root/installer.sh b/iso/root/installer.sh index bed9ce8..de06852 100755 --- a/iso/root/installer.sh +++ b/iso/root/installer.sh @@ -4,10 +4,37 @@  . /usr/lib/glyphs.sh  . /usr/lib/colors.sh +DEBUG_MODE=false +  logfile="installer.log" -default_packages="base linux xipkg dracut grub mksh sudo neofetch vim tzdata" +default_packages="base xipkg dracut grub doas neofetch vim tzdata mksh"  additional_services="networkmanager xorg iwd" +OPT_KERNEL="linux-libre" +OPT_BOOTSYSTEM="efi" +OPT_ENCRYPTION="none" + +welcome_splash () { +    t_radio "Welcome to the xilinux installer" "install xilinux" "network configuration" "exit to shell" + +    case "$T_RESULT" in +        "network configuration") +            t_clean +            nmtui +            t_init +            welcome_splash +            ;; +        "install xilinux") +            return 0 +            ;; +        *) +            t_clean +            exit 0 +            ;; +    esac +} + +  list_disks () {      lsblk -r | while read -r line; do          set - $line @@ -24,42 +51,89 @@ list_partitions () {  partition_disk () {      t_msg "Partitioning $1..." -    export EFI_PART=$11 -    export SYS_PART=$12 + +    # if is efi, create an efi partition +    efi= +    [ "$OPT_BOOTSYSTEM" = "efi" ] && { +        export EFI_PART=$11 +        export SYS_PART=$12 +        efi="type=ef, start=2048, size=210000" +    } || { +        export SYS_PART=$11 +    } +      export SWAP_PART=none +      echo "      unit: sectors      sector-size: 512 -    type=ef, start=2048, size=210000 +    $efi      type=83 -    " | sfdisk $1 >$logfile && +    " | sfdisk $1 >>$logfile &&      t_msg "Partitioned $1!"  } -welcome_splash () { -    t_radio "welcome to the xilinux installer" "continue" "exit to shell" -    [ "$T_RESULT" != "continue" ] && { -        t_clean -        exit 0 +detect_efi () { +    [ -d "/sys/firmware/efi" ] \ +        && OPT_BOOTSYSTEM="efi" \ +        || OPT_BOOTSYSTEM="bios" + +    t_yesno "Detected boot system as '$OPT_BOOTSYSTEM', is this correct?" || { +        [ $OPT_BOOTSYSTEM = "efi" ] \ +            && OPT_BOOTSYSTEM="bios" \ +            || OPT_BOOTSYSTEM="efi"      } +    return 0  } +encrypt_disk () { +    #t_yesno "${LIGHT_RED}Warning this will ${RED}irreversibly ${LIGHT_RED} erase all data.\n${BLUE}continue?" || { +        #partition_disks +        #return 1 +    #} +    #t_msg "Wiping disk $ROOT_DISK..." +    #printf "YES\n" | cryptsetup open --type plain -d /dev/urandom $ROOT_DISK to_be_wiped >> $logfile +    #dd if=/dev/zero of=/dev/mapper/to_be_wiped >> $logfile +    #cryptsetup close to_be_wiped >> $logfile + +    partition_disk $ROOT_DISK +    enter_password "disk encryption password" +    t_msg "Encrypting $ROOT_DISK.." +    printf "$passwd" | cryptsetup luksFormat $SYS_PART -d ->> $logfile + +    printf "$passwd" | cryptsetup luksOpen $SYS_PART cryptlvm -d - >> $logfile + +    pvcreate /dev/mapper/cryptlvm >> $logfile +    vgcreate xilinux /dev/mapper/cryptlvm >> $logfile +     +    lvcreate -l 100%FREE xilinux -n root >> $logfile + +    export SYS_PART=/dev/xilinux/root +    return 0 +}  partition_disks () {      # need to use eval to work with spaces in line names      eval "t_radio 'Select install disk' $(list_disks)"      local selected=$(echo $T_RESULT | cut -d' ' -f1) +    export ROOT_DISK=$selected -    t_yesno "${BLUE}Auto-partition $selected disk?\n${RED}(Warning: existing data will be overwritten)" &&  { +    t_yesno "${BLUE}Use full disk encryption?" && { +        export OPT_ENCRYPTION="lvm-luks" +        encrypt_disk $ROOT_DISK +        return 0 +    } || t_yesno "${BLUE}Auto-partition $selected disk?\n${RED}(Warning: existing data will be overwritten)" &&  {          partition_disk $selected || return 1      } || {          cfdisk $selected && {              t_radio 'Select primary system partition' $(list_partitions $selected)              export SYS_PART=$T_RESULT -            t_radio 'Select efi system partition' $(list_partitions $selected) -            export EFI_PART=$T_RESULT +            [ $OPT_BOOTSYSTEM = "efi" ] && { +                t_radio 'Select efi system partition' $(list_partitions $selected) +                export EFI_PART=$T_RESULT +            }              t_radio 'Select swap partition' $(list_partitions $selected)              export SWAP_PART=$T_RESULT @@ -74,26 +148,26 @@ ${TABCHAR}EFI Partition  " -    [ -b "$SYS_PART" ] && mkfs.ext4 $SYS_PART > $logfile +    [ -b "$SYS_PART" ] && mkfs.ext4 $SYS_PART >> $logfile      t_msg "Formatting partitions...  ${GREEN}${TABCHAR}System partition ${CHECKMARK} (ext4)  ${TABCHAR}EFI Partition  " -    [ -b "$EFI_PART" ] && mkfs.fat -F 32 $EFI_PART > $logfile +    [ -b "$EFI_PART" ] && mkfs.fat -F 32 $EFI_PART >> $logfile      t_msg "Formatting partitions...  ${GREEN}${TABCHAR}System partition ${CHECKMARK} (ext4)  ${GREEN}${TABCHAR}EFI Partition ${CHECKMARK} (fat32)  " -    [ -b "$SWAP_PART" ] && mkswap $SWAP_PART > $logfile +    [ -b "$SWAP_PART" ] && mkswap $SWAP_PART >> $logfile      return 0  }  mount_disks () {      t_msg "Mounting disks..."      export sysroot=/xilinux.mnt -    export efi_mntpoint=/xilinux.mnt/boot/efi +    export efi_mntpoint=/xilinux.mnt/boot      [ ! -f "$sysroot" ] && mkdir -p $sysroot @@ -104,6 +178,7 @@ mount_disks () {          return 1      } +    echo "[efi] mounting $EFI_PART to $efi_mntpoint" >> $logfile      [ -b "$EFI_PART" ] && {          mkdir -p $efi_mntpoint          mount $EFI_PART $efi_mntpoint @@ -113,15 +188,25 @@ mount_disks () {      return 0  } +prompt_kernel () { +    t_radio "Select which kernel you would like to use:" "linux-libre" "linux" +    OPT_KERNEL=$T_RESULT +} +  bootstrap_system () {      t_msg "Creating directories..." -    xi -vy -r $sysroot bootstrap >> $logfile +    xi -qvy -r $sysroot bootstrap >> $logfile  }  install_base () { -    t_msg "Installing packages..." -    xi -vy -r $sysroot sync >> $logfile -    xi -vy -r $sysroot install $default_packages >> $logfile +    { +        t_msg "Syncing repos..." +        xi -qvy -r $sysroot sync >> $logfile  +        for pkg in $default_packages $OPT_KERNEL; do  +            t_msg "${BLUE}Installing packages...${RESET}$pkg" +            xi -qlvy -r $sysroot install $pkg >> $logfile +        done +    }   }  copy_resolvconf () { @@ -140,46 +225,63 @@ generate_fstab () {  }  build_initramfs () { -    t_msg "Build initramfs" - -    kernel_version=$(ls $SYSROOT/usr/lib/modules | tail -1)      mkdir -p $sysroot/var/tmp -    xichroot $sysroot dracut --kver $kernel_version 2>&1 >> $logfile +    for kernel_version in $(ls $sysroot/usr/lib/modules); do  +        t_msg "Building initramfs for $kernel_version..." +        xichroot $sysroot dracut --kver $kernel_version 2>&1 >> $logfile +    done  }  install_grub () {      t_yesno "Install grub?" && { -        target="x86_64-efi" -        opts="--target=$target --efi-directory=$efi_mntpoint" - -        t_yesno "Install as removable system?" && opts="$opts --removable" +        [ "$OPT_BOOTSYSTEM" = "efi" ] && { +                target="x86_64-efi" +                opts="--target=$target --efi-directory=$efi_mntpoint"  +                t_yesno "Install as removable system?" && opts="--removable $opts " || true +            } || { +                target="i386-pc" +                opts="--target=$target $ROOT_DISK" +            }          t_msg "Installing grub for target $target..." -        xichrooot $sysroot grub-install $opts >> $logfile +        xichroot $sysroot grub-install $opts >> $logfile          t_msg "Creating grub configuration..." -        xichrooot $sysroot grub-mkconfig -o /boot/grub/grub.cfg +        xichroot $sysroot grub-mkconfig -o /boot/grub/grub.cfg + +        t_prompt "Installed grub for $target"      } || return 0  } +configure_hostname () { +    t_input "Enter hostname:" +    local hostname=$T_RESULT +    echo $hostname > $sysroot/etc/hostname + +    cat > $sysroot/etc/hosts << EOF +127.0.0.1   localhost +::1         localhost +127.0.1.1   $hostname.local $hostname +EOF +} +  enter_password () { +    local label=${1:-password}      export passwd="" -    t_input_hidden "Enter Password:" +    t_input_hidden "Enter $label:"      passwd=$T_RESULT -    t_input_hidden "Confirm Password:" +    t_input_hidden "Confirm $label"      local cpasswd=$T_RESULT      [ "$passwd" = "$cpasswd" ] || {          t_prompt "Passwords do not match!" -        enter_password +        enter_password $*      }  }  configure_users () { -    t_input_cmd "xichroot $sysroot passwd" "Enter root password" -      t_input "Enter username:"      local username=$T_RESULT      enter_password @@ -188,8 +290,9 @@ configure_users () {      xichroot $sysroot useradd -s /bin/mksh -m $username      printf "$passwd\n$passwd\n" | xichroot $sysroot passwd $username -    t_yesno "Allow this user to use sudo?" && { -        echo "$username ALL=(ALL:ALL) ALL" >> $sysroot/etc/sudoers +    t_yesno "Allow this user to use doas?" && { +        mkdir -p $sysroot/etc/doas.d/ +        echo "permit persist david" >> $sysroot/etc/doas.d/doas.conf      }      t_yesno "Set a password for the root user?" && { @@ -244,7 +347,7 @@ select_timezone () {  install_additional () {      t_check "Install and configure additional services: " $additional_services -    local services=$T_RESULT +    local services="$T_RESULT"      for service in $services; do          service_$service @@ -254,7 +357,7 @@ install_additional () {  service_networkmanager () {      t_msg "Installing NetworkManager..."      { -        xi -ly -r $sysroot install networkmanager  +        xi -qvly -r $sysroot install networkmanager           xichroot $sysroot rc-update add networkmanager      } >> $logfile  } @@ -262,48 +365,83 @@ service_networkmanager () {  service_iwd () {      t_msg "Installing iwd..."      { -        xi -ly -r $sysroot install iwd  +        xi -qvly -r $sysroot install iwd           xichroot $sysroot rc-update add iwd      } >> $logfile  }  service_xorg () {      t_msg "Installing xorg..." -    xi -r $sysroot install base-xorg base-fonts >> $logfile -    t_check "Select video drivers:" $(xi search xd86-video- | cut -f2 -d/) -    [ "${#T_RESULT}" != "0" ] && xi -r $sysroot install $T_RESULT +    xi -qvly -r $sysroot install base-xorg base-fonts >> $logfile +    t_check "Select video drivers:" $(xi search xf86-video- | cut -f2 -d/) +    [ "${#T_RESULT}" != "0" ] && xi -r $sysroot install $T_RESULT >> $logfile      t_prompt "Installed basic xorg functionality  TODO: preconfigured window managers, for now you need to configure them yourself"  } +prompt_shell () { +    t_yesno "Would you like to drop into the shell of your new system before rebooting?" && { +        t_clean +        xichroot $sysroot /bin/mksh -l +        t_init +        t_no_cur +        t_cls_ptrn +    } +    return 0 +}  umount_disks () { +    t_msg "Unmounting disks..."      umount -R $sysroot      [ -b "$SWAP_PART" ] && swapoff $SWAP_PART +    [ "$OPT_ENCRYPTION" = "lvm-luks"] && cryptsetup close cryptlvm      return 0  } +prompt_reboot () { +    t_yesno "Install complete, reboot?" && { +        t_clean +        reboot & exit 0 +    } +} +  t_init  t_no_cur  checkroot   steps="welcome_splash +detect_efi  partition_disks  format_disks  mount_disks +prompt_kernel  bootstrap_system  install_base  copy_resolvconf +configure_hostname +select_timezone  sync_system  generate_fstab  build_initramfs +install_grub  configure_users  fix_permissions -select_timezone  install_additional +prompt_shell  umount_disks +prompt_reboot  " +$DEBUG_MODE && { +    echo > $logfile + +    { +        tail -f $logfile | while read -r line; do +            t_tail $logfile  +        done  +    } & +} +  for step in $steps; do      t_cls_ptrn      $step 2>> $logfile || { @@ -313,5 +451,4 @@ for step in $steps; do      }  done  t_prompt "Completed install!" -  t_clean diff --git a/src/bootstrap.sh b/src/bootstrap.sh index 7215d9b..d82380d 100644 --- a/src/bootstrap.sh +++ b/src/bootstrap.sh @@ -58,7 +58,6 @@ bootstrap () {      if [ -e ${SYSROOT} ] && [ "$(ls -1 ${SYSROOT})" != "0" ]; then          if prompt_question "${WHITE}System already exists on ${SYSROOT}, clear?"; then -            umount -r ${SYSROOT}/*              rm -rf ${SYSROOT}/*          fi      fi | 
