From c30b103b82a72a09d0d352047a1709e251eda7fd Mon Sep 17 00:00:00 2001 From: natemaia Date: Sun, 17 May 2020 09:36:29 -0700 Subject: [PATCH] Rename script, cleanup btrfs functions and simplify --- README.md | 2 +- archlabs-installer => installer | 224 ++++++++++++++++---------------- 2 files changed, 113 insertions(+), 113 deletions(-) rename archlabs-installer => installer (95%) diff --git a/README.md b/README.md index db23915..af1c3c1 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ #### Manual Installation ``` -curl -fSL https://bitbucket.org/archlabslinux/installer/raw/master/archlabs-installer -o /usr/bin/archlabs-installer +curl -fSL https://bitbucket.org/archlabslinux/installer/raw/master/installer -o /usr/bin/installer ``` --- diff --git a/archlabs-installer b/installer similarity index 95% rename from archlabs-installer rename to installer index d620977..cba9309 100755 --- a/archlabs-installer +++ b/installer @@ -259,7 +259,7 @@ declare -A FS_CMD_FLAGS=( [ntfs]='-q' [reiserfs]='-q' [vfat]='-F32' -[xfs]='-f' +[xfs]='-fq' ) # } # mount options for each filesystem { @@ -315,7 +315,7 @@ _device="\nSelect a device to use from the list below.\n\nDevices (/dev) are the _mount="\nUse [Space] to toggle mount options from below, press [Enter] when done to confirm selection.\n\nNot selecting any and confirming will run an automatic mount." _warn="\nIMPORTANT: Choose carefully when editing, formatting, and mounting partitions or your DATA MAY BE LOST.\n\nTo mount a partition without formatting it, select 'skip' when prompted to choose a file system during the mounting stage.\nThis can only be used for partitions that already contain a file system and cannot be the root (/) partition, it needs to be formatted before install.\n" _part="\nFull device auto partitioning is available for beginners otherwise cfdisk is recommended.\n\n - All systems will require a root partition (8G or greater).\n - UEFI or BIOS using LUKS without LVM require a separate boot partition (100-512M)." -_btrfs="\nBtrfs can create branching subvolumes.\n\nAn initial subvolume will be created and mounted with additional subvolumes branching from this created after.\nOtherwise you can skip directly to mounting options.\n\nCreate subvolumes?\n" +_btrfs="\nBtrfs can be used with or without the use of subvolumes.\n\nAn initial subvolume will be created and mounted with additional subvolumes branching from this created after.\n\nUse subvolumes?\n" _uefi="\nSelect the EFI boot partition (/boot), required for UEFI boot.\n\nIt's usually the first partition on the device, 100-512M, and will be formatted as vfat/fat32 if not already." _bios="\nDo you want to use a separate boot partition? (optional)\n\nIt's usually the first partition on the device, 100-512M, and will be formatted as ext3/4 if not already." _biosluks="\nSelect the boot partition (/boot), required for LUKS.\n\nIt's usually the first partition on the device, 100-512M, and will be formatted as ext3/4 if not already." @@ -357,7 +357,7 @@ _lvmdelask="\nConfirm deletion of volume group(s) and logical volume(s).\n\nDele # Errors _errexpart="\nCannot mount partition due to a problem with the mountpoint.\n\nEnsure it begins with a slash (/) followed by at least one character.\n" _errpart="\nYou need to create the partition(s) first.\n\n\nBIOS systems require at least one partition (ROOT).\n\nUEFI systems require at least two (ROOT and EFI).\n" -_errchoice="\nIf you want to fix the issue yourself use Ctrl-z to pause the installer. From there you can do whatever is needed to resolve the error.\nOnce finished use the 'fg' command to resume the installer, then select 'Continue'.\n" +_errchoice="\nIf you want to fix the issue yourself use Ctrl-z to pause the installer.\nFrom there you can do whatever is needed to resolve the error.\nOnce finished use the 'fg' command to resume the installer and select 'Continue'.\n" _lukserr="\nA minimum of two partitions are required for encryption:\n\n 1. root (/) - standard or LVM.\n 2. boot (/boot) - standard (unless using LVM on BIOS systems).\n" _lvmerr="\nThere are no viable partitions available to use for LVM, a minimum of one is required.\n\nIf LVM is already in use, deactivating it will allow the partition(s) to be used again.\n" _lvmerrvgname="\nInvalid name entered.\n\nThe volume group name may be alpha-numeric, but may not contain spaces, start with a '/', or already be in use.\n" @@ -1036,30 +1036,24 @@ part_swap() part_mount() { local part="$1" - local mntpt="${MNT}$2" - local ignore=0 - [[ $part == "$ROOT" && $3 ]] && ignore=$3 + local mntp="${MNT}$2" local fs fs="$(lsblk -lno FSTYPE "$part")" - mkdir -p "$mntpt" + mkdir -p "$mntp" - if [[ $ignore -ne 2 && $fs && ${FS_OPTS[$fs]} && $part != "$BOOT" && $part != "$AUTO_ROOT" ]] && select_mntopts "$fs"; then - mount -o $MNT_OPTS "$part" "$mntpt" > /dev/null 2> "$ERR" || mount -o $MNT_OPTS "$part" "$mntpt" > /dev/null 2> "$ERR" - errshow 0 "mount -o $MNT_OPTS $part $mntpt" || return 1 + if [[ $BTRFS -ne 2 && $fs && ${FS_OPTS[$fs]} && $part != "$BOOT" && $part != "$AUTO_ROOT" ]] && select_mntopts "$part" "$fs"; then + mount -o $MNT_OPTS "$part" "$mntp" > /dev/null 2> "$ERR" || mount -o $MNT_OPTS "$part" "$mntp" > /dev/null 2> "$ERR" + errshow 0 "mount -o $MNT_OPTS $part $mntp" || return 1 else - mount "$part" "$mntpt" > /dev/null 2> "$ERR" || mount "$part" "$mntpt" > /dev/null 2> "$ERR" - errshow 0 "mount $part $mntpt" || return 1 + mount "$part" "$mntp" > /dev/null 2> "$ERR" || mount "$part" "$mntp" > /dev/null 2> "$ERR" + errshow 0 "mount $part $mntp" || return 1 + MNT_OPTS='' fi - if grep -q "$mntpt" /proc/mounts; then - msg "Mount Success" "\n$part mounted at $mntpt\n" 1 - part_countdec "$part" - part_cryptlv "$part" - else - msg "Mount Failed" "\nUnable to mount $part at $mntpt\n" 2 - return 1 - fi + msg "Mount Complete" "\nMounted $part at $mntp\n" 1 + part_countdec "$part" + part_cryptlv "$part" return 0 } @@ -1103,7 +1097,6 @@ part_format() local part="$1" local fs="$2" local delay="$3" - shift 3 if [[ $fs == 'f2fs' && -z $PF2FS ]]; then modprobe f2fs @@ -1327,16 +1320,15 @@ select_boot() select_root() { + local pts dev size isize ptcount=0 + if [[ -z $ROOT ]]; then if [[ $AUTO_ROOT && -z $LVM && -z $LUKS ]]; then ROOT="$AUTO_ROOT" msg "Mount Menu" "\nUsing partitions created during automatic format.\n" 2 - part_mount "$ROOT" || { ROOT=''; return 1; } + part_mount "$ROOT" || { AUTO_ROOT='' ROOT=''; return 1; } return 0 # we're done here - else - local pts dev size isize ptcount=0 - - # walk partition list and skip ones that are < 8G + else # walk partition list and skip ones that are < 8G while read -r dev size; do s=${size%%__*} size_t="${s: -1:1}" @@ -1361,13 +1353,14 @@ select_root() if [[ $ROOT ]]; then select_filesystem "$ROOT" || return 1 - part_mount "$ROOT" "" $BTRFS || return 1 + part_mount "$ROOT" || return 1 if (( BTRFS == 2 )); then btrfs_subvols "$ROOT" || return 1 fi BTRFS=0 return 0 fi + # should never reach here unless an error occurred ROOT='' return 1 @@ -1441,7 +1434,7 @@ select_extra() dlg part menu 'Mount Extra' "$_expart" 'done' 'finish mounting step' $PARTS || break if [[ $part == 'done' ]]; then break - elif select_filesystem "$part" && select_mountpoint && part_mount "$part" "$EXMNT" $BTRFS; then + elif select_filesystem "$part" && select_mountpoint && part_mount "$part" "$EXMNT"; then if (( BTRFS == 2 )); then btrfs_subvols "$part" "$EXMNT" || return 1 fi @@ -1458,11 +1451,12 @@ select_extra() select_mntopts() { - local fs="$1" + local part="$1" + local fs="$2" local opts='' local title="${fs^} Mount Options" - yesno "$title" "\nMount partition with default options?\n" && return 1 + yesno "$title" "\nMount $part with default mount options?\n" && return 1 for i in ${FS_OPTS[$fs]}; do opts+="$i - off " done @@ -1470,7 +1464,7 @@ select_mntopts() dlg MNT_OPTS check "$title" "$_mount" $opts [[ $MNT_OPTS ]] || return 1 # no options is auto mount MNT_OPTS="${MNT_OPTS// /,}" - yesno "$title" "\nConfirm the following options: $MNT_OPTS\n" || MNT_OPTS='' + yesno "$title" "\nConfirm mount options: $MNT_OPTS\n" || MNT_OPTS='' done return 0 } @@ -1550,9 +1544,12 @@ install_main() install_login # changing distro name? - if [[ $DIST != "ArchLabs" ]]; then + if grep -q 'ArchLabs' "$MNT/etc/lsb-release"; then sed -i "s/ArchLabs/$DIST/g" "$MNT/etc/lsb-release" sed -i "s/ArchLabs/$DIST/g" "$MNT/etc/os-release" + else + sed -i "s/Arch/$DIST/g" "$MNT/etc/lsb-release" + sed -i "s/Arch/$DIST/g" "$MNT/etc/os-release" fi # allow members of the wheel group to run commands as root @@ -2385,15 +2382,14 @@ prerun_systemd-boot() btrfs_name() { local txt="$1" - local def="$2" - local match="$3" + local match="$2" SUBVOL='' until [[ $SUBVOL ]]; do - dlg SUBVOL input "Subvolume Name" "$txt" "$def" || return 1 + dlg SUBVOL input "Subvolume Name" "$txt" || return 1 if [[ -z $SUBVOL ]]; then return 1 - elif [[ $SUBVOL =~ \ |\' || $match == *"$SUBVOL"* || $SUBVOL == "$MVOL" ]]; then + elif [[ $SUBVOL =~ \ |\' || $match == *"$SUBVOL"* ]]; then msg "Subvolume Name Error" "$_btrfserrname" SUBVOL='' fi @@ -2401,48 +2397,47 @@ btrfs_name() return 0 } +btrfs_extsubvols() +{ + local mntp="$1" + local mvol="$2" + local list='' + local n=0 + + SUBVOL_COUNT=0 + dlg SUBVOL_COUNT menu "Subvolume Count" "\nSelect the number of subvolumes to create in: $mvol" \ + 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - + while (( ++n <= SUBVOL_COUNT )); do + local txt="\nEnter a name for subvolume $n within '$mvol'." + if (( n > 1 )); then + btrfs_name "$txt\n\nCreated subvolumes: $list" "$list $mvol" || return 1 + else + btrfs_name "$txt" "$mvol" || return 1 + fi + btrfs subvolume create "$mntp/$SUBVOL" > /dev/null 2> "$ERR" + errshow 0 "btrfs subvolume create $mntp/$SUBVOL" || return 1 + list+="$SUBVOL " + done + return 0 +} + btrfs_subvols() { local part="$1" - local mntp="$2" - local list='' opts='' s="${mntp//\//_}" n=1 - local txt="\nEnter a name for the initial subvolume.\n\nOnce mounted other subvolumes created for" + local mntp="${MNT}$2" + local mvol='' - btrfs_name "$txt $MNT${mntp} will branch from it." "subvol${s:-_root}" || return 1 - MVOL="$SUBVOL" - - mkdir -p "$MNT${mntp}" || return 1 - [[ -z $mntp ]] && BTRFS_MNT="rootflags=subvol=$MVOL" - - # create the main subvolume - btrfs subvolume create "$MNT${mntp}/$MVOL" > /dev/null 2> "$ERR" - errshow 0 "btrfs subvolume create $MNT${mntp}/$MVOL" || return 1 - umount "$part" 2> "$ERR" - errshow 0 "umount $part" || return 1 - - if select_mntopts 'btrfs' && [[ $MNT_OPTS ]]; then - opts="${MNT_OPTS},subvol=${MVOL}" - else - opts="subvol=${MVOL}" - fi - - mount -o $opts "$part" "$MNT${mntp}" 2> "$ERR" - errshow 0 "mount -o $opts $part $MNT${mntp}" || return 1 - grep -q "$MNT${mntp}" /proc/mounts || { msg "Mount Failed" "\nUnable to mount $part at $MNT${mntp}\n" 2; return 1; } - msg "Mount Complete" "\nSubvolume $MVOL mounted at $MNT${mntp}\n" 1 - - # create the subvolume(s) - until [[ $SUBVOL == '*' ]]; do - local txt="\nEnter a name for subvolume $n within '$MVOL' subvolume." - txt+="\n\nThis process will be repeated until an asterisk (*) is entered as the subvolume name." - btrfs_name "$txt\n\nCreated subvolumes: ${list:-none}\n" "subvol_$n" "$list" || return 1 - btrfs subvolume create "$MNT${mntp}/$MVOL/$SUBVOL" > /dev/null 2> "$ERR" - errshow 0 "btrfs subvolume create $MNT${mntp}/$MVOL/$SUBVOL" || return 1 - (( n++ )) - list+="$SUBVOL " - done - - msg "Btrfs Setup Complete" "\nBtrfs subvolumes:\n\n$(ls -R "$MNT${mntp}/$MVOL")" + btrfs_name "\nEnter a name for the initial subvolume on $part." || return 1 + mvol="$SUBVOL" + [[ $mntp == "$MNT" ]] && BTRFS_MNT="rootflags=subvol=$mvol" + btrfs subvolume create "$mntp/$mvol" > /dev/null 2> "$ERR" + errshow 0 "btrfs subvolume create $mntp/$mvol" || return 1 + umount_dir "$mntp" || return 1 + select_mntopts 'btrfs' && [[ $MNT_OPTS ]] && MNT_OPTS+=',' + mount -o ${MNT_OPTS}subvol=${mvol} "$part" "$mntp" 2> "$ERR" + errshow 0 "mount -o ${MNT_OPTS}subvol=${mvol} $part $mntp" || return 1 + btrfs_extsubvols "$mntp" "$mvol" || return 1 + msg "Btrfs Setup Complete" "\nCreated subvolumes:\n\n$(ls -R "$mntp/$mvol")" } ############################################################################### @@ -2485,18 +2480,21 @@ lvm_detect() lvm_create() { - VGROUP='' LVM_PARTS='' VGROUP_MB=0 + VGROUP='' LVM_PARTS='' VOL_COUNT=0 VGROUP_MB=0 umount_dir "$MNT" lvm_mkgroup || return 1 + local txt="\nThe last (or only) logical volume will automatically use all remaining space in the volume group." - dlg VOL_COUNT menu "$_lvmnew" "\nSelect the number of logical volumes (LVs) to create in: $VGROUP\n$txt" 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - + dlg VOL_COUNT menu "$_lvmnew" "\nSelect the number of logical volumes (LVs) to create in: $VGROUP\n$txt" \ + 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - [[ $VOL_COUNT ]] || return 1 lvm_extra_lvs || return 1 lvm_volume_name "$_lvmlvname\nNOTE: This LV will use up all remaining space in the volume group (${VGROUP_MB}MB)" || return 1 msg "$_lvmnew (LV:$VOL_COUNT)" "\nCreating volume $VNAME from remaining space in $VGROUP\n" 0 lvcreate -l +100%FREE "$VGROUP" -n "$VNAME" > /dev/null 2> "$ERR" - errshow 0 "lvcreate -l +100%FREE '$VGROUP' -n '$VNAME' >/dev/null" || return 1 - LVM='logical volume'; sleep 0.5 + errshow 0 "lvcreate -l +100%FREE $VGROUP -n $VNAME" || return 1 + LVM='logical volume' + sleep 0.5 txt="\nDone, volume: $VGROUP-$VNAME (${VOLUME_SIZE:-${VGROUP_MB}MB}) has been created.\n" msg "$_lvmnew (LV:$VOL_COUNT)" "$txt\n$(lsblk -o NAME,SIZE $LVM_PARTS)\n" return 0 @@ -2508,7 +2506,7 @@ lvm_lv_size() while :; do ERR_SIZE=0 - dlg VOLUME_SIZE input "$_lvmnew (LV:$VOL_COUNT)" "$txt" '' + dlg VOLUME_SIZE input "$_lvmnew (LV:$VOL_COUNT)" "$txt" if [[ -z $VOLUME_SIZE ]]; then ERR_SIZE=1 break # allow bailing with escape or an empty choice @@ -2643,7 +2641,7 @@ lvm_group_name() { VGROUP='' until [[ $VGROUP ]]; do - dlg VGROUP input "$_lvmnew" "$_lvmvgname" "lvgroup" + dlg VGROUP input "$_lvmnew" "$_lvmvgname" if [[ -z $VGROUP ]]; then return 1 elif [[ ${VGROUP:0:1} == "/" || $VGROUP =~ \ |\' ]] || vgdisplay | grep -q "$VGROUP"; then @@ -2657,10 +2655,9 @@ lvm_group_name() lvm_volume_name() { VNAME='' - local txt="$1" default="root" - (( VOL_COUNT > 1 )) && default="volume$VOL_COUNT" + local txt="$1" until [[ $VNAME ]]; do - dlg VNAME input "$_lvmnew (LV:$VOL_COUNT)" "\n$txt" "$default" + dlg VNAME input "$_lvmnew (LV:$VOL_COUNT)" "\n$txt" if [[ -z $VNAME ]]; then return 1 elif [[ ${VNAME:0:1} == "/" || $VNAME =~ \ |\' ]] || lsblk | grep -q "$VNAME"; then @@ -2841,20 +2838,23 @@ dlg() local l=$((LINES - 20)) (( ($# / 2) > l )) && n=$l - tput civis case "$dlg_t" in menu) + tput civis dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " $title " \ --menu "$body" 0 0 $n "$@" 2> "$ANS" || return 1 ;; check) + tput civis dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " $title " \ --checklist "$body" 0 0 $n "$@" 2> "$ANS" || return 1 ;; input) tput cnorm - local def="$1" # assign default value for input - shift + if [[ $1 && $1 != 'limit' ]]; then + local def="$1" # assign default value for input + shift + fi if [[ $1 == 'limit' ]]; then dialog --backtitle "$DIST Installer - $SYS - v$VER" --max-input 63 \ --title " $title " --inputbox "$body" 0 0 "$def" 2> "$ANS" || return 1 @@ -2949,30 +2949,30 @@ usage() usage: $1 [-hDn] [-r ROOT] [-b BOOT] [-l SESSION] [-d DISTRO] [-m MOUNTPOINT] options: - -h print this message and exit - -l install and setup a live session - -D enable xtrace and log output to $DBG - -m set the mountpoint used for the new installation - -d set the distribution name for the installed system - -n no partitioning, mounting, or formatting (self mount) - -r root partition to use for install, required when using -n - -b boot partition to use for install, required on UEFI systems when using -n - -t 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 + -h print this message and exit + -l install and setup a live session + -D enable xtrace and log output to $DBG + -m set the mountpoint used for the new installation + -d set the distribution name for the installed system + -n no partitioning, mounting, or formatting (self mount) + -r root partition to use for install, required when using -n + -b boot partition to use for install, required on UEFI systems when using -n + -t install and setup drivers for nvidia or tearfree xorg configs for other vendors + if you experience boot issues with this option, remove /etc/X11/xorg.conf.d/20-*.conf sessions: - i3-gaps - A fork of i3wm with more features including gaps - openbox - A lightweight, powerful, and highly configurable stacking wm - dwm - A dynamic WM for X that manages windows in tiled, floating, or monocle layouts - awesome - A customized Awesome WM session created by @elanapan - lxqt - A port of the lightweight desktop environment (LXDE) to Qt - bspwm - A tiling wm that represents windows as the leaves of a binary tree - fluxbox - A lightweight and highly-configurable window manager - jwm - A lightweight window manager for Xorg written in C - gnome - A desktop environment that aims to be simple and easy to use - cinnamon - A desktop environment combining traditional desktop with modern effects - plasma - A kde software project currently comprising a full desktop environment - xfce4 - A lightweight and modular desktop environment based on gtk+2/3 + i3-gaps - A fork of i3wm with more features including gaps + openbox - A lightweight, powerful, and highly configurable stacking wm + dwm - A dynamic WM for X that manages windows in tiled, floating, or monocle layouts + awesome - A customized Awesome WM session created by @elanapan + lxqt - A port of the lightweight desktop environment (LXDE) to Qt + bspwm - A tiling wm that represents windows as the leaves of a binary tree + fluxbox - A lightweight and highly-configurable window manager + jwm - A lightweight window manager for Xorg written in C + gnome - A desktop environment that aims to be simple and easy to use + cinnamon - A desktop environment combining traditional desktop with modern effects + plasma - A kde software project currently comprising a full desktop environment + xfce4 - A lightweight and modular desktop environment based on gtk+2/3 EOF exit 0 @@ -3071,7 +3071,7 @@ errshow() shift 1 # always shift off the fatal level arg local txt - txt="\nCommand: $1\n\n\n\nError:\n$(errmsg)\n\n" + txt="\nCommand: $1\n\n$(errmsg)\n\n" tput cnorm if (( fatal )); then dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Install Error " --yes-label "Abort" --no-label "Continue" \ @@ -3314,9 +3314,9 @@ fi # check for update once if [[ ! -f /tmp/new ]]; then msg "Installer Update" "\nChecking for newer installer versions.\n" 1 - if curl -fsSL https://bitbucket.org/archlabslinux/installer/raw/master/archlabs-installer -o /tmp/new; then - if (( $(vercmp "$(awk -F= '/^VER=/ {print $2}' /tmp/archlabs-installer)" "$VER") > 0 )); then - cp /tmp/new /usr/bin/archlabs-installer && exec archlabs-installer "$@" + if curl -fsSL https://bitbucket.org/archlabslinux/installer/raw/master/installer -o /tmp/new; then + if (( $(vercmp "$(awk -F= '/^VER=/ {print $2}' /tmp/new)" "$VER") > 0 )); then + cp /tmp/new /usr/bin/installer && exec installer "$@" die fi else