Skip to content

Commit

Permalink
Implement and make use of robust list functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tails developers authored and daniel-baumann committed Jun 4, 2012
1 parent 5f89a19 commit acd782e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scripts/live
Expand Up @@ -1001,12 +1001,12 @@ setup_unionfs ()
;;
esac

if echo ${PERSISTENCE_METHOD} | grep -qe "\<overlay\>"
if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
then
overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
fi

if echo ${PERSISTENCE_METHOD} | grep -qe "\<snapshot\>"
if is_in_comma_sep_list snapshot ${PERSISTENCE_METHOD}
then
snapshots="${root_snapshot_label} ${home_snapshot_label}"
fi
Expand Down
37 changes: 29 additions & 8 deletions scripts/live-helpers
Expand Up @@ -388,7 +388,7 @@ Arguments ()
then
PERSISTENCE_ENCRYPTION="none"
export PERSISTENCE_ENCRYPTION
elif echo ${PERSISTENCE_ENCRYPTION} | grep -qe "\<luks\>"
elif is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION}
then
if ! modprobe dm-crypt
then
Expand Down Expand Up @@ -418,6 +418,27 @@ Arguments ()
fi
}

is_in_list_separator_helper () {
local sep=${1}
shift
local element=${1}
shift
local list=${*}
echo ${list} | grep -qe "^\(.*${sep}\)\?${element}\(${sep}.*\)\?$"
}

is_in_space_sep_list () {
local element=${1}
shift
is_in_list_separator_helper "[[:space:]]" "${element}" "${*}"
}

is_in_comma_sep_list () {
local element=${1}
shift
is_in_list_separator_helper "," "${element}" "${*}"
}

sys2dev ()
{
sysdev=${1#/sys}
Expand Down Expand Up @@ -449,9 +470,9 @@ storage_devices()
do
fulldevname=$(sys2dev "${sysblock}")

if echo "${black_listed_devices}" | grep -qe "\<${fulldevname}\>" || \
if is_in_space_sep_list ${fulldevname} ${black_listed_devices} || \
[ -n "${white_listed_devices}" ] && \
echo "${white_listed_devices}" | grep -qve "\<${fulldevname}\>"
! is_in_space_sep_list ${fulldevname} ${white_listed_devices}
then
# skip this device entirely
continue
Expand All @@ -461,7 +482,7 @@ storage_devices()
do
devname=$(sys2dev "${dev}")

if echo "${black_listed_devices}" | grep -qe "\<${devname}\>"
if is_in_space_sep_list ${devname} ${black_listed_devices}
then
# skip this subdevice
continue
Expand Down Expand Up @@ -984,7 +1005,7 @@ find_persistence_media ()
# in order to probe any filesystem it contains, like we do
# below. activate_custom_mounts() also depends on that any luks
# device already has been opened.
if echo ${PERSISTENCE_ENCRYPTION} | grep -qe "\<luks\>" && \
if is_in_comma_sep_list luks ${PERSISTENCE_ENCRYPTION} && \
is_luks_partition ${dev}
then
if luks_device=$(open_luks_device "${dev}")
Expand All @@ -994,14 +1015,14 @@ find_persistence_media ()
# skip $dev since we failed/chose not to open it
continue
fi
elif echo ${PERSISTENCE_ENCRYPTION} | grep -qve "\<none\>"
elif ! is_in_comma_sep_list none ${PERSISTENCE_ENCRYPTION}
then
# skip $dev since we don't allow unencrypted storage
continue
fi

# Probe for matching GPT partition names or filesystem labels
if echo ${PERSISTENCE_STORAGE} | grep -qe "\<filesystem\>"
if is_in_comma_sep_list filesystem ${PERSISTENCE_STORAGE}
then
result=$(probe_for_gpt_name "${overlays}" "${snapshots}" ${dev})
if [ -n "${result}" ]
Expand All @@ -1019,7 +1040,7 @@ find_persistence_media ()
fi

# Probe for files with matching name on mounted partition
if echo ${PERSISTENCE_STORAGE} | grep -qe "\<file\>"
if is_in_comma_sep_list file ${PERSISTENCE_STORAGE}
then
result=$(probe_for_file_name "${overlays}" "${snapshots}" ${dev})
if [ -n "${result}" ]
Expand Down

0 comments on commit acd782e

Please sign in to comment.