summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slx-tools41
1 files changed, 30 insertions, 11 deletions
diff --git a/slx-tools b/slx-tools
index cce30a2..02703de 100644
--- a/slx-tools
+++ b/slx-tools
@@ -4,14 +4,22 @@
################################################################################
export PATH=$PATH:/opt/openslx/bin:/opt/openslx/sbin
-declare -rg dmstate="/run/openslx/dmsetup.state"
+dmstate="/run/openslx/dmsetup.state"
+readonly dmstate
-get_backing_part() {
- local _dev _mp
- read -r _dev _mp _rest <<< \
- "$(df -P "$1" 2>&1 | awk '$1 ~ /^\/dev\// {print $1" "$6}')"
+df_dev_only() {
+ df -P "$1" 2>&1 | awk '$1 ~ /^\/dev\// {print $0}'
+}
+
+get_backing_dev() {
+ local _dev="$(df_dev_only "$1" | awk '{print $1}' )"
[ -b "$_dev" ] || return 1
- echo $_dev
+ echo "$_dev"
+}
+get_backing_dev_mp() {
+ local _mp="$(df_dev_only "$1" | awk '{print $6}')"
+ [ -d "$_mp" ] || return 1
+ echo "$_mp"
}
# Helper to check whether given directory resides in RAM, either
# by being mounted as tmpfs or not mounted at all in which case
@@ -19,8 +27,11 @@ get_backing_part() {
# 2 when errors occur.
is_volatile() {
[ -z "$1" ] && return 2
- local _dev="$(get_backing_part $1)"
+ local _dev="$(get_backing_dev "$1")"
+ [ -z "$_dev" ] && return 0
[ "$_dev" = "${_dev//\/dev\/mapper/}" ] && return 1
+ local _mp="$(get_backing_dev_mp "$1")"
+ [ -z "$_mp" ] && return 2
# it is a device mapper device, check if it was setup in dracut's initramfs.
if [ -s "$dmstate" ]; then
grep -qE "^${_dev}\s+${_mp}\s+type=0" "$dmstate"
@@ -35,10 +46,14 @@ get_dm_backing_size() {
[ "$_dev" = "${_dev//\/dev\/mapper/}" ] && return 1
local _dm_line="$(grep -m1 -E "^${_dev}\s+/\s+type=[^0]" "$dmstate")"
[ -z "$_dm_line" ] && return 1
- local _dm_dev_size="$(grep -Po '(?<=physical_size=|virtual_size=)\w*' <<< "$_dm_line" )"
+ local _dm_dev_size="$(echo "$_dm_line" | grep -Po '(?<=physical_size=|virtual_size=)\w*' )"
echo ${_dm_dev_size:--1}
}
+regex_match() {
+ echo "$1" | grep -qE "$2"
+}
+
get_partitions_by_id () {
local ID dev exp target
exp=
@@ -56,11 +71,15 @@ get_partitions_by_id () {
shift
[ -z "$ID" ] && continue
# if single digit, e.g. 7, look for 0x7 and 0x07
- [[ $ID =~ ^[0-9]$ ]] && ID="0?$ID"
- if [[ $ID =~ ^[0-9]{2}$ ]]; then
+ #[[ $ID =~ ^[0-9]$ ]] && ID="0?$ID"
+ if regex_match "$ID" "^[0-9]$" ; then
+ ID="0?$ID"
+ fi
+
+ if regex_match "$ID" "^[0-9]{2}$"; then
# if double digit look for MBR types and OpenSLX-ID$ID GPT labels
exp="$exp|ID_PART_ENTRY_(NAME=OpenSLX-ID|TYPE=0x)$ID"
- elif [[ $ID =~ ^(0x[0-9]{2}|[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})$ ]]; then
+ elif regex_match "$ID" "^(0x[0-9]{2}|[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})$"; then
# if full MBR type (e.g. 0x44) or UUID look for TYPE
exp="$exp|ID_PART_ENTRY_TYPE=$ID"
else