rwx/sh/util.sh

77 lines
1.1 KiB
Bash
Raw Normal View History

2024-12-01 23:40:54 +01:00
rwx_file_append() {
local file="${1}"
local text="${2}"
if [ -n "${file}" ]; then
printf "%s" "${text}" >>"${file}"
fi
}
rwx_file_empty() {
local file="${1}"
if [ -n "${file}" ]; then
rwx_file_write "${file}" ""
fi
}
2024-12-01 16:39:55 +01:00
rwx_file_write() {
local file="${1}"
local text="${2}"
if [ -n "${file}" ]; then
2024-12-01 17:47:06 +01:00
printf "%s" "${text}" >"${file}"
2024-12-01 16:39:55 +01:00
fi
}
2024-12-01 19:04:23 +01:00
rwx_link() {
local link="${1}"
local target="${2}"
ln \
2024-12-01 21:39:41 +01:00
--symbolic \
2024-12-01 19:04:23 +01:00
"${target}" \
"${link}"
}
2024-11-29 19:18:30 +01:00
rwx_list_block_devices() {
2024-11-16 13:25:02 +01:00
lsblk \
--noempty \
--output "NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS"
}
2024-11-29 19:18:30 +01:00
rwx_not() {
2024-11-12 06:42:16 +01:00
case "${1}" in
"false") echo "true" ;;
"true") echo "false" ;;
*) ;;
esac
}
2024-11-12 09:28:08 +01:00
2024-11-29 19:18:30 +01:00
rwx_read_passphrase() {
rwx_read_secret "PassPhrase: "
2024-11-12 09:28:08 +01:00
}
2024-11-29 19:18:30 +01:00
rwx_read_secret() {
2024-11-12 09:28:08 +01:00
local prompt="${1}"
local secret
2024-11-12 10:25:44 +01:00
printf "%s" "${prompt}" 1>&2
2024-11-13 13:08:09 +01:00
stty -echo
read -r secret
stty echo
2024-11-12 09:28:08 +01:00
echo >&2
echo "${secret}"
unset secret
}
2024-11-16 13:22:55 +01:00
2024-12-01 19:01:05 +01:00
rwx_remove() {
rm \
--force \
--recursive \
"${@}"
}
2024-11-29 19:18:30 +01:00
rwx_warn_wipe() {
2024-11-16 13:22:55 +01:00
local tmp
2024-11-29 19:18:30 +01:00
rwx_list_block_devices
2024-11-16 13:22:55 +01:00
printf "%s" "WIPE ${*} /?\\ OR CANCEL /!\\"
read -r tmp
2024-11-29 19:18:30 +01:00
rwx_log_trace "${tmp}"
2024-11-16 13:22:55 +01:00
}