Skip to content

Commit

Permalink
Merge pull request #699 from jsmeix/add_optional_value_to_specify_D_c…
Browse files Browse the repository at this point in the history
…ommand_line_option_settings

Added separated debugscripts option and first steps so that 'set -eu' works
  • Loading branch information
gdha committed Nov 19, 2015
2 parents 42be800 + ddfed6f commit 45b6baa
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 267 deletions.
339 changes: 217 additions & 122 deletions usr/sbin/rear

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions usr/share/rear/conf/GNU/Linux.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# progs to take along
PROGS=(
${PROGS[@]}
${PROGS[@]:-}
rpc.statd
rpcbind
bash
Expand Down Expand Up @@ -170,12 +170,12 @@ dosfslabel
# the lib* serves to cover both 32bit and 64bit libraries!
#
LIBS=(
${LIBS[@]}
${LIBS[@]:-}

### needed for username lookups
/lib*/libnss_dns*
/lib*/libnss_files*
### support multiarch
### support multiarch
/lib/*/libnss_dns*
/lib/*/libnss_files*

Expand All @@ -188,7 +188,7 @@ ${LIBS[@]}
)

MODULES=(
${MODULES[@]}
${MODULES[@]:-}
vfat
nls_iso8859_1
nls_utf8
Expand Down Expand Up @@ -219,13 +219,14 @@ crc32c
crc32c-intel
)

COPY_AS_IS=( ${COPY_AS_IS[@]} /dev /etc/inputr[c] /etc/protocols /etc/services /etc/rpc /etc/termcap /etc/terminfo /lib*/terminfo /usr/share/terminfo /etc/netconfig /etc/mke2fs.conf /etc/*-release /lib*/firmware /etc/localtime /etc/magic /usr/share/misc/magic /etc/dracut.conf /etc/dracut.conf.d /usr/lib/dracut /sbin/modprobe.ksplice-orig )
COPY_AS_IS=( ${COPY_AS_IS[@]:-} /dev /etc/inputr[c] /etc/protocols /etc/services /etc/rpc /etc/termcap /etc/terminfo /lib*/terminfo /usr/share/terminfo /etc/netconfig /etc/mke2fs.conf /etc/*-release /lib*/firmware /etc/localtime /etc/magic /usr/share/misc/magic /etc/dracut.conf /etc/dracut.conf.d /usr/lib/dracut /sbin/modprobe.ksplice-orig )

# exclude /dev/shm/*, due to the way we use tar the leading / should be omitted
COPY_AS_IS_EXCLUDE=( ${COPY_AS_IS_EXCLUDE[@]} dev/shm/\* )
COPY_AS_IS_EXCLUDE=( ${COPY_AS_IS_EXCLUDE[@]:-} dev/shm/\* )

# some stuff for the Linux command line
KERNEL_CMDLINE="$KERNEL_CMDLINE selinux=0"
# common users and groups
CLONE_USERS=( "${CLONE_USERS[@]}" daemon rpc usbmuxd usbmux vcsa nobody)
CLONE_GROUPS=( "${CLONE_GROUPS[@]}" tty usbmuxd usbmux fuse kvm oinstall )
CLONE_USERS=( "${CLONE_USERS[@]:-}" daemon rpc usbmuxd usbmux vcsa nobody)
CLONE_GROUPS=( "${CLONE_GROUPS[@]:-}" tty usbmuxd usbmux fuse kvm oinstall )

4 changes: 2 additions & 2 deletions usr/share/rear/conf/Linux-i386.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
REQUIRED_PROGS=(
"${REQUIRED_PROGS[@]}"
"${REQUIRED_PROGS[@]:-}"
parted
sfdisk
)

PROGS=(
"${PROGS[@]}"
"${PROGS[@]:-}"
grub
partprobe
lilo
Expand Down
8 changes: 5 additions & 3 deletions usr/share/rear/conf/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ KERNEL_FILE=""
# append special kernel parameters on rescue media
KERNEL_CMDLINE=""
# Relax-and-Recover knows several kernel parameters
# - adding 'debug' starts all init-scripts in debug (-X) mode and allows you to
# - adding 'debug' starts all init-scripts in debug (-X) mode and allows you to
# skip a script.
# - 'noip' prevents initialization of the networking configuration, useful when
# you want to prevent the system to use the same ip address.
Expand Down Expand Up @@ -79,9 +79,11 @@ OS_VERSION=none
KEEP_BUILD_DIR=""

# no default workflows. This variable is filled in where the worklflows are defined
WORKFLOWS=( )
# without the empty string as initial value WORKFLOWS and LOCKLESS_WORKFLOWS would
# be unbound variables that would result an error exit if 'set -eu' is used:
WORKFLOWS=("")
# allow some workflows to not lock, also generates a separate log
LOCKLESS_WORKFLOWS=( )
LOCKLESS_WORKFLOWS=("")

# default backup and output targets
BACKUP=REQUESTRESTORE
Expand Down
117 changes: 63 additions & 54 deletions usr/share/rear/lib/_input-output-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,64 @@
#
#

LF="
"
# the sequence $'...' is an special bash expansion with backslash-escaped characters
# see "Words of the form $'string' are treated specially" in "man bash"
# that works at least down to bash 3.1 in SLES10:
LF=$'\n'

# collect exit tasks in this array
EXIT_TASKS=()
# without the empty string as initial value ${EXIT_TASKS[@]} would be an unbound variable
# that would result an error exit if 'set -eu' is used:
EXIT_TASKS=("")
# add $* as a task to be done at the end
AddExitTask() {
# NOTE: we add the task at the beginning to make sure that they are executed in reverse order
EXIT_TASKS=( "$*" "${EXIT_TASKS[@]}" ) # I use $* on purpose because I want to get one string from all args!
Debug "Added '$*' as an exit task"
function AddExitTask () {
# NOTE: we add the task at the beginning to make sure that they are executed in reverse order
# I use $* on purpose because I want to get one string from all args!
EXIT_TASKS=( "$*" "${EXIT_TASKS[@]}" )
Debug "Added '$*' as an exit task"
}
QuietAddExitTask() {
EXIT_TASKS=( "$*" "${EXIT_TASKS[@]}" ) # I use $* on purpose because I want to get one string from all args!
function QuietAddExitTask () {
# I use $* on purpose because I want to get one string from all args!
EXIT_TASKS=( "$*" "${EXIT_TASKS[@]}" )
}

# remove $* from the task list
RemoveExitTask() {
local removed=""
for (( c=0 ; c<${#EXIT_TASKS[@]} ; c++ )) ; do
if test "${EXIT_TASKS[c]}" == "$*" ; then
unset 'EXIT_TASKS[c]' # the ' ' protect from bash expansion, however unlikely to have a file named EXIT_TASKS in pwd...
removed=yes
Debug "Removed '$*' from the list of exit tasks"
fi
done
[ "$removed" == "yes" ]
LogIfError "Could not remove exit task '$*' (not found). Exit Tasks:
$(
for task in "${EXIT_TASKS[@]}" ; do
echo "$task"
done
)"
function RemoveExitTask () {
local removed="" exit_tasks=""
for (( c=0 ; c<${#EXIT_TASKS[@]} ; c++ )) ; do
if test "${EXIT_TASKS[c]}" = "$*" ; then
# the ' ' protect from bash expansion, however unlikely to have a file named EXIT_TASKS in pwd...
unset 'EXIT_TASKS[c]'
removed=yes
Debug "Removed '$*' from the list of exit tasks"
fi
done
if ! test "$removed" = "yes" ; then
exit_tasks="$( for task in "${EXIT_TASKS[@]}" ; do echo "$task" ; done )"
Log "Could not remove exit task '$*' (not found). Exit Tasks: '$exit_tasks'"
fi
}

# do all exit tasks
DoExitTasks() {
Log "Running exit tasks."
# kill all running jobs
JOBS=( $(jobs -p) )
if test "$JOBS" ; then
Log "The following jobs are still active:"
jobs -l >&2
kill -9 "${JOBS[@]}" >&2
sleep 1 # allow system to clean up after killed jobs
fi
for task in "${EXIT_TASKS[@]}" ; do
Debug "Exit task '$task'"
eval "$task"
done
function DoExitTasks () {
Log "Running exit tasks."
# kill all running jobs
JOBS=( $( jobs -p ) )
# when "jobs -p" results nothing then JOBS is still an unbound variable so that
# an empty default value is used to avoid 'set -eu' error exit if $JOBS is unset:
if test -n ${JOBS:-""} ; then
Log "The following jobs are still active:"
jobs -l >&2
kill -9 "${JOBS[@]}" >&2
# allow system to clean up after killed jobs
sleep 1
fi
for task in "${EXIT_TASKS[@]}" ; do
Debug "Exit task '$task'"
eval "$task"
done
}

# activate the trap function
builtin trap "DoExitTasks" 0
# keep PID of main process
Expand All @@ -82,7 +91,7 @@ builtin trap "echo 'Aborting due to an error, check $LOGFILE for details' >&7 ;

# make sure nobody else can use trap
function trap () {
BugError "Forbidden use of trap with '$@'. Use AddExitTask instead."
BugError "Forbidden use of trap with '$@'. Use AddExitTask instead."
}

# Check if any of the binaries/aliases exist
Expand Down Expand Up @@ -157,12 +166,12 @@ BugIfError() {
fi
}

Debug() {
test "$DEBUG" && Log "$@"
function Debug () {
test -n "$DEBUG" && Log "$@" || true
}

Print() {
test "$VERBOSE" && echo -e "$*" >&7
function Print () {
test -n "$VERBOSE" && echo -e "$*" >&7 || true
}

# print if there is an error
Expand All @@ -173,7 +182,7 @@ PrintIfError() {
fi
}

if [[ "$DEBUG" || "$DEBUG_SCRIPTS" ]]; then
if [[ "$DEBUG" || "$DEBUGSCRIPTS" ]]; then
Stamp() {
date +"%Y-%m-%d %H:%M:%S.%N "
}
Expand All @@ -183,12 +192,12 @@ else
}
fi

Log() {
if test $# -gt 0 ; then
echo "$(Stamp)$*"
else
echo "$(Stamp)$(cat)"
fi >&2
function Log () {
if test $# -gt 0 ; then
echo "$(Stamp)$*"
else
echo "$(Stamp)$(cat)"
fi >&2
}

# log if there is an error
Expand All @@ -199,9 +208,9 @@ LogIfError() {
fi
}

LogPrint() {
Log "$@"
Print "$@"
function LogPrint () {
Log "$@"
Print "$@"
}

# log/print if there is an error
Expand Down
15 changes: 10 additions & 5 deletions usr/share/rear/lib/array-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

# return wether $1 equals one of the remaining arguments
function IsInArray() {
local needle="$1"
while shift; do
[[ "$needle" == "$1" ]] && return 0
done
return 1
local needle="$1"
test -z "$needle" && return 1
while shift ; do
# at the end $1 becomes an unbound variable (after all arguments were shifted)
# so that an empty default value is used to avoid 'set -eu' error exit
# and that empty default value cannot match because needle is non-empty:
test "$needle" == "${1:-}" && return 0
done
return 1
}

2 changes: 1 addition & 1 deletion usr/share/rear/lib/checklayout-workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
WORKFLOW_checklayout_DESCRIPTION="check if the disk layout has changed"
WORKFLOWS=( ${WORKFLOWS[@]} checklayout )
LOCKLESS_WORKFLOWS=( ${LOCKLESS_WORKFLOWS[@]} checklayout )
WORKFLOW_checklayout () {
function WORKFLOW_checklayout () {
ORIG_LAYOUT=$VAR_DIR/layout/disklayout.conf
TEMP_LAYOUT=$TMP_DIR/checklayout.conf

Expand Down
10 changes: 10 additions & 0 deletions usr/share/rear/lib/config-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,23 @@ SetOSVendorAndVersion () {
OS_MASTER_VENDOR="Arch"
OS_MASTER_VERSION="$OS_VERSION"
;;
(*)
# set fallback values to aviod error exit for 'set -eu' because of unbound variables:
OS_MASTER_VENDOR=""
OS_MASTER_VERSION="$OS_VERSION"
;;
esac

# combined stuff for OS_MASTER_*
if [ "$OS_MASTER_VENDOR" ] ; then
OS_MASTER_VENDOR_VERSION="$OS_MASTER_VENDOR/$OS_MASTER_VERSION"
OS_MASTER_VENDOR_ARCH="$OS_MASTER_VENDOR/$MACHINE"
OS_MASTER_VENDOR_VERSION_ARCH="$OS_MASTER_VENDOR/$OS_MASTER_VERSION/$MACHINE"
else
# set fallback values to aviod error exit for 'set -eu' because of unbound variables:
OS_MASTER_VENDOR_VERSION="$OS_MASTER_VERSION"
OS_MASTER_VENDOR_ARCH="$MACHINE"
OS_MASTER_VENDOR_VERSION_ARCH="$OS_MASTER_VERSION/$MACHINE"
fi

}
Expand Down
Loading

0 comments on commit 45b6baa

Please sign in to comment.