summaryrefslogtreecommitdiff
path: root/scripts/live-helpers
diff options
context:
space:
mode:
authorTails developers <amnesia@boum.org>2010-11-01 18:23:05 +0100
committerTails developers <amnesia@boum.org>2011-09-07 14:53:41 +0200
commit3f02456e392ead3abf36bc181692fcb75c8f16f3 (patch)
tree46f6f223f2846b9fba18e905fa44b7d6e8fdae93 /scripts/live-helpers
parent209828c38d8af6fa2eab68cd668ca9109261f249 (diff)
downloadlive-boot-3f02456e392ead3abf36bc181692fcb75c8f16f3.tar.gz
live-boot-3f02456e392ead3abf36bc181692fcb75c8f16f3.zip
Factorizing loops on removable/non-removable devices.
The already duplicated code will be needed a few more times for the upcoming persistent-media={removable,removable-usb} boot option. Copy/pasting it a few more times seems the wrong way to go, hence this factorization. Depending on the place they are used, the newly introduced functions must return a list of devices named either /sys/block/* or /dev/*. Their first parameter therefore specifies the wanted output format (default is /dev/* as it is the most often used).
Diffstat (limited to 'scripts/live-helpers')
-rw-r--r--scripts/live-helpers70
1 files changed, 70 insertions, 0 deletions
diff --git a/scripts/live-helpers b/scripts/live-helpers
index 7f8649f..73d9f9d 100644
--- a/scripts/live-helpers
+++ b/scripts/live-helpers
@@ -488,3 +488,73 @@ is_luks()
fi
}
+
+removable_dev ()
+{
+ output_format="${1}"
+ want_usb="${2}"
+ ret=
+
+ for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+ do
+ dev_ok=
+ if [ "$(cat ${sysblock}/removable)" = "1" ]
+ then
+ if [ -z "${want_usb}" ]
+ then
+ dev_ok="yes"
+ else
+ if readlink ${sysblock} | grep -q usb
+ then
+ dev_ok="yes"
+ fi
+ fi
+ fi
+
+ if [ "${dev_ok}" = "yes" ]
+ then
+ case "${output_format}" in
+ sys)
+ ret="${ret} ${sysblock}"
+ ;;
+ *)
+ devname=$(sys2dev "${sysblock}")
+ ret="${ret} ${devname}"
+ ;;
+ esac
+ fi
+ done
+
+ echo "${ret}"
+}
+
+removable_usb_dev ()
+{
+ output_format="${1}"
+
+ removable_dev "${output_format}" "want_usb"
+}
+
+non_removable_dev ()
+{
+ output_format="${1}"
+ ret=
+
+ for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)")
+ do
+ if [ "$(cat ${sysblock}/removable)" = "0" ]
+ then
+ case "${output_format}" in
+ sys)
+ ret="${ret} ${sysblock}"
+ ;;
+ *)
+ devname=$(sys2dev "${sysblock}")
+ ret="${ret} ${devname}"
+ ;;
+ esac
+ fi
+ done
+
+ echo "${ret}"
+}