Attempt to re-run failing commands

This should help when something fails but may work after a short
wait and retry, we also check stderr output of each and compare.
If they are different both will be shown otherwise just the first.
This commit is contained in:
natemaia 2019-12-20 10:05:03 -08:00
parent b440669527
commit 13e41a9a68

View File

@ -8,7 +8,7 @@
# check for syntax errors
# set -n
VER=2.1.6
VER=2.1.7
# default values {
@ -646,14 +646,14 @@ part_auto()
while read -r PART; do
[[ $PART ]] || continue
parted -s "$device" rm "$PART" > /dev/null 2> "$ERR"
errshow 0 "parted -s $device rm $PART" || return 1
errshow 0 "parted -s '$device' rm '$PART' > /dev/null" || return 1
done <<< "$(awk '/^ [1-9][0-9]?/ {print $1}' <<< "$dev_info" | sort -r)"
[[ $(awk '/Table:/ {print $3}' <<< "$dev_info") != "$label" ]] && parted -s "$device" mklabel "$label" > /dev/null 2> "$ERR"
msg "Auto Partition" "\nCreating a 512M $boot_fs boot partition.\n" 1
parted -s "$device" mkpart "$boot_type" "$boot_fs" 1MiB 513MiB > /dev/null 2> "$ERR"
errshow 0 "parted -s $device mkpart $boot_type $boot_fs 1MiB 513MiB" || return 1
errshow 0 "parted -s '$device' mkpart '$boot_type' '$boot_fs' 1MiB 513MiB > /dev/null" || return 1
sleep 0.5
BOOT_D="$device"
@ -661,19 +661,19 @@ part_auto()
if [[ $SYS == "BIOS" ]]; then
mkfs.ext4 -q "$AUTO_BOOT" > /dev/null 2> "$ERR"
errshow 0 "mkfs.ext4 -q $AUTO_BOOT" || return 1
errshow 0 "mkfs.ext4 -q '$AUTO_BOOT' > /dev/null" || return 1
else
mkfs.vfat -F32 "$AUTO_BOOT" > /dev/null 2> "$ERR"
errshow 0 "mkfs.vfat -F32 $AUTO_BOOT" || return 1
errshow 0 "mkfs.vfat -F32 '$AUTO_BOOT' > /dev/null" || 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> "$ERR"
errshow 0 "parted -s $device mkpart primary ext4 513MiB 100%" || return 1
errshow 0 "parted -s '$device' mkpart primary ext4 513MiB 100% > /dev/null" || return 1
sleep 0.5
AUTO_ROOT="$(lsblk -lno NAME,TYPE "$device" | awk 'NR==3 {print "/dev/" $1}')"
mkfs.ext4 -q "$AUTO_ROOT" > /dev/null 2> "$ERR"
errshow 0 "mkfs.ext4 -q $AUTO_ROOT" || return 1
errshow 0 "mkfs.ext4 -q '$AUTO_ROOT' > /dev/null" || return 1
sleep 0.5
msg "Auto Partition" "\nProcess complete.\n\n$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE "$device")\n"
}
@ -720,7 +720,7 @@ part_shrink()
*)
e2fsck -f "$part"; sleep 0.5
resize2fs -f "$part" ${size}K 2> "$ERR" # K=2^10 bytes
errshow 0 "resize2fs -f $part ${size}K" || return 1
errshow 0 "resize2fs -f '$part' ${size}K" || return 1
;;
esac
sleep 0.5
@ -729,10 +729,10 @@ part_shrink()
sleep 0.5
if [[ $devsize == "$end" ]]; then
parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2> "$ERR"
errshow 0 "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
errshow 0 "parted -s '$device' mkpart primary ext4 ${size}KiB 100%" || return 1
else
parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2> "$ERR"
errshow 0 "parted -s $device mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
errshow 0 "parted -s '$device' mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
fi
msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n" 1
;;
@ -787,14 +787,14 @@ part_swap()
{
if [[ $1 == "$MNT/swapfile" && $SWAP_S ]]; then
fallocate -l $SWAP_S "$1" 2> "$ERR"
errshow 0 "fallocate -l $SWAP_S $1"
errshow 0 "fallocate -l '$SWAP_S' '$1'"
chmod 600 "$1" 2> "$ERR"
errshow 0 "chmod 600 $1"
errshow 0 "chmod 600 '$1'"
fi
mkswap "$1" > /dev/null 2> "$ERR"
errshow 0 "mkswap $1"
errshow 0 "mkswap '$1' > /dev/null"
swapon "$1" > /dev/null 2> "$ERR"
errshow 0 "swapon $1"
errshow 0 "swapon '$1' > /dev/null"
return 0
}
@ -809,10 +809,10 @@ part_mount()
if [[ $fs && ${FS_OPTS[$fs]} && $part != "$BOOT" && $part != "$AUTO_ROOT" ]] && select_mntopts "$fs"; then
mount -o "$MNT_OPTS" "$part" "$mntpt" > /dev/null 2> "$ERR"
errshow 0 "mount -o $MNT_OPTS $part $mntpt" || return 1
errshow 0 "mount -o '$MNT_OPTS' '$part' '$mntpt' > /dev/null" || return 1
else
mount "$part" "$mntpt" > /dev/null 2> "$ERR"
errshow 0 "mount $part $mntpt" || return 1
errshow 0 "mount '$part' '$mntpt' > /dev/null" || return 1
fi
msg "Mount Complete" "\nPartition $part mounted at $mntpt\n" 1
@ -831,7 +831,7 @@ part_format()
msg "Format" "\nFormatting $part as $fs\n" 0
mkfs.$fs ${FS_CMD_FLAGS[$fs]} "$part" > /dev/null 2> "$ERR"
errshow 0 "mkfs.$fs ${FS_CMD_FLAGS[$fs]} "$part"" || return 1
errshow 0 "mkfs.$fs ${FS_CMD_FLAGS[$fs]} '$part' > /dev/null" || return 1
sleep $delay
}
@ -1170,7 +1170,7 @@ install_main()
{
install_base
genfstab -U "$MNT" > "$MNT/etc/fstab" 2> "$ERR"
errshow 1 "genfstab -U $MNT > $MNT/etc/fstab"
errshow 1 "genfstab -U '$MNT' > '$MNT/etc/fstab'"
[[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" "$MNT/etc/fstab"
install_packages
install_tearfree "$MNT/etc/X11/xorg.conf.d"
@ -1182,7 +1182,7 @@ install_main()
chrun "chown -Rf $NEWUSER:users /home/$NEWUSER"
if [[ "$USER_CMD" ]]; then
chrun "$USER_CMD" 2> "$ERR" 2>&1
errshow 0 "$USER_CMD"
errshow 0 "chrun '$USER_CMD'"
fi
while :; do
@ -1248,8 +1248,8 @@ install_base()
[[ $DIST != "ArchLabs" ]] || sed -i "s/ArchLabs/$DIST/g" "$MNT/etc/"{lsb-release,os-release}
# vmlinuz, if this isn't copied the standard kernel may fail mkinitcpio
cp -vf "$RUN/x86_64/vmlinuz" "$MNT/boot/vmlinuz-linux" 2> "$ERR" 2>&1
errshow 1 "cp -vf $RUN/x86_64/vmlinuz $MNT/boot/vmlinuz-linux"
cp -vf "$RUN/x86_64/vmlinuz" "$MNT/boot/vmlinuz-linux" 2> "$ERR"
errshow 1 "cp -vf '$RUN/x86_64/vmlinuz' '$MNT/boot/vmlinuz-linux'"
# copy network settings
[[ -d /etc/netctl ]] && cp -rfv /etc/netctl "$MNT/etc/"
@ -1313,7 +1313,7 @@ install_boot()
prerun_$BOOTLDR
chrun "${BCMDS[$BOOTLDR]}" 2> "$ERR" 2>&1
errshow 1 "${BCMDS[$BOOTLDR]}"
errshow 1 "chrun '${BCMDS[$BOOTLDR]}'"
if [[ -d $MNT/hostrun ]]; then
echo "Unmounting chroot directories"
@ -1345,19 +1345,19 @@ install_user()
rm -f "$MNT/root/.zlogin" # remove welcome message
chrun "chpasswd <<< 'root:$ROOT_PASS'" 2> "$ERR" 2>&1
errshow 1 "set root password"
errshow 1 "chrun 'chpasswd <<< \"root:$ROOT_PASS\"'"
if [[ $MYSHELL != 'zsh' ]]; then # root uses zsh by default
chrun "usermod -s /bin/$MYSHELL root" 2> "$ERR" 2>&1
errshow 1 "usermod -s /bin/$MYSHELL root"
errshow 1 "chrun 'usermod -s /bin/$MYSHELL root'"
# copy the default mkshrc to /root if it was selected
[[ $MYSHELL == 'mksh' ]] && cp -fv "$MNT/etc/skel/.mkshrc" "$MNT/root/.mkshrc"
fi
echo "Creating new user $NEWUSER and setting password"
chrun "useradd -m -u 1000 -g users -G $groups -s /bin/$MYSHELL $NEWUSER" 2> "$ERR" 2>&1
errshow 1 "useradd -m -u 1000 -g users -G $groups -s /bin/$MYSHELL $NEWUSER"
errshow 1 "chrun 'useradd -m -u 1000 -g users -G $groups -s /bin/$MYSHELL $NEWUSER'"
chrun "chpasswd <<< '$NEWUSER:$USER_PASS'" 2> "$ERR" 2>&1
errshow 1 "set $NEWUSER password"
errshow 1 "chrun 'chpasswd <<< \"$NEWUSER:$USER_PASS\"'"
[[ $INSTALL_WMS == *dwm* ]] && install_suckless "/home/$NEWUSER" chroot
@ -1380,8 +1380,8 @@ install_login()
if [[ $LOGIN_TYPE != 'xinit' ]]; then
[[ $INSTALL_WMS == *dwm* ]] && dwm_xsession
rm -rf "$AUTOLOGIN_SERV" "$MNT/home/$NEWUSER/.xinitrc"
chrun "systemctl enable $LOGIN_TYPE.service" 2> "$ERR" 2>&1
errshow 1 "systemctl enable $LOGIN_TYPE.service"
chrun "systemctl enable $LOGIN_TYPE.service" 2> "$ERR"
errshow 1 "chrun 'systemctl enable $LOGIN_TYPE.service'"
fi
${LOGIN_TYPE}_config
@ -1440,7 +1440,7 @@ install_packages()
# update and install crucial packages first to avoid issues
al_repo "$MNT/etc/pacman.conf"
chrun "pacman -Syyu $KERNEL $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed" 2> "$ERR" 2>&1
errshow 1 "pacman -Syyu $KERNEL $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed"
errshow 1 "chrun 'pacman -Syyu $KERNEL $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed'"
# remove the packages we don't want on the installed system
[[ $rmpkg ]] && chrun "pacman -Rnsc $rmpkg --noconfirm"
@ -1450,19 +1450,19 @@ install_packages()
# install the packages chosen throughout the install
chrun "pacman -S $inpkg --needed --noconfirm" 2> "$ERR" 2>&1
errshow 1 "pacman -S $inpkg --needed --noconfirm"
errshow 1 "chrun 'pacman -S $inpkg --needed --noconfirm'"
# bootloader packages
if [[ $BOOTLDR == 'grub' ]]; then
[[ $SYS == 'UEFI' ]] && local efib="efibootmgr"
chrun "pacman -S os-prober grub $efib --needed --noconfirm" 2> "$ERR" 2>&1
errshow 1 "pacman -S os-prober grub $efib --needed --noconfirm"
errshow 1 "chrun 'pacman -S os-prober grub $efib --needed --noconfirm'"
elif [[ $BOOTLDR == 'refind-efi' ]]; then
chrun "pacman -S refind-efi efibootmgr --needed --noconfirm" 2> "$ERR" 2>&1
errshow 1 "pacman -S refind-efi efibootmgr --needed --noconfirm"
errshow 1 "chrun 'pacman -S refind-efi efibootmgr --needed --noconfirm'"
elif [[ $SYS == 'UEFI' ]]; then
chrun "pacman -S efibootmgr --needed --noconfirm" 2> "$ERR" 2>&1
errshow 1 "pacman -S efibootmgr --needed --noconfirm"
errshow 1 "chrun 'pacman -S efibootmgr --needed --noconfirm'"
fi
if [[ $VM ]] && dmesg | grep -qi 'vbox'; then
@ -1596,7 +1596,7 @@ install_mkinitcpio()
[[ $LVM ]] && add+=" lvm2"
sed -i "s/block filesystems/block${add} filesystems ${HOOKS}/g" "$MNT/etc/mkinitcpio.conf"
chrun "mkinitcpio -p $KERNEL" 2> "$ERR" 2>&1
errshow 1 "mkinitcpio -p $KERNEL"
errshow 1 "chrun 'mkinitcpio -p $KERNEL'"
}
install_mirrorlist()
@ -1739,12 +1739,12 @@ prerun_grub()
if [[ $LUKS_DEV ]]; then
sed -i "s~#GRUB_ENABLE_CRYPTODISK~GRUB_ENABLE_CRYPTODISK~g; s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g" "$MNT/etc/default/grub" 2> "$ERR" 2>&1
errshow 1 "sed -i 's~#GRUB_ENABLE_CRYPTODISK~GRUB_ENABLE_CRYPTODISK~g; s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g' $MNT/etc/default/grub"
errshow 1 "sed -i 's~#GRUB_ENABLE_CRYPTODISK~GRUB_ENABLE_CRYPTODISK~g; s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g' '$MNT/etc/default/grub'"
fi
if [[ $SYS == 'BIOS' && $LVM && -z $SEP_BOOT ]]; then
sed -i "s/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g" "$MNT/etc/default/grub" 2> "$ERR" 2>&1
errshow 1 "sed -i 's/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g' $MNT/etc/default/grub"
errshow 1 "sed -i 's/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g' '$MNT/etc/default/grub'"
fi
# setup for os-prober module
@ -1789,11 +1789,8 @@ prerun_syslinux()
d='';
fi
mkdir -pv "$c" 2> "$ERR" 2>&1
errshow 1 "mkdir -pv $c"
cp -rfv "$s/"* "$c/" 2> "$ERR" 2>&1
errshow 1 "cp -rfv $s/* $c/"
cp -fv "$RUN/syslinux/splash.png" "$c/" 2> "$ERR" 2>&1
errshow 0 "cp -fv $RUN/syslinux/splash.png $c/"
cat > "$c/syslinux.cfg" <<- EOF
UI vesamenu.c32
MENU TITLE $DIST Boot Menu
@ -1939,7 +1936,7 @@ lvm_detect()
if [[ $(lvs -o vg_name,lv_name --noheading --separator - 2> /dev/null) && $(pvs -o pv_name --noheading 2> /dev/null) ]]; then
msg "LVM Setup" "\nActivating existing logical volume management.\n" 0
modprobe dm-mod > /dev/null 2> "$ERR"
errshow 0 'modprobe dm-mod'
errshow 0 'modprobe dm-mod > /dev/null'
vgscan > /dev/null 2>&1
vgchange -ay > /dev/null 2>&1
fi
@ -1958,7 +1955,7 @@ lvm_create()
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" || return 1
errshow 0 "lvcreate -l +100%FREE '$VGROUP' -n '$VNAME' >/dev/null" || 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,MODEL,TYPE,FSTYPE,SIZE $LVM_PARTS)\n"
@ -2031,7 +2028,7 @@ lvm_mkgroup()
msg "$_lvmnew" "\nCreating volume group: $VGROUP\n" 0
vgcreate -f "$VGROUP" $LVM_PARTS > /dev/null 2> "$ERR"
errshow 0 "vgcreate -f $VGROUP $LVM_PARTS" || return 1
errshow 0 "vgcreate -f '$VGROUP' $LVM_PARTS >/dev/null" || return 1
SIZE=$(vgdisplay "$VGROUP" | awk '/VG Size/ { gsub(/[^0-9.]/, ""); print int($0) }')
SIZE_UNIT="$(vgdisplay "$VGROUP" | awk '/VG Size/ { print substr($NF, 0, 1) }')"
@ -2086,7 +2083,7 @@ lvm_extra_lvs()
lvm_volume_name "$_lvmlvname" && lvm_lv_size || return 1
msg "$_lvmnew (LV:$VOL_COUNT)" "\nCreating a $VOLUME_SIZE volume $VNAME in $VGROUP\n" 0
lvcreate -L "$VOLUME_SIZE" "$VGROUP" -n "$VNAME" > /dev/null 2> "$ERR"
errshow 0 "lvcreate -L $VOLUME_SIZE $VGROUP -n $VNAME" || return 1
errshow 0 "lvcreate -L '$VOLUME_SIZE' '$VGROUP' -n '$VNAME'" || return 1
msg "$_lvmnew (LV:$VOL_COUNT)" "\nDone, logical volume (LV) $VNAME ($VOLUME_SIZE) has been created.\n"
(( VOL_COUNT-- ))
done
@ -2172,7 +2169,7 @@ luks_open()
luks_pass "$_luksopen" || return 1
msg "$_luksopen" "\nOpening encrypted partition: $LUKS_NAME\n\nUsing device/volume: $LUKS_PART\n" 0
cryptsetup open --type luks "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> "$ERR"
errshow 0 "cryptsetup open --type luks $LUKS_PART $LUKS_NAME" || return 1
errshow 0 "cryptsetup open --type luks '$LUKS_PART' '$LUKS_NAME' <<< '$LUKS_PASS'" || return 1
LUKS='encrypted'; luks_show
return 0
}
@ -2235,9 +2232,9 @@ luks_basic()
luks_setup || return 1
msg "$_luksnew" "\nCreating encrypted partition: $LUKS_NAME\n\nDevice or volume used: $LUKS_PART\n" 0
cryptsetup -q luksFormat "$LUKS_PART" <<< "$LUKS_PASS" 2> "$ERR"
errshow 0 "cryptsetup -q luksFormat $LUKS_PART" || return 1
errshow 0 "cryptsetup -q luksFormat '$LUKS_PART' <<< '$LUKS_PASS'" || return 1
cryptsetup open "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> "$ERR"
errshow 0 "cryptsetup open $LUKS_PART $LUKS_NAME" || return 1
errshow 0 "cryptsetup open '$LUKS_PART' '$LUKS_NAME' <<< '$LUKS_PASS'" || return 1
LUKS='encrypted'; luks_show
return 0
}
@ -2250,9 +2247,9 @@ luks_advanced()
[[ $cipher ]] || return 1
msg "$_luksadv" "\nCreating encrypted partition: $LUKS_NAME\n\nDevice or volume used: $LUKS_PART\n" 0
cryptsetup -q $cipher luksFormat "$LUKS_PART" <<< "$LUKS_PASS" 2> "$ERR"
errshow 0 "cryptsetup -q $cipher luksFormat $LUKS_PART" || return 1
errshow 0 "cryptsetup -q $cipher luksFormat '$LUKS_PART' <<< '$LUKS_PASS'" || return 1
cryptsetup open "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> "$ERR"
errshow 0 "cryptsetup open $LUKS_PART $LUKS_NAME" || return 1
errshow 0 "cryptsetup open '$LUKS_PART' '$LUKS_NAME' <<< '$LUKS_PASS'" || return 1
luks_show
return 0
fi
@ -2451,6 +2448,15 @@ debug()
DEBUG=true
}
errmsg()
{
local err=""
err="$(sed 's/[^[:print:]]//g; s/\[[0-9\;:]*\?m//g; s/==> //g; s/] ERROR:/]\nERROR:/g' "$ERR")"
[[ -z $err ]] && err="no error message was found"
printf "%s" "$err"
}
al_repo()
{
local conf="$1"
@ -2501,12 +2507,18 @@ errshow()
local fatal=$1
shift # always shift off the fatal level arg
local err="$(errmsg)"
local err=""
err="$(sed 's/[^[:print:]]//g; s/\[[0-9\;:]*\?m//g; s/==> //g; s/] ERROR:/]\nERROR:/g' "$ERR")"
[[ -z $err ]] && err="no error message was found"
# try to rerun the command to make sure it's consistently failing
sleep 1 && $1 > "$ERR"
[ $? -eq 0 ] && return 0
local err2="$(errmsg)"
local txt="\nCommand: $1\n\n\n\nError: $err\n\n"
if [[ $err == $err2 ]]; then # no need to show duplicate output
local txt="\nCommand: $1\n\n\n\nError:\n$err\n\n"
else
local txt="\nCommand: $1\n\n\n\nFirst run error:\n$err\n\nSecond run error:\n$err2\n\n"
fi
if (( fatal )); then
msg "Install Error" "${txt}Errors at this stage are fatal, the install cannot continue.\n"