2
0
Fork 0
This commit is contained in:
Ducky 2023-08-15 04:49:27 +01:00
parent 8d355454ef
commit 229cee2f31
7 changed files with 350 additions and 21 deletions

View file

@ -0,0 +1,116 @@
#!/usr/bin/env bash
function die() {
say error "$@"
exit 255
}
function get_config_dir() {
prog="$1"
config_dir=""
if [[ ! -z $prog ]]; then
config_dir="/etc/zio/$prog"
else
config_dir="/etc/zio"
fi
if [[ ! -d "$config_dir" ]]; then
mkdir -p "$config_dir"
fi
echo "$config_dir"
}
function podman_exec() {
container="$1"
command="${@:2}"
podman exec -it $container "$command"
}
function repeat() {
string="$1"
amount=$2
if ! [[ -n $amount ]]; then
amount=20
fi
eval "for i in {1..$amount}; do echo -n "$1"; done"
}
function say() {
color=""
message="${@:2}"
output=""
prefix=""
style="0"
if [[ "$2" != "" ]]; then
message="$2"
type="$1"
else
message="$1"
fi
case $1 in
debug)
color="35"
prefix="Debug"
;;
error)
color="31"
prefix="Error"
style="1"
;;
info)
color="34"
style="1"
;;
primary)
color="37"
style="1"
;;
warning)
color="33"
style="1"
;;
*|default)
color="0"
message="$@"
;;
esac
if [[ $prefix == "" ]]; then
output="\033[${style};${color}m${message}\033[0m"
else
output="\033[1;${color}m${prefix}"
if [[ $message == "" ]]; then
output+="!"
else
output+=": \033[${style};${color}m${message}\033[0m"
fi
output+="\033[0m"
fi
echo -e "$output"
}
function test_file() {
if [[ ! -f "$1" ]]; then
die "'$1' does not exist"
fi
}
function test_root() {
if [[ ! $(id -u) = 0 ]]; then
die "Unauthorized (are you root?)"
fi
}
function test_prog() {
[[ ! $(command -v "$1") ]] && die "'$1' not installed"
}