batman
This commit is contained in:
commit
cc8ffcfcc2
38 changed files with 6046 additions and 0 deletions
76
logging.sh
Normal file
76
logging.sh
Normal file
|
@ -0,0 +1,76 @@
|
|||
#!/bin/sh
|
||||
|
||||
# POSIX-compliant color codes
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
GREEN='\033[0;32m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Simple echo functions without any arrays or typeset
|
||||
echo_error() {
|
||||
printf "${RED}❌ %s${NC}\n" "$1" >&2
|
||||
}
|
||||
|
||||
echo_warning() {
|
||||
printf "${YELLOW}⚠️ %s${NC}\n" "$1"
|
||||
}
|
||||
|
||||
echo_info() {
|
||||
printf "${GREEN}ℹ️ %s${NC}\n" "$1"
|
||||
}
|
||||
|
||||
echo_note() {
|
||||
printf "${CYAN}📝 %s${NC}\n" "$1"
|
||||
}
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
command_exists() {
|
||||
for i in which command; do
|
||||
if command_exists $i; then
|
||||
case $i in
|
||||
command) command -v "$@" >/dev/null 2>&1 ;;
|
||||
which) which "$@" >/dev/null 2>&1 ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
_cd() {
|
||||
cd "$1" || { echo_error "Cannot navigate to the directory: $1"; return 1; }
|
||||
}
|
||||
|
||||
_exit() {
|
||||
echo_error "There was an error, which caused the script to exit immediately"
|
||||
echo_error "$1"
|
||||
echo_error "Exiting now!"
|
||||
exit 1
|
||||
}
|
||||
|
||||
confirm_action() {
|
||||
read -p "$1 - [y/n]: " confirm
|
||||
case $confirm in
|
||||
[yY] ) return 0 ;;
|
||||
[nN] ) return 1 ;;
|
||||
* ) echo_warning "Invalid input. Action cancelled." ; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
create_dir() {
|
||||
if [ ! -d "$1" ]; then
|
||||
echo_info "Creating directory: $1"
|
||||
mkdir -p "$1" || _exit "Failed to create directory $1"
|
||||
else
|
||||
echo_info "Directory $1 already exists"
|
||||
fi
|
||||
}
|
||||
|
||||
check_disk_space() {
|
||||
threshold=1000000 # Minimum space in KB (e.g., 1GB)
|
||||
available_space=$(df / | awk 'NR==2 {print $4}')
|
||||
if [ "$available_space" -lt "$threshold" ]; then
|
||||
echo_warning "Not enough disk space. Only $((available_space / 1024))MB remaining."
|
||||
return 1
|
||||
fi
|
||||
echo_info "Sufficient disk space available."
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue