summaryrefslogtreecommitdiff
path: root/src/xilib.sh
blob: c21bbb965935aac7e9132cba65c86344dd91f11f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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!${RESET}\n"
        exit 1
    }
}