summaryrefslogtreecommitdiff
path: root/src/xilib.sh
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-05-15 18:17:44 +0100
committerdavidovski <david@davidovski.xyz>2022-05-15 18:17:44 +0100
commitf41fac9c90011c8c8605ba77a707593d52b750ae (patch)
tree450f3f358fddde2634fe3fb46af49c5b1c920659 /src/xilib.sh
parent2cc91fe26563b2726da24ecf6fd2a1d11f4aa89a (diff)
added xilib for some extra functionsv1.4.2
Diffstat (limited to 'src/xilib.sh')
-rw-r--r--src/xilib.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/xilib.sh b/src/xilib.sh
new file mode 100644
index 0000000..56e2592
--- /dev/null
+++ b/src/xilib.sh
@@ -0,0 +1,23 @@
+#!/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!\n"
+ exit 1
+ }
+}
+
+