mirror of
https://codeberg.org/privacy1st/arch
synced 2024-12-23 01:16:04 +01:00
36 lines
1.0 KiB
Bash
36 lines
1.0 KiB
Bash
function newline_to_space(){
|
|
# Replaces all newlines with spaces
|
|
# $1: name of variable
|
|
|
|
local -n ptr=$1
|
|
# Replace newlines with spaces
|
|
# See bash string substitution: https://gist.github.com/JPvRiel/b279524d3e56229a896477cb8082a72b
|
|
|
|
echo "removing newlines in str: -->$ptr<--"
|
|
ptr="${ptr//$'\n'/' '}"
|
|
echo "new str is: -->$ptr<--"
|
|
}
|
|
|
|
function get_block_devices(){
|
|
# return: the following variables:
|
|
# BLOCK_DEVICES (array with each block device as one entry)
|
|
|
|
# get list of devices, one per line
|
|
local tmp
|
|
tmp=$(lsblk -dplnx size -o name | grep -Ev "boot|rpmb|loop")
|
|
|
|
readarray -t BLOCK_DEVICES <<<"$tmp"
|
|
}
|
|
|
|
function get_block_devices_with_size() {
|
|
# return: the following variables:
|
|
# BLOCK_DEVICE_SIZES (space separated list of block devices and their sizes)
|
|
|
|
# one could use sed to remove multiple white spaces
|
|
# sed 's|\s\s*| |'
|
|
BLOCK_DEVICE_SIZES="$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | tac)"
|
|
|
|
# replace newlines with spaces
|
|
newline_to_space BLOCK_DEVICE_SIZES
|
|
}
|