#!/usr/bin/env bash function container_exec() { podman_exec $@ } function die() { say error "$@" exit 255 } function get_config_dir() { prog="$(echo $1 | sed -e "s/sh.zio.//g")" prefix_dir="/etc/zio" if [[ -n "$2" ]]; then prefix_dir="$2/zio" fi config_dir="" if [[ ! -z $prog ]]; then config_dir="$prefix_dir/$prog" else config_dir="$prefix_dir" fi if [[ ! -d "$config_dir" ]]; then mkdir -p "$config_dir" fi echo "$config_dir" } function get_real_path() { echo "$(cd -P "$1" && pwd)" } function podman_exec() { container="$1" command="${@:2}" shell="/bin/sh" # TODO: Programatically get this podman exec -it $container $shell -c "$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" }