From f41fac9c90011c8c8605ba77a707593d52b750ae Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 15 May 2022 18:17:44 +0100 Subject: added xilib for some extra functions --- src/xilib.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/xilib.sh (limited to 'src') 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 + } +} + + -- cgit v1.2.1