Skip to content

Commit

Permalink
Replace all old deprecated usage of >&8 with >/dev/null to keep the c…
Browse files Browse the repository at this point in the history
…urrent behaviour
  • Loading branch information
jsmeix committed Jun 26, 2017
1 parent 523b956 commit 4f4efb3
Show file tree
Hide file tree
Showing 75 changed files with 164 additions and 150 deletions.
6 changes: 3 additions & 3 deletions usr/share/rear/backup/NETFS/default/500_make_backup.sh
Expand Up @@ -130,7 +130,7 @@ function get_disk_used() {
test "$PROGRESS_WAIT_SECONDS" || PROGRESS_WAIT_SECONDS=1
case "$( basename $BACKUP_PROG )" in
(tar)
while sleep $PROGRESS_WAIT_SECONDS ; kill -0 $BackupPID 2>&8; do
while sleep $PROGRESS_WAIT_SECONDS ; kill -0 $BackupPID 2>/dev/null; do
#blocks="$(stat -c %b ${backuparchive})"
#size="$((blocks*512))"
size="$(stat -c %s ${backuparchive}* | awk '{s+=$1} END {print s}')"
Expand All @@ -145,14 +145,14 @@ case "$( basename $BACKUP_PROG )" in
# this should be good enough and in any case this is only some eye candy.
# TODO: Find a fast way to count the actual transfer data, preferrable getting the info from rsync.
let old_disk_used="$(get_disk_used "$backuparchive")"
while sleep $PROGRESS_WAIT_SECONDS ; kill -0 $BackupPID 2>&8; do
while sleep $PROGRESS_WAIT_SECONDS ; kill -0 $BackupPID 2>/dev/null; do
let disk_used="$(get_disk_used "$backuparchive")" size=disk_used-old_disk_used
#echo -en "\e[2K\rArchived $((size/1024/1024)) MiB [avg $((size/1024/(SECONDS-starttime))) KiB/sec]"
ProgressInfo "Archived $((size/1024/1024)) MiB [avg $((size/1024/(SECONDS-starttime))) KiB/sec] "
done
;;
(*)
while sleep $PROGRESS_WAIT_SECONDS ; kill -0 $BackupPID 2>&8; do
while sleep $PROGRESS_WAIT_SECONDS ; kill -0 $BackupPID 2>/dev/null; do
size="$(stat -c "%s" "$backuparchive")" || {
kill -9 $BackupPID
ProgressError
Expand Down
4 changes: 2 additions & 2 deletions usr/share/rear/backup/RSYNC/GNU/Linux/610_start_selinux.sh
Expand Up @@ -8,9 +8,9 @@

(ssh)
# for some reason rsync changes the mode of backup after each run to 666
ssh $RSYNC_USER@$RSYNC_HOST "chmod $v 755 ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" 2>&8
ssh $RSYNC_USER@$RSYNC_HOST "chmod $v 755 ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" 2>/dev/null
$BACKUP_PROG -a "${TMP_DIR}/selinux.autorelabel" \
"$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel" 2>&8
"$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel" 2>/dev/null
_rc=$?
if [ $_rc -ne 0 ]; then
LogPrint "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup [${rsync_err_msg[$_rc]}]"
Expand Down
Expand Up @@ -6,9 +6,9 @@

(ssh)
# for some reason rsync changes the mode of backup after each run to 666
ssh $RSYNC_USER@$RSYNC_HOST "chmod $v 755 ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" 2>&8
ssh $RSYNC_USER@$RSYNC_HOST "chmod $v 755 ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" 2>/dev/null
$BACKUP_PROG -a "${TMP_DIR}/selinux.autorelabel" \
"$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel" 2>&8
"$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}/backup/.autorelabel" 2>/dev/null
_rc=$?
if [ $_rc -ne 0 ]; then
LogPrint "Failed to create .autorelabel on ${RSYNC_PATH}/${RSYNC_PREFIX}/backup [${rsync_err_msg[$_rc]}]"
Expand Down
Expand Up @@ -17,7 +17,7 @@ case $RSYNC_PROTO in

(ssh)
LogPrint "Calculating size of $RSYNC_HOST:$RSYNC_PATH"
ssh -l $RSYNC_USER $RSYNC_HOST "df -P ${RSYNC_PATH}" >$TMP_DIR/rs_size 2>&8
ssh -l $RSYNC_USER $RSYNC_HOST "df -P ${RSYNC_PATH}" >$TMP_DIR/rs_size 2>/dev/null
StopIfError "Failed to determine size of ${RSYNC_PATH}"
_div=1 # 1024-blocks
grep -q "512-blocks" $TMP_DIR/rs_size && _div=2 # HPUX: divide with 2 to get kB size
Expand Down
4 changes: 2 additions & 2 deletions usr/share/rear/backup/RSYNC/default/700_copy_backup_log.sh
Expand Up @@ -9,9 +9,9 @@ case $RSYNC_PROTO in

(ssh)
$BACKUP_PROG -a "${TMP_DIR}/${BACKUP_PROG_ARCHIVE}.log.gz" \
"${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/${BACKUP_PROG_ARCHIVE}-${Timestamp}.log.gz" 2>&8
"${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/${BACKUP_PROG_ARCHIVE}-${Timestamp}.log.gz" 2>/dev/null

$BACKUP_PROG -a "$RUNTIME_LOGFILE" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/rear-${Timestamp}.log" 2>&8
$BACKUP_PROG -a "$RUNTIME_LOGFILE" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/rear-${Timestamp}.log" 2>/dev/null
;;

(rsync)
Expand Down
Expand Up @@ -8,9 +8,9 @@ for libdir in /lib* /usr/lib* ; do
mkdir $v -p $ROOTFS_DIR$target >&2
fi
### move into ROOTFS_DIR to create 'absolute' symlinks
pushd $ROOTFS_DIR >&8
pushd $ROOTFS_DIR >/dev/null
ln $v -sf ${target#/} ${libdir#/} >&2
popd >&8
popd >/dev/null
else
mkdir $v -p $ROOTFS_DIR$libdir >&2
fi
Expand Down
8 changes: 4 additions & 4 deletions usr/share/rear/build/GNU/Linux/100_copy_as_is.sh
Expand Up @@ -11,14 +11,14 @@ Log "Files being excluded: ${COPY_AS_IS_EXCLUDE[@]}"
for f in "${COPY_AS_IS_EXCLUDE[@]}" ; do echo "$f" ; done >$TMP_DIR/copy-as-is-exclude
tar -v -X $TMP_DIR/copy-as-is-exclude \
-P -C / -c "${COPY_AS_IS[@]}" 2>$TMP_DIR/copy-as-is-filelist | \
tar $v -C $ROOTFS_DIR/ -x >&8
tar $v -C $ROOTFS_DIR/ -x >/dev/null
StopIfError "Could not copy files and directories"
Log "Finished copying COPY_AS_IS"

# fix ReaR directory if running from checkout
if [[ "$REAR_DIR_PREFIX" ]] ; then
for dir in /usr/share/rear /var/lib/rear ; do
ln $v -sf $REAR_DIR_PREFIX$dir $ROOTFS_DIR$dir>&8
ln $v -sf $REAR_DIR_PREFIX$dir $ROOTFS_DIR$dir>/dev/null
done
fi

Expand All @@ -35,7 +35,7 @@ while read -r ; do
if [[ ! -d "$REPLY" && -x "$REPLY" ]]; then
COPY_AS_IS_EXELIST=( "${COPY_AS_IS_EXELIST[@]}" "$REPLY" )
fi
echo "$REPLY" >&8
echo "$REPLY" >/dev/null
done <$TMP_DIR/copy-as-is-filelist

Log "Checking COPY_AS_IS_EXELIST"
Expand All @@ -50,4 +50,4 @@ while read -r ; do
else
echo "$lib is part of COPY_AS_IS_EXELIST"
fi
done >&8 < <( SharedObjectFiles "${COPY_AS_IS_EXELIST[@]}" | sed -e 's#^#/#' )
done >/dev/null < <( SharedObjectFiles "${COPY_AS_IS_EXELIST[@]}" | sed -e 's#^#/#' )
4 changes: 2 additions & 2 deletions usr/share/rear/build/GNU/Linux/110_touch_empty_files.sh
Expand Up @@ -5,8 +5,8 @@
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.

pushd $ROOTFS_DIR >&8
pushd $ROOTFS_DIR >/dev/null
touch var/log/lastlog
touch var/lib/nfs/state
touch etc/mtab
popd >&8
popd >/dev/null
4 changes: 2 additions & 2 deletions usr/share/rear/build/GNU/Linux/150_adjust_permissions.sh
@@ -1,9 +1,9 @@

# adjust some permissions
pushd $ROOTFS_DIR >&8
pushd $ROOTFS_DIR >/dev/null
# SSH requires this
chmod $v 0700 root >&2
chmod $v 0755 var/empty var/lib/empty >&2
chown $v -R root.root root var/empty var/lib/empty >&2

popd >&8
popd >/dev/null
Expand Up @@ -21,7 +21,7 @@ while read file location ; do
if [[ -x $ROOTFS_DIR/$file || -x $ROOTFS_DIR/lib/udev/$file || -x $ROOTFS_DIR/bin/$file ]]; then
# everything is fine
# Log "matched external call to $file in $location"
echo "matched external call to $file in $location" >&8
echo "matched external call to $file in $location" >/dev/null
else
Debug "WARNING: unmatched external call to '$file' in $location"
fi
Expand Down
2 changes: 1 addition & 1 deletion usr/share/rear/conf/default.conf
Expand Up @@ -1362,7 +1362,7 @@ EXTERNAL_IGNORE_ERRORS=( 23 24 )
# Command to verify the availability of the backup resource, will be executed only if PING=1
# NOTE: This command will be run within the ProgressBar system !! You should therefore avoid
# output on STDOUT by rerouting that to FD 8, the progress bar
EXTERNAL_CHECK="ssh vms date >&8"
EXTERNAL_CHECK="ssh vms date >/dev/null"

##
# BACKUP_RESTORE_MOVE_AWAY
Expand Down
Expand Up @@ -8,7 +8,7 @@ fi
# FIXME: Why is there is no matching popd for this pushd?
# Cf. finalize/GNU/Linux/150_migrate_uuid_tags.sh where a popd is at the end.
# If there is intentionally no popd here an explanation why there is no popd is missing.
pushd $TARGET_FS_ROOT >&8
pushd $TARGET_FS_ROOT >/dev/null
# the funny [] around the first letter make sure that shopt -s nullglob removes this file from the list if it does not exist
# the files without a [] are mandatory, like fstab
for file in [b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* [b]oot/grub/{grub.conf,menu.lst,device.map} \
Expand Down
4 changes: 2 additions & 2 deletions usr/share/rear/finalize/GNU/Linux/280_migrate_uuid_tags.sh
Expand Up @@ -15,7 +15,7 @@ done < <(sort -u $FS_UUID_MAP)
Log "$SED_SCRIPT"

# now run sed
pushd $TARGET_FS_ROOT >&8
pushd $TARGET_FS_ROOT >/dev/null
# the funny [] around the first letter make sure that shopt -s nullglob removes this file from the list if it does not exist
# the files without a [] are mandatory, like fstab
for file in [b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* \
Expand Down Expand Up @@ -53,4 +53,4 @@ for file in [b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* \
StopIfError "Patching '$file' with sed failed."
done

popd >&8
popd >/dev/null
Expand Up @@ -26,7 +26,7 @@ RULE_FILES=( $( echo /etc/udev/rules.d/*persistent*{names,net,cd}.rules ) )
# preserving a backup in /root/rear-*.old
for rule in "${RULE_FILES[@]}" ; do
rulefile="$(basename "$rule")"
if test -s "$rule" && ! diff -q "$rule" $TARGET_FS_ROOT/"$rule" >&8 ; then
if test -s "$rule" && ! diff -q "$rule" $TARGET_FS_ROOT/"$rule" >/dev/null ; then
LogPrint "Updating udev configuration ($rulefile)"
# test for file $TARGET_FS_ROOT/"$rule" as BACKUP_RESTORE_MOVE_AWAY_FILES variable
# may have prevented the restore of one of these files
Expand Down
@@ -1,6 +1,6 @@
# Test if ORIG_LAYOUT and TEMP_LAYOUT are the same

diff -u <(grep -v '^#' $ORIG_LAYOUT) <(grep -v '^#' $TEMP_LAYOUT) >&8
diff -u <(grep -v '^#' $ORIG_LAYOUT) <(grep -v '^#' $TEMP_LAYOUT) >/dev/null

if [ $? -eq 0 ] ; then
LogPrint "Disk layout is identical."
Expand Down
Expand Up @@ -7,7 +7,7 @@ create_smartarray() {
read sa slotnr junk < <(grep "^smartarray ${1#sma:} " "$LAYOUT_FILE")
cat <<EOF >>"$LAYOUT_CODE"
LogPrint "Clearing HP SmartArray controller $slotnr"
if ! $HPSSACLI ctrl slot=$slotnr delete forced >&8; then
if ! $HPSSACLI ctrl slot=$slotnr delete forced >/dev/null; then
Log "Failed to clear HP SmartArray controller $slotnr, this is not necessarily fatal."
fi
EOF
Expand Down
Expand Up @@ -9,7 +9,7 @@ LogPrint "Start system layout restoration."
mkdir -p $TARGET_FS_ROOT
if create_component "vgchange" "rear" ; then
lvm vgchange -a n >&8
lvm vgchange -a n >/dev/null
component_created "vgchange" "rear"
fi
Expand Down
2 changes: 1 addition & 1 deletion usr/share/rear/layout/recreate/default/250_verify_mount.sh
@@ -1,6 +1,6 @@
### Verify that a filesystem has been mounted at $TARGET_FS_ROOT (by default /mnt/local)
### Failure would lead to OOM conditions (restore to the ramdisk)

if diff -u <( df -P $TARGET_FS_ROOT ) <( df -P / ) >&8 ; then
if diff -u <( df -P $TARGET_FS_ROOT ) <( df -P / ) >/dev/null ; then
Error "No filesystem mounted on '$TARGET_FS_ROOT'. Stopping."
fi
Expand Up @@ -102,7 +102,7 @@ read_filesystems_command="$read_filesystems_command | sort -t ' ' -k 1,1 -u"
tunefs="tune2fs"
# on RHEL 5 tune2fs does not work on ext4, needs tune4fs
if [ "$fstype" = "ext4" ] ; then
if ! tune2fs -l $device >&8; then
if ! tune2fs -l $device >/dev/null; then
tunefs="tune4fs"
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion usr/share/rear/layout/save/GNU/Linux/260_crypt_layout.sh
Expand Up @@ -30,7 +30,7 @@ while read dm_name junk ; do
device="$(get_device_name ${slave##*/})"
done

if ! cryptsetup isLuks $device >&8 2>&1; then
if ! cryptsetup isLuks $device >/dev/null 2>&1; then
continue
fi

Expand Down
30 changes: 22 additions & 8 deletions usr/share/rear/lib/_input-output-functions.sh
Expand Up @@ -107,7 +107,7 @@ QuietAddExitTask "exec 8>&-"

# USR1 is used to abort on errors.
# It is not using PrintError but does direct output to the original STDERR:
builtin trap "echo '${MESSAGE_PREFIX}Aborting due to an error, check $RUNTIME_LOGFILE for details' >&8 ; kill $MASTER_PID" USR1
builtin trap "echo '${MESSAGE_PREFIX}Aborting due to an error, check $RUNTIME_LOGFILE for details' 1>&8 ; kill $MASTER_PID" USR1

# Make sure nobody else can use trap:
function trap () {
Expand All @@ -123,7 +123,7 @@ function Print () {
# For actually intended user error messages output to the original STDERR
# regardless whether or not the user launched 'rear' in verbose mode:
function PrintError () {
echo -e "${MESSAGE_PREFIX}$*" >&8 || true
echo -e "${MESSAGE_PREFIX}$*" 1>&8 || true
}

# For messages that should only appear in the log file output to the current STDERR
Expand Down Expand Up @@ -171,7 +171,8 @@ LogToSyslog() {
# see https://github.com/rear/rear/issues/729
function has_binary () {
for bin in $@ ; do
if type $bin &>/dev/null ; then
# Have all output on stderr to get all output in the log file regardless whereto stdout goes:
if type $bin 1>&2 ; then
return 0
fi
done
Expand All @@ -184,7 +185,7 @@ function has_binary () {
# or function, and returns the name of the disk file that would be executed
# see https://github.com/rear/rear/issues/729
function get_path () {
type -P $1 2>/dev/null
type -P $1
}

# Error exit:
Expand Down Expand Up @@ -320,6 +321,7 @@ function UserInput () {
while getopts ":t:p:a:n:d:D:" option ; do
case $option in
(t)
# Avoid stderr if OPTARG is not set or empty or not an integer value:
test "$OPTARG" -ge 0 2>/dev/null && timeout=$OPTARG || Log "UserInput: Invalid -$option argument '$OPTARG' using fallback '$timeout'"
;;
(p)
Expand All @@ -329,6 +331,7 @@ function UserInput () {
output_array="$OPTARG"
;;
(n)
# Avoid stderr if OPTARG is not set or empty or not an integer value:
test "$OPTARG" -ge 0 2>/dev/null && input_max_chars=$OPTARG || Log "UserInput: Invalid -$option argument '$OPTARG' using fallback '$input_max_chars'"
;;
(d)
Expand All @@ -338,6 +341,7 @@ function UserInput () {
default_choice="$OPTARG"
;;
(I)
# Avoid stderr if OPTARG is not set or empty or not an integer value:
test "$OPTARG" -ge 0 2>/dev/null && user_input_ID="$OPTARG" || Log "UserInput: Invalid -$option argument '$OPTARG' ignored"
;;
(\?)
Expand All @@ -358,6 +362,7 @@ function UserInput () {
# It is possible (it is no error) to specify no choices:
Log "UserInput: No choices specified"
else
# Avoid stderr if default_choice is not set or empty or not an integer value:
if test "$default_choice" -ge 0 2>/dev/null ; then
# It is possible (it is no error) to specify a number as default choice that has no matching choice:
test "${choices[$default_choice]:=}" || Log "UserInput: Default choice '$default_choice' not in choices"
Expand All @@ -368,21 +373,25 @@ function UserInput () {
test "$default_choice" = "$choice" && default_choice=$choice_index
(( choice_index += 1 ))
done
# It is possible (it is no error) to specify anything as default choice:
# It is possible (it is no error) to specify anything as default choice.
# Avoid stderr if default_choice is not set or empty or not an integer value:
test "$default_choice" -ge 0 2>/dev/null || Log "UserInput: Default choice not found in choices"
fi
fi
# When an empty prompt was specified (via -p '') do not change that:
if test "$prompt" ; then
# Avoid stderr if default_choice or timeout is not set or empty or not an integer value:
if test "$default_choice" -o "$timeout" -ge 1 2>/dev/null ; then
prompt="$prompt ("
if test "$default_choice" ; then
# Avoid stderr if default_choice is not set or empty or not an integer value:
if test "$default_choice" -ge 0 2>/dev/null ; then
prompt="$prompt default $(( default_choice + 1 ))"
else
prompt="$prompt default '$default_choice'"
fi
fi
# Avoid stderr if timeout is not set or empty or not an integer value:
if test "$timeout" -ge 1 2>/dev/null ; then
prompt="$prompt timeout $timeout"
fi
Expand All @@ -403,11 +412,13 @@ function UserInput () {
test "$prompt" && LogUserOutput "$prompt"
# Prepare the 'read' call:
local read_options_and_arguments=""
# When a zero timeout was specified (via -t 0) do not use it:
# When a zero timeout was specified (via -t 0) do not use it.
# Avoid stderr if timeout is not set or empty or not an integer value:
test "$timeout" -ge 1 2>/dev/null && read_options_and_arguments="$read_options_and_arguments -t $timeout"
# When no output_array was specified (via -a myarr) do not use it:
test "$output_array" && read_options_and_arguments="$read_options_and_arguments -a $output_array"
# When zero input_max_chars was specified (via -n 0) do not use it:
# When zero input_max_chars was specified (via -n 0) do not use it.
# Avoid stderr if input_max_chars is not set or empty or not an integer value:
test "$input_max_chars" -ge 1 2>/dev/null && read_options_and_arguments="$read_options_and_arguments -n $input_max_chars"
# When no input_delimiter was specified (via -d x) do not use it:
test "$input_delimiter" && read_options_and_arguments="$read_options_and_arguments -d $input_delimiter"
Expand All @@ -416,7 +427,8 @@ function UserInput () {
if read $read_options_and_arguments user_input 0<&6 ; then
Log "UserInput: 'read' got as user input '$user_input'"
else
# Continue in any case because in case of errors the default choice is used:
# Continue in any case because in case of errors the default choice is used.
# Avoid stderr if timeout is not set or empty or not an integer value:
if test "$timeout" -ge 1 2>/dev/null ; then
Log "UserInput: 'read' finished with non-zero exit code probably because 'read' timed out"
else
Expand All @@ -433,6 +445,7 @@ function UserInput () {
echo ""
return 101
fi
# Avoid stderr if default_choice is not set or empty or not an integer value:
if ! test "$default_choice" -ge 0 2>/dev/null ; then
LogPrint "UserInput: No user input and default choice no possible index in choices so that the result is '$default_choice'"
echo "$default_choice"
Expand All @@ -453,6 +466,7 @@ function UserInput () {
echo "$user_input"
return 0
fi
# Avoid stderr if user_input is not set or empty or not an integer value:
if ! test "$user_input" -ge 1 2>/dev/null ; then
LogPrint "UserInput: User input no possible index in choices so that the result is '$user_input'"
echo "$user_input"
Expand Down
4 changes: 2 additions & 2 deletions usr/share/rear/lib/bootloader-functions.sh
Expand Up @@ -204,7 +204,7 @@ function make_syslinux_config {
# Enable serial console, unless explicitly disabled (only last entry is used :-/)
if [[ "$USE_SERIAL_CONSOLE" =~ ^[yY1] ]]; then
for devnode in $(ls /dev/ttyS[0-9]* | sort); do
speed=$(stty -F $devnode 2>&8 | awk '/^speed / { print $2 }')
speed=$(stty -F $devnode 2>/dev/null | awk '/^speed / { print $2 }')
if [ "$speed" ]; then
echo "serial ${devnode##/dev/ttyS} $speed"
fi
Expand Down Expand Up @@ -407,7 +407,7 @@ function make_syslinux_config {
fi

# You need the memtest86+ package installed for this to work
MEMTEST_BIN=$(ls -d /boot/memtest86+-* 2>&8 | tail -1)
MEMTEST_BIN=$(ls -d /boot/memtest86+-* 2>/dev/null | tail -1)
if [[ "$MEMTEST_BIN" != "." && -r "$MEMTEST_BIN" ]]; then
cp $v "$MEMTEST_BIN" "$BOOT_DIR/memtest" >&2
echo "memtest - Run memtest86+"
Expand Down

0 comments on commit 4f4efb3

Please sign in to comment.