zpkg/src/util.sh
2020-05-26 11:20:51 +02:00

30 lines
444 B
Bash

#!/bin/sh
# random alphanumeric string of $1 chars
random_string()
{
tr -cd '[:alnum:]' < /dev/urandom | head -c$1
}
# $1 = input , $2 = prefix absolute path
resolve_path()
{
if [ "$(echo $1 | cut -c1)" != "/" ]
then
echo "$2/$1"
else
echo "$1"
fi
}
# get name of the folder
getname()
{
basename "$(readlink -f "$1")"
}
# return error if user is root
root_check()
{
[ "$(id | cut -d'=' -f2 | cut -d'(' -f1)" -eq 0 ]
}