Redirect stderr to stdout after sending to error file

This commit is contained in:
natemaia 2019-10-27 14:56:08 -07:00
parent 9f10cce8e4
commit f51ab5171a

View File

@ -8,7 +8,7 @@
# check for syntax errors
# set -n
VER=2.0.92
VER=2.0.93
# default values {
@ -694,7 +694,7 @@ part_shrink()
case "$fs" in
ntfs)
if ntfsresize -fc "$part"; then
ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2> $ERR # k=10^3 bytes
ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2> "$ERR" # k=10^3 bytes
errshow "ntfsresize -f -s $(( (size * 1024) / 1000 ))k $part" || return 1
else
msg "Resize" "\nThe ntfs partition $part cannot be resized because it is scheduled for a consistency check.\n\nTo do a consistency check in windows open command prompt as admin and run:\n\n\tchkdsk /f /r /x\n"
@ -703,7 +703,7 @@ part_shrink()
;;
*)
e2fsck -f "$part"; sleep 0.5
resize2fs -f "$part" ${size}K 2> $ERR # K=2^10 bytes
resize2fs -f "$part" ${size}K 2> "$ERR" # K=2^10 bytes
errshow "resize2fs -f $part ${size}K" || return 1
;;
esac
@ -712,10 +712,10 @@ part_shrink()
(( size++ ))
sleep 0.5
if [[ $devsize == "$end" ]]; then
parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2> $ERR
parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2> "$ERR"
errshow "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
else
parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2> $ERR
parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2> "$ERR"
errshow "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
@ -760,14 +760,14 @@ part_find()
part_swap()
{
if [[ $1 == "$MNT/swapfile" && $SWAP_SIZE ]]; then
fallocate -l $SWAP_SIZE "$1" 2> $ERR
fallocate -l $SWAP_SIZE "$1" 2> "$ERR"
errshow "fallocate -l $SWAP_SIZE $1"
chmod 600 "$1" 2> $ERR
chmod 600 "$1" 2> "$ERR"
errshow "chmod 600 $1"
fi
mkswap "$1" > /dev/null 2> $ERR
mkswap "$1" > /dev/null 2> "$ERR"
errshow "mkswap $1"
swapon "$1" > /dev/null 2> $ERR
swapon "$1" > /dev/null 2> "$ERR"
errshow "swapon $1"
return 0
}
@ -795,7 +795,7 @@ part_format()
local part="$1" fs="$2" delay="$3"
msg "Format" "\nFormatting $part as $fs\n" 0
mkfs.$fs ${FS_CMD_FLAGS[$fs]} "$part" > /dev/null 2> $ERR
mkfs.$fs ${FS_CMD_FLAGS[$fs]} "$part" > /dev/null 2> "$ERR"
errshow "mkfs.$fs ${FS_CMD_FLAGS[$fs]} "$part"" || return 1
FORMATTED+="$part "
sleep $delay
@ -1145,7 +1145,7 @@ select_extra_partitions()
install_main()
{
install_base
genfstab -U "$MNT" > "$MNT/etc/fstab" 2> "$ERR" 2>&1
genfstab -U "$MNT" > "$MNT/etc/fstab" 2> "$ERR"
errshow 1 "genfstab -U $MNT > $MNT/etc/fstab"
[[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" "$MNT/etc/fstab"
install_packages
@ -1158,7 +1158,7 @@ install_main()
install_login
chrun "chown -Rf $NEWUSER:users /home/$NEWUSER"
if [[ "$USER_CMD" ]]; then
chrun "$USER_CMD" 2> "$ERR" 2>&1
chrun "$USER_CMD" > "$ERR" 2>&1
errshow 0 "$USER_CMD"
fi
@ -1222,7 +1222,7 @@ 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
cp -vf "$RUN/x86_64/vmlinuz" "$MNT/boot/vmlinuz-linux" > "$ERR" 2>&1
errshow 1 "cp -vf $RUN/x86_64/vmlinuz $MNT/boot/vmlinuz-linux"
# copy network settings
@ -1286,7 +1286,7 @@ install_boot()
fi
prerun_$BOOTLDR
chrun "${BCMDS[$BOOTLDR]}" 2> $ERR 2>&1
chrun "${BCMDS[$BOOTLDR]}" > "$ERR" 2>&1
errshow 1 "${BCMDS[$BOOTLDR]}"
if [[ -d $MNT/hostrun ]]; then
@ -1317,19 +1317,19 @@ install_user()
rm -f "$MNT/root/.zlogin" # remove welcome message
chrun "chpasswd <<< 'root:$ROOT_PASS'" 2> "$ERR" 2>&1
chrun "chpasswd <<< 'root:$ROOT_PASS'" > "$ERR" 2>&1
errshow 1 "set root password"
if [[ $MYSHELL != 'zsh' ]]; then # root uses zsh by default
chrun "usermod -s /bin/$MYSHELL root" 2> "$ERR" 2>&1
chrun "usermod -s /bin/$MYSHELL root" > "$ERR" 2>&1
errshow 1 "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
chrun "useradd -m -u 1000 -g users -G $groups -s /bin/$MYSHELL $NEWUSER" > "$ERR" 2>&1
errshow 1 "useradd -m -u 1000 -g users -G $groups -s /bin/$MYSHELL $NEWUSER"
chrun "chpasswd <<< '$NEWUSER:$USER_PASS'" 2> "$ERR" 2>&1
chrun "chpasswd <<< '$NEWUSER:$USER_PASS'" > "$ERR" 2>&1
errshow 1 "set $NEWUSER password"
if [[ $INSTALL_WMS == *dwm* ]];then
@ -1370,7 +1370,7 @@ install_login()
EOF
fi
rm -rf "$serv" "$MNT/home/$NEWUSER/.xinitrc"
chrun "systemctl enable $LOGIN_TYPE.service" 2> $ERR 2>&1
chrun "systemctl enable $LOGIN_TYPE.service" > "$ERR" 2>&1
errshow 1 "systemctl enable $LOGIN_TYPE.service"
${LOGIN_TYPE}_config
;;
@ -1416,7 +1416,7 @@ install_packages()
fi
# update and install crucial packages first to avoid issues
chrun "pacman -Syyu $KERNEL $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed" 2> $ERR 2>&1
chrun "pacman -Syyu $KERNEL $BASE_PKGS base-devel ${LOGIN_PKGS[$LOGIN_TYPE]} $MYSHELL --noconfirm --needed" > "$ERR" 2>&1
errshow 1 "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
@ -1426,19 +1426,19 @@ install_packages()
chrun "pacman -S iputils $UCODE --noconfirm"
# install the packages chosen throughout the install
chrun "pacman -S $inpkg --needed --noconfirm" 2> $ERR 2>&1
chrun "pacman -S $inpkg --needed --noconfirm" > "$ERR" 2>&1
errshow 1 "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
chrun "pacman -S os-prober grub $efib --needed --noconfirm" > "$ERR" 2>&1
errshow 1 "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
chrun "pacman -S refind-efi efibootmgr --needed --noconfirm" > "$ERR" 2>&1
errshow 1 "pacman -S refind-efi efibootmgr --needed --noconfirm"
elif [[ $SYS == 'UEFI' ]]; then
chrun "pacman -S efibootmgr --needed --noconfirm" 2> $ERR 2>&1
chrun "pacman -S efibootmgr --needed --noconfirm" > "$ERR" 2>&1
errshow 1 "pacman -S efibootmgr --needed --noconfirm"
fi
@ -1486,7 +1486,7 @@ install_mkinitcpio()
[[ $LUKS ]] && add="encrypt"
[[ $LVM ]] && { [[ $add ]] && add+=" lvm2" || add+="lvm2"; }
sed -i "s/block filesystems/block ${add} filesystems ${HOOKS}/g" "$MNT/etc/mkinitcpio.conf"
chrun "mkinitcpio -p $KERNEL" 2> $ERR 2>&1
chrun "mkinitcpio -p $KERNEL" > "$ERR" 2>&1
errshow 1 "mkinitcpio -p $KERNEL"
}
@ -1667,12 +1667,12 @@ prerun_grub()
sed -i "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"${DIST}\"/g; s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"\"/g" "$MNT/etc/default/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
sed -i "s~#GRUB_ENABLE_CRYPTODISK~GRUB_ENABLE_CRYPTODISK~g; s~GRUB_CMDLINE_LINUX=.*~GRUB_CMDLINE_LINUX=\"${LUKS_DEV}\"~g" "$MNT/etc/default/grub" > "$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"
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
sed -i "s/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g" "$MNT/etc/default/grub" > "$ERR" 2>&1
errshow 1 "sed -i 's/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g' $MNT/etc/default/grub"
fi
@ -1717,11 +1717,11 @@ prerun_syslinux()
s="/usr/lib/syslinux/efi64"
d='';
fi
mkdir -pv "$c" 2> $ERR 2>&1
mkdir -pv "$c" > "$ERR" 2>&1
errshow 1 "mkdir -pv $c"
cp -rfv "$s/"* "$c/" 2> $ERR 2>&1
cp -rfv "$s/"* "$c/" > "$ERR" 2>&1
errshow 1 "cp -rfv $s/* $c/"
cp -fv "$RUN/syslinux/splash.png" "$c/" 2> $ERR 2>&1
cp -fv "$RUN/syslinux/splash.png" "$c/" > "$ERR" 2>&1
errshow 0 "cp -fv $RUN/syslinux/splash.png $c/"
cat > "$c/syslinux.cfg" <<- EOF
UI vesamenu.c32
@ -1871,7 +1871,7 @@ lvm_detect()
if [[ $VGROUP && $v && $pv ]]; then
msg "LVM Setup" "\nActivating existing logical volume management.\n" 0
modprobe dm-mod > /dev/null 2> $ERR
modprobe dm-mod > /dev/null 2> "$ERR"
errshow 'modprobe dm-mod'
vgscan > /dev/null 2>&1
vgchange -ay > /dev/null 2>&1
@ -1889,7 +1889,7 @@ lvm_create()
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
lvcreate -l +100%FREE "$VGROUP" -n "$VNAME" > /dev/null 2> "$ERR"
errshow "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"
@ -1948,7 +1948,7 @@ lvm_mkgroup()
done
msg "$_lvmnew" "\nCreating volume group: $VGROUP\n" 0
vgcreate -f "$VGROUP" $LVM_PARTS > /dev/null 2> $ERR
vgcreate -f "$VGROUP" $LVM_PARTS > /dev/null 2> "$ERR"
errshow "vgcreate -f $VGROUP $LVM_PARTS" || return 1
SIZE=$(vgdisplay "$VGROUP" | awk '/VG Size/ { gsub(/[^0-9.]/, ""); print int($0) }')
@ -2003,7 +2003,7 @@ lvm_extra_lvs()
while (( VOL_COUNT > 1 )); do
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
lvcreate -L "$VOLUME_SIZE" "$VGROUP" -n "$VNAME" > /dev/null 2> "$ERR"
errshow "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-- ))
@ -2089,7 +2089,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
cryptsetup open --type luks "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> "$ERR"
errshow "cryptsetup open --type luks $LUKS_PART $LUKS_NAME" || return 1
LUKS='encrypted'; luks_show
return 0
@ -2152,9 +2152,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
cryptsetup -q luksFormat "$LUKS_PART" <<< "$LUKS_PASS" 2> "$ERR"
errshow "cryptsetup -q luksFormat $LUKS_PART" || return 1
cryptsetup open "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> $ERR
cryptsetup open "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> "$ERR"
errshow "cryptsetup open $LUKS_PART $LUKS_NAME" || return 1
LUKS='encrypted'; luks_show
return 0
@ -2167,9 +2167,9 @@ luks_advanced()
dlg cipher input "LUKS Encryption" "$_lukskey" "-s 512 -c aes-xts-plain64"
[[ $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
cryptsetup -q $cipher luksFormat "$LUKS_PART" <<< "$LUKS_PASS" 2> "$ERR"
errshow "cryptsetup -q $cipher luksFormat $LUKS_PART" || return 1
cryptsetup open "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> $ERR
cryptsetup open "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2> "$ERR"
errshow "cryptsetup open $LUKS_PART $LUKS_NAME" || return 1
luks_show
return 0