summaryrefslogtreecommitdiff
path: root/src/lib/xilib.sh
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-06-27 01:14:42 +0100
committerdavidovski <david@davidovski.xyz>2022-06-27 01:14:42 +0100
commit7bba6cd7612293796e905885f9ed3072877798ab (patch)
treedd01942dbdd474a4df62ecf74479f5e78d83f1c8 /src/lib/xilib.sh
parent79fb6f41104cd0d88891598ddfc3c30d1bb0352d (diff)
added shmk, building all with shmk
Diffstat (limited to 'src/lib/xilib.sh')
-rw-r--r--src/lib/xilib.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/xilib.sh b/src/lib/xilib.sh
new file mode 100644
index 0000000..57dd10c
--- /dev/null
+++ b/src/lib/xilib.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# format a number into a bytes, kibibytes, mebibytes, or gibibytes
+#
+format_bytes () {
+ case "1" in
+ "$(($1>=1<<30))") printf "$(($1>>30))GiB";;
+ "$(($1>=1<<20))") printf "$(($1>>20))MiB";;
+ "$(($1>=1<<10))") printf "$(($1>>10))kiB";;
+ *) printf "$1B";;
+ esac
+}
+
+# ensure that the user is a root user
+#
+checkroot () {
+ [ "$(id -u)" = "0" ] || {
+ printf "${RED}Please run as root!${RESET}\n"
+ exit 1
+ }
+}
+
+# reverse the order of lines
+#
+reverse_lines () {
+ local result=
+ while IFS= read -r line; do
+ result="$line
+ $result"
+ done
+ echo "$result"
+}
+
+