OSDN Git Service

Don't allow skipping formatting root
[pacbang-linux/installer-arch.git] / archlabs-installer
index 1904d82..9494470 100755 (executable)
@@ -8,14 +8,13 @@
 # check for syntax errors
 # set -n
 
-VER=2.0.95
+VER=2.1.3
 
 # default values {
 
 : ${DIST=ArchLabs}                 # distro name if not set
 MNT=/mnt                           # installation root mountpoint
 ANS=/tmp/ans                       # dialog answer output file
-BOOTDIR=boot                       # location to mount boot partition
 FONT=ter-i16n                      # font used for the linux console
 HOOKS=shutdown                     # additional mkinitcpio HOOKS
 SEL=0                              # currently selected menu item
@@ -629,20 +628,23 @@ part_auto()
 
        msg "Auto Partition" "\nRemoving partitions on $device and setting table to $table\n" 1
 
-       dev_info="$(parted -s "$device" print)"
+       dev_info="$(parted -s "$device" print 2> /dev/null)"
 
        swapoff -a
        while read -r PART; do
-               parted -s "$device" rm "$PART" > /dev/null 2>&1
+               parted -s "$device" rm "$PART" > /dev/null 2> "$ERR"
+               errshow 0 "parted -s $device rm $PART" || return 1
        done <<< "$(awk '/^ [1-9][0-9]?/ {print $1}' <<< "$dev_info" | sort -r)"
 
-       [[ $(awk '/Table:/ {print $3}' <<< "$dev_info") != "$table" ]] && parted -s "$device" mklabel "$table" > /dev/null 2>&1
+       [[ $(awk '/Table:/ {print $3}' <<< "$dev_info") != "$table" ]] && parted -s "$device" mklabel "$table" > /dev/null 2> "$ERR"
 
        msg "Auto Partition" "\nCreating a 512M $boot_fs boot partition.\n" 1
        if [[ $SYS == "BIOS" ]]; then
-               parted -s "$device" mkpart primary "$boot_fs" 1MiB 513MiB > /dev/null 2>&1
+               parted -s "$device" mkpart primary "$boot_fs" 1MiB 513MiB > /dev/null 2> "$ERR"
+               errshow 0 "parted -s $device mkpart primary $boot_fs 1MiB 513MiB" || return 1
        else
-               parted -s "$device" mkpart ESP "$boot_fs" 1MiB 513MiB > /dev/null 2>&1
+               parted -s "$device" mkpart ESP "$boot_fs" 1MiB 513MiB > /dev/null 2> "$ERR"
+               errshow 0 "parted -s $device mkpart ESP $boot_fs 1MiB 513MiB" || return 1
        fi
 
        sleep 0.5
@@ -650,16 +652,20 @@ part_auto()
        AUTO_BOOT_PART=$(lsblk -lno NAME,TYPE "$device" | awk 'NR==2 {print "/dev/" $1}')
 
        if [[ $SYS == "BIOS" ]]; then
-               mkfs.ext4 -q "$AUTO_BOOT_PART" > /dev/null 2>&1
+               mkfs.ext4 -q "$AUTO_BOOT_PART" > /dev/null 2> "$ERR"
+               errshow 0 "mkfs.ext4 -q $AUTO_BOOT_PART" || return 1
        else
-               mkfs.vfat -F32 "$AUTO_BOOT_PART" > /dev/null 2>&1
+               mkfs.vfat -F32 "$AUTO_BOOT_PART" > /dev/null 2> "$ERR"
+               errshow 0 "mkfs.vfat -F32 $AUTO_BOOT_PART" || return 1
        fi
 
        msg "Auto Partition" "\nCreating a $size ext4 root partition.\n" 0
-       parted -s "$device" mkpart primary ext4 513MiB 100% > /dev/null 2>&1
+       parted -s "$device" mkpart primary ext4 513MiB 100% > /dev/null 2> "$ERR"
+       errshow 0 "parted -s $device mkpart primary ext4 513MiB 100%" || return 1
        sleep 0.5
        AUTO_ROOT_PART="$(lsblk -lno NAME,TYPE "$device" | awk 'NR==3 {print "/dev/" $1}')"
-       mkfs.ext4 -q "$AUTO_ROOT_PART" > /dev/null 2>&1
+       mkfs.ext4 -q "$AUTO_ROOT_PART" > /dev/null 2> "$ERR"
+       errshow 0 "mkfs.ext4 -q $AUTO_ROOT_PART" || return 1
        sleep 0.5
        msg "Auto Partition" "\nProcess complete.\n\n$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE "$device")\n"
 }
@@ -919,7 +925,7 @@ part_mountconf()
 
 mount_menu()
 {
-       msg "Mount Menu" "\nGathering device and partition information.\n" 0
+       msg "Mount Menu" "\nGathering device and partition information.\n" 1
        no_bg_install || return 0
        lvm_detect
        umount_dir "$MNT"
@@ -929,7 +935,7 @@ mount_menu()
        select_root_partition || { ROOT_PART=''; return 1; }
        select_boot_partition || { BOOT_PART=''; return 1; }
        if [[ $BOOT_PART ]]; then
-               part_mount "$BOOT_PART" "/$BOOTDIR" && SEP_BOOT=true || return 1
+               part_mount "$BOOT_PART" "/boot" && SEP_BOOT=true || return 1
                part_bootdev
        fi
        select_swap || return 1
@@ -1022,7 +1028,7 @@ select_filesystem()
        [[ $cur && $part == "$AUTO_ROOT_PART" ]] && return 0
 
        until [[ $fs ]]; do
-               if [[ $cur && $FORMATTED == *"$part"* ]]; then
+               if [[ $cur && $part != "$ROOT_PART" ]]; then
                        dlg fs menu "Filesystem" "$txt\nCurrent:  $cur" skip - ext4 - ext3 - ext2 - vfat - ntfs - f2fs - jfs - xfs - nilfs2 - reiserfs - || return 1
                else
                        dlg fs menu "Filesystem" "$txt" ext4 - ext3 - ext2 - vfat - ntfs - f2fs - jfs - xfs - nilfs2 - reiserfs - || return 1
@@ -1135,7 +1141,7 @@ select_extra_partitions()
                done <<< "$PARTS"
        fi
 
-       while (( COUNT > 0 )); do
+       while (( COUNT )); do
                part=''
                dlg part menu 'Mount Extra' "$_expart" 'done' 'finish mounting step' $PARTS || break
                if [[ $part == 'done' ]]; then
@@ -1163,7 +1169,7 @@ install_main()
        [[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" "$MNT/etc/fstab"
        install_packages
        # tear free configs, MUST be done after package install for nvidia
-       install_tearfree_conf "$MNT/etc/X11/xorg.conf.d"
+       [[ $TEARFREE ]] && install_tearfree_conf "$MNT/etc/X11/xorg.conf.d"
        install_mkinitcpio
        install_boot
        chrun "hwclock --systohc --utc" || chrun "hwclock --systohc --utc --directisa"
@@ -1294,8 +1300,8 @@ install_boot()
        if [[ $SYS == 'UEFI' ]]; then
                # remove our old install and generic BOOT/ dir
                echo "Removing conflicting boot directories"
-               find "$MNT/$BOOTDIR/EFI/" -maxdepth 1 -mindepth 1 -iname "$DIST" -type d -delete -printf "remove %p\n"
-               find "$MNT/$BOOTDIR/EFI/" -maxdepth 1 -mindepth 1 -iname 'BOOT' -type d -delete -printf "remove %p\n"
+               find "$MNT/boot/EFI/" -maxdepth 1 -mindepth 1 -iname "$DIST" -type d -delete -printf "remove %p\n"
+               find "$MNT/boot/EFI/" -maxdepth 1 -mindepth 1 -iname 'BOOT' -type d -delete -printf "remove %p\n"
        fi
 
        prerun_$BOOTLDR
@@ -1311,12 +1317,12 @@ install_boot()
 
        if [[ $SYS == 'UEFI' ]]; then
                # some UEFI firmware requires a generic esp/BOOT/BOOTX64.EFI
-               mkdir -pv "$MNT/$BOOTDIR/EFI/BOOT"
+               mkdir -pv "$MNT/boot/EFI/BOOT"
                case "$BOOTLDR" in
-                       grub) cp -fv "$MNT/$BOOTDIR/EFI/$DIST/grubx64.efi" "$MNT/$BOOTDIR/EFI/BOOT/BOOTX64.EFI" ;;
-                       syslinux) cp -rf "$MNT/$BOOTDIR/EFI/syslinux/"* "$MNT/$BOOTDIR/EFI/BOOT/" && cp -f "$MNT/$BOOTDIR/EFI/syslinux/syslinux.efi" "$MNT/$BOOTDIR/EFI/BOOT/BOOTX64.EFI" ;;
-                       refind-efi) sed -i '/#extra_kernel_version_strings/ c extra_kernel_version_strings linux-hardened,linux-zen,linux-lts,linux' "$MNT/$BOOTDIR/EFI/refind/refind.conf"
-                               cp -fv "$MNT/$BOOTDIR/EFI/refind/refind_x64.efi" "$MNT/$BOOTDIR/EFI/BOOT/BOOTX64.EFI" ;;
+                       grub) cp -fv "$MNT/boot/EFI/$DIST/grubx64.efi" "$MNT/boot/EFI/BOOT/BOOTX64.EFI" ;;
+                       syslinux) cp -rf "$MNT/boot/EFI/syslinux/"* "$MNT/boot/EFI/BOOT/" && cp -f "$MNT/boot/EFI/syslinux/syslinux.efi" "$MNT/boot/EFI/BOOT/BOOTX64.EFI" ;;
+                       refind-efi) sed -i '/#extra_kernel_version_strings/ c extra_kernel_version_strings linux-hardened,linux-zen,linux-lts,linux' "$MNT/boot/EFI/refind/refind.conf"
+                               cp -fv "$MNT/boot/EFI/refind/refind_x64.efi" "$MNT/boot/EFI/BOOT/BOOTX64.EFI" ;;
                esac
        fi
 
@@ -1345,12 +1351,12 @@ install_user()
        chrun "chpasswd <<< '$NEWUSER:$USER_PASS'" 2> "$ERR" 2>&1
        errshow 1 "set $NEWUSER password"
 
-       if [[ $INSTALL_WMS == *dwm* ]];then
+       if [[ $INSTALL_WMS == *dwm* ]]; then
                install_suckless "/home/$NEWUSER" chroot
                [[ $INSTALL_WMS == 'dwm' ]] && rm -rf "$MNT/home/$NEWUSER/.config/xfce4"
        fi
-       [[ $INSTALL_WMS == *jwm* ]] && cp -rf "$MNT/etc/system.jwmrc" "$MNT/home/$NEWUSER/.jwmrc"
-       [[ $INSTALL_WMS != *bspwm* && $INSTALL_WMS != *openbox* ]] && rm -rf "$MNT/home/$NEWUSER/.config/"{jgmenu,tint2}
+       [[ $INSTALL_WMS == *jwm* ]] && sed '7,14d; s/xlock -mode blank/i3-lock-fancy -p/g; s/root:1/rofi_run/g' "$MNT/etc/system.jwmrc" > "$MNT/home/$NEWUSER/.jwmrc"
+       [[ $INSTALL_WMS =~ (bspwm|openbox) ]] || rm -rf "$MNT/home/$NEWUSER/.config/"{jgmenu,tint2}
        [[ $USER_PKGS != *geany* ]] && rm -rf "$MNT/home/$NEWUSER/.config/geany"
        [[ $MYSHELL != 'bash' ]] && rm -rf "$MNT/home/$NEWUSER/.bash"*
        [[ $MYSHELL != 'zsh' ]] && rm -rf "$MNT/home/$NEWUSER/.z"*
@@ -1422,7 +1428,7 @@ install_packages()
                rmpkg+="zsh "
        fi
 
-       if [[ $INSTALL_WMS =~ (openbox|bspwm|i3-gaps|fluxbox) ]]; then
+       if [[ $INSTALL_WMS =~ (openbox|bspwm|i3-gaps|fluxbox|jwm|awesome) ]]; then
                inpkg+="$WM_BASE_PKGS "
        elif [[ $INSTALL_WMS == 'dwm' ]]; then # dwm only needs a very limited package set
                inpkg+="nitrogen polkit-gnome gnome-keyring dunst "
@@ -1472,7 +1478,8 @@ install_suckless()
 {
        local dir="$1/suckless"
        shift
-       if [[ $2 == 'chroot' ]]; then
+
+       if [[ $1 == 'chroot' ]]; then
                chrun "mkdir -pv '$dir'"
                for i in dwm dmenu st; do
                        if chrun "git clone 'https://git.suckless.org/$i' '$dir/$i'"; then
@@ -1666,7 +1673,7 @@ setup_grub()
                BCMDS[grub]="grub-install --recheck --force --target=i386-pc $BOOT_DEV"
        else
                BCMDS[grub]="mount -t efivarfs efivarfs /sys/firmware/efi/efivars > /dev/null 2>&1
-               grub-install --recheck --force --target=x86_64-efi --efi-directory=/$BOOTDIR --bootloader-id=$DIST"
+               grub-install --recheck --force --target=x86_64-efi --efi-directory=/boot --bootloader-id=$DIST"
                grep -q /sys/firmware/efi/efivars /proc/mounts || mount -t efivarfs efivarfs /sys/firmware/efi/efivars > /dev/null 2>&1
        fi
 
@@ -1709,7 +1716,7 @@ setup_efistub()
 
 prerun_efistub()
 {
-       BCMDS[systemd-boot]="mount -t efivarfs efivarfs /sys/firmware/efi/efivars > /dev/null 2>&1
+       BCMDS[efistub]="mount -t efivarfs efivarfs /sys/firmware/efi/efivars > /dev/null 2>&1
                efibootmgr -v -d $BOOT_DEV -p $BOOT_PART_NUM -c -L '${DIST} Linux' -l /vmlinuz-${KERNEL} \
                -u 'root=$ROOT_PART_ID rw $([[ $UCODE ]] && printf 'initrd=\%s.img ' "$UCODE")initrd=\initramfs-${KERNEL}.img'"
 }
@@ -2297,7 +2304,7 @@ live()
        pacman -Scc --noconfirm
        rm -rf /var/cache/pacman/pkg/*
        cp -rfT /etc/skel /root
-       install_tearfree_conf "/etc/X11/xorg.conf.d"
+       [[ $TEARFREE ]] && install_tearfree_conf "/etc/X11/xorg.conf.d"
        case "$ses" in
                plasma|gnome|cinnamon) sed -i '/super/d; /nitrogen/d; /compton/d' /root/.xprofile ;;
                dwm) sed -i '/super/d; /compton/d' /root/.xprofile ;;
@@ -2315,9 +2322,12 @@ usage()
        usage: $1 [-hdl] [session]
 
        options:
-               -h, --help     print this message and exit
-               -l, --live     install and setup a live session
-               -d, --debug    enable xtrace and log output to $DBG
+               -h, --help      print this message and exit
+               -l, --live      install and setup a live session
+               -d, --debug     enable xtrace and log output to $DBG
+               -t, --tearfree  install and setup drivers for nvidia or tearfree xorg configs for other vendors
+                                               if you experience boot issues with this option you can remove
+                                                   /etc/X11/xorg.conf.d/20-*.conf
 
        sessions:
                i3-gaps  - A fork of i3wm with more features including gaps
@@ -2553,10 +2563,11 @@ fi
 # trap ^C to perform cleanup
 trap 'printf "\n^C\n" && die 1' INT
 
-while getopts ":hl:d" OPT; do
+while getopts ":htl:d" OPT; do
        case "$OPT" in
                d) debug ;;
                h) usage "$0" ;;
+               t) TEARFREE=true ;;
                l)
                        if [[ "${!WM_SESSIONS[@]}" =~ $OPTARG ]]; then
                                live "$OPTARG"