This commit is contained in:
pvincent
2026-08-18 12:31:14 +04:00
parent 7cb8306c23
commit 1eb8459950
2 changed files with 18 additions and 18 deletions
+13 -15
View File
@@ -2,17 +2,13 @@
## ASSERT Functions
function sudo_root {
[[ "$UID" -ne 0 ]] && sudo -vp 'SUDO privilege required: '
}
function assert_root {
[[ "$UID" -ne 0 ]] && echo 'root privilege required' && return 1
true
}
function assert_container {
cat /proc/self/cgroup | grep -E '/session-c[0-9]+.scope'
cat /proc/self/cgroup | grep -qE'session-c[0-9]+\.scope'
}
function assert_system_mode {
@@ -26,7 +22,6 @@ function assert_system_mode {
true
}
## ===============
## ARRAY Functions
## ===============
@@ -34,7 +29,10 @@ function assert_system_mode {
function _array_contains {
local -n array=$1
local element=$2
[[ " ${array[@]} " =~ " ${element} " ]] && return 0 || return 1
for item in "${array[@]}"; do
[[ "$item" == "$element" ]] && return 0
done
return 1
}
function _array_intersect {
@@ -50,9 +48,10 @@ function _array_intersect {
}
function _array_subtract {
local -n arr1=$1 # First array
local -n arr2=$2 # Array to subtract
local -n result=$3 # Output array
local -n arr1 arr2 result
arr1=$1 # First array
arr2=$2 # Array to subtract
result=$3 # Output array
[[ ${#arr2[@]} == 0 ]] && result=("${arr1[@]}") && return
@@ -68,7 +67,7 @@ function _array_subtract {
function _pluralize_simple {
echo -n "$1 "
[[ $1 -eq 1 || $1 -eq -1 ]] && echo ${2} || echo ${2}s
[[ $1 -eq 1 || $1 -eq -1 ]] && echo "${2}" || echo "${2}s"
}
## ==============
@@ -89,7 +88,7 @@ function fetch_distro_like {
function _confirm_destructive {
local message="${1:-This cannot be undone!}"
echo "⚠️ WARNING: $message"
read -p "Type YES to confirm: " response
read -rp "Type YES to confirm: " response
case "$response" in
[yY][eE][sS] | [yY]) return 0 ;;
*) echo "canceled!" && return 1 ;;
@@ -103,7 +102,7 @@ function _confirm_destructive {
function _flatten_short_options {
local -n args=$1
local result=()
for word in ${args[@]}; do
for word in "${args[@]}"; do
[[ $word == -- ]] && break
if [[ $word =~ ^-[a-z][a-z] ]]; then
word=${word:1}
@@ -134,8 +133,7 @@ function get_distro_like {
return 1
}
## ==============
## Deprecated: FIXME: to remove
## FIXME: Deprecated -> to remove
## ==============
##