mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2024-11-22 12:35:13 +00:00
improve readability of code in some complex branching points
avoid usage of if...elif...elif...else in some points, substituted with while true; do ... done loops and break statements on success.
This commit is contained in:
parent
c1b5e1b310
commit
117bd9bd6e
96
tomb
96
tomb
@ -500,56 +500,54 @@ ask_password() {
|
|||||||
|
|
||||||
pass_asked=0
|
pass_asked=0
|
||||||
|
|
||||||
if [[ ! -z $WAYLAND_DISPLAY ]]; then
|
while true; do
|
||||||
|
[[ ! -z $WAYLAND_DISPLAY ]] && {
|
||||||
_verbose "wayland display detected"
|
_verbose "wayland display detected"
|
||||||
_is_found "pinentry-gnome3" && {
|
_is_found "pinentry-gnome3" && {
|
||||||
_verbose "using pinentry-gnome3 on wayland"
|
_verbose "using pinentry-gnome3 on wayland"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-gnome3)
|
output=$(pinentry_assuan_getpass | pinentry-gnome3)
|
||||||
pass_asked=1
|
break; }
|
||||||
|
# TODO: pinentry on KDE running in wayland?
|
||||||
}
|
}
|
||||||
fi
|
[[ ! -z $DISPLAY ]] && [[ $pass_asked == 0 ]] && {
|
||||||
if [[ ! -z $DISPLAY ]] && [[ $pass_asked == 0 ]]; then
|
|
||||||
_verbose "X11 display detected"
|
_verbose "X11 display detected"
|
||||||
if _is_found "pinentry-gtk-2"; then
|
_is_found "pinentry-gtk-2" && {
|
||||||
_verbose "using pinentry-gtk2"
|
_verbose "using pinentry-gtk2"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-gtk-2)
|
output=$(pinentry_assuan_getpass | pinentry-gtk-2)
|
||||||
pass_asked=1
|
break; }
|
||||||
elif _is_found "pinentry-x11"; then
|
_is_found "pinentry-x11" && {
|
||||||
_verbose "using pinentry-x11"
|
_verbose "using pinentry-x11"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-x11)
|
output=$(pinentry_assuan_getpass | pinentry-x11)
|
||||||
pass_asked=1
|
break; }
|
||||||
elif _is_found "pinentry-gnome3"; then
|
_is_found "pinentry-gnome3" && {
|
||||||
_verbose "using pinentry-gnome3 on X11"
|
_verbose "using pinentry-gnome3 on X11"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-gnome3)
|
output=$(pinentry_assuan_getpass | pinentry-gnome3)
|
||||||
pass_asked=1
|
break; }
|
||||||
elif _is_found "pinentry-qt5"; then
|
_is_found "pinentry-qt5" && {
|
||||||
_verbose "using pinentry-qt5"
|
_verbose "using pinentry-qt5"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-qt5)
|
output=$(pinentry_assuan_getpass | pinentry-qt5)
|
||||||
pass_asked=1
|
break; }
|
||||||
elif _is_found "pinentry-qt4"; then
|
_is_found "pinentry-qt4" && {
|
||||||
_verbose "using pinentry-qt4"
|
_verbose "using pinentry-qt4"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-qt4)
|
output=$(pinentry_assuan_getpass | pinentry-qt4)
|
||||||
pass_asked=1
|
break; }
|
||||||
fi
|
}
|
||||||
fi
|
|
||||||
if [[ $pass_asked == 0 ]]; then
|
|
||||||
_verbose "no display detected"
|
_verbose "no display detected"
|
||||||
if _is_found "pinentry-curses"; then
|
_is_found "pinentry-curses" && {
|
||||||
_verbose "using pinentry-curses with no display"
|
_verbose "using pinentry-curses with no display"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-curses)
|
output=$(pinentry_assuan_getpass | pinentry-curses)
|
||||||
pass_asked=1
|
break; }
|
||||||
elif _is_found "pinentry-tty"; then
|
_is_found "pinentry-tty" && {
|
||||||
_verbose "using pinentry-tty with no display"
|
_verbose "using pinentry-tty with no display"
|
||||||
output=$(pinentry_assuan_getpass | pinentry-tty)
|
output=$(pinentry_assuan_getpass | pinentry-tty)
|
||||||
pass_asked=1
|
break; }
|
||||||
else
|
# TODO: fallback using read -s - and beware
|
||||||
# TODO: fallback to asking password using read
|
# using read with or without -r may break
|
||||||
_failure "Cannot find any pinentry and no DISPLAY detected."
|
# passwords, so this must be covered by a test
|
||||||
fi
|
# for compatibility
|
||||||
fi
|
|
||||||
|
|
||||||
[[ $pass_asked == 0 ]] &&
|
|
||||||
_failure "Cannot find any pinentry and no DISPLAY detected."
|
_failure "Cannot find any pinentry and no DISPLAY detected."
|
||||||
|
exit 1
|
||||||
|
done
|
||||||
|
|
||||||
# parse the pinentry output
|
# parse the pinentry output
|
||||||
local pinentry_error
|
local pinentry_error
|
||||||
@ -589,26 +587,23 @@ is_valid_tomb() {
|
|||||||
local _fail=0
|
local _fail=0
|
||||||
# Tomb file must be a readable, writable, non-empty regular file.
|
# Tomb file must be a readable, writable, non-empty regular file.
|
||||||
# If passed the "ro" mount option, the writable check is skipped.
|
# If passed the "ro" mount option, the writable check is skipped.
|
||||||
|
while true; do
|
||||||
option_value_contains -o ro || {
|
option_value_contains -o ro || {
|
||||||
[[ ! -w "$1" ]] && {
|
[[ ! -w "$1" ]] && {
|
||||||
_warning "Tomb file is not writable: ::1 tomb file::" $1
|
_warning "Tomb file is not writable: ::1 tomb file::" $1
|
||||||
_fail=1
|
_fail=1; break; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_verbose "tomb file is readable"
|
_verbose "tomb file is readable"
|
||||||
|
|
||||||
[[ ! -f "$1" ]] && {
|
[[ ! -f "$1" ]] && {
|
||||||
_warning "Tomb file is not a regular file: ::1 tomb file::" $1
|
_warning "Tomb file is not a regular file: ::1 tomb file::" $1
|
||||||
_fail=1
|
_fail=1; break; }
|
||||||
}
|
|
||||||
_verbose "tomb file is a regular file"
|
_verbose "tomb file is a regular file"
|
||||||
|
|
||||||
[[ ! -s "$1" ]] && {
|
[[ ! -s "$1" ]] && {
|
||||||
_warning "Tomb file is empty (zero length): ::1 tomb file::" $1
|
_warning "Tomb file is empty (zero length): ::1 tomb file::" $1
|
||||||
_fail=1
|
_fail=1; break; }
|
||||||
}
|
|
||||||
_verbose "tomb file is not empty"
|
_verbose "tomb file is not empty"
|
||||||
|
break;
|
||||||
|
done
|
||||||
[[ $_fail == 1 ]] && {
|
[[ $_fail == 1 ]] && {
|
||||||
_failure "Tomb command failed: ::1 command name::" $subcommand
|
_failure "Tomb command failed: ::1 command name::" $subcommand
|
||||||
}
|
}
|
||||||
@ -1101,24 +1096,27 @@ _load_key() {
|
|||||||
[[ -z $keyfile ]] && {
|
[[ -z $keyfile ]] && {
|
||||||
_failure "This operation requires a key file to be specified using the -k option." }
|
_failure "This operation requires a key file to be specified using the -k option." }
|
||||||
|
|
||||||
if [[ $keyfile == "-" ]]; then
|
while true; do
|
||||||
|
[[ $keyfile == "-" ]] && {
|
||||||
_verbose "load_key reading from stdin."
|
_verbose "load_key reading from stdin."
|
||||||
_message "Waiting for the key to be piped from stdin... "
|
_message "Waiting for the key to be piped from stdin... "
|
||||||
TOMBKEYFILE=stdin
|
TOMBKEYFILE=stdin
|
||||||
TOMBKEY=$(cat)
|
TOMBKEY=$(cat)
|
||||||
elif [[ $keyfile == "cleartext" ]]; then
|
break; }
|
||||||
|
[[ $keyfile == "cleartext" ]] && {
|
||||||
_verbose "load_key reading SECRET from stdin"
|
_verbose "load_key reading SECRET from stdin"
|
||||||
_message "Waiting for the key to be piped from stdin... "
|
_message "Waiting for the key to be piped from stdin... "
|
||||||
TOMBKEYFILE=cleartext
|
TOMBKEYFILE=cleartext
|
||||||
TOMBKEY=cleartext
|
TOMBKEY=cleartext
|
||||||
TOMBSECRET=$(cat)
|
TOMBSECRET=$(cat)
|
||||||
else
|
break; }
|
||||||
_verbose "load_key argument: ::1 key file::" $keyfile
|
_verbose "load_key argument: ::1 key file::" $keyfile
|
||||||
[[ -r $keyfile ]] || _failure "Key not found, specify one using -k."
|
[[ -r $keyfile ]] || _failure "Key not found, specify one using -k."
|
||||||
_track_stat "$keyfile"
|
_track_stat "$keyfile"
|
||||||
TOMBKEYFILE=$keyfile
|
TOMBKEYFILE=$keyfile
|
||||||
TOMBKEY="${mapfile[$TOMBKEYFILE]}"
|
TOMBKEY="${mapfile[$TOMBKEYFILE]}"
|
||||||
fi
|
break
|
||||||
|
done
|
||||||
|
|
||||||
_verbose "load_key: ::1 key::" $TOMBKEYFILE
|
_verbose "load_key: ::1 key::" $TOMBKEYFILE
|
||||||
|
|
||||||
@ -2520,14 +2518,18 @@ exec_safe_bind_hooks() {
|
|||||||
for dir in ${mounted}; do _sudo umount $dir; done
|
for dir in ${mounted}; do _sudo umount $dir; done
|
||||||
return 0 }
|
return 0 }
|
||||||
|
|
||||||
if [[ ! -r "$HOME/${maps[$dir]}" ]]; then
|
while true; do
|
||||||
_warning "bind-hook target not existent, skipping ::1 home::/::2 subdir::" $HOME ${maps[$dir]}
|
[[ ! -r "$mnt/$dir" ]] && {
|
||||||
elif [[ ! -r "$mnt/$dir" ]]; then
|
|
||||||
_warning "bind-hook source not found in tomb, skipping ::1 mount point::/::2 subdir::" $mnt $dir
|
_warning "bind-hook source not found in tomb, skipping ::1 mount point::/::2 subdir::" $mnt $dir
|
||||||
else
|
break; }
|
||||||
_sudo mount -o bind,$MOUNTOPTS $mnt/$dir $HOME/${maps[$dir]} \
|
[[ ! -r "$HOME/${maps[$dir]}" ]] && {
|
||||||
|
_warning "bind-hook target not existent, skipping ::1 home::/::2 subdir::" $HOME ${maps[$dir]}
|
||||||
|
break; }
|
||||||
|
_sudo mount -o bind,$MOUNTOPTS \
|
||||||
|
$mnt/$dir $HOME/${maps[$dir]} \
|
||||||
&& mounted+=("$HOME/${maps[$dir]}")
|
&& mounted+=("$HOME/${maps[$dir]}")
|
||||||
fi
|
break
|
||||||
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user