Files
manybot/setup
2026-03-14 01:32:23 -03:00

113 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
set -e
# ------------------------
# Cores
# ------------------------
RESET="\033[0m"
BOLD="\033[1m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
CYAN="\033[36m"
MAGENTA="\033[35m"
GRAY="\033[90m"
timestamp() {
date +"%H:%M:%S"
}
log() {
local level="$1"
local color="$2"
shift 2
echo -e "${GRAY}[$(timestamp)]${RESET} ${color}${level}${RESET} $*"
}
log_info() { log "[INFO]" "$BLUE" "$@"; }
log_ok() { log "[OK]" "$GREEN" "$@"; }
log_warn() { log "[WARN]" "$YELLOW" "$@"; }
log_error() { log "[ERROR]" "$RED" "$@"; }
log_cmd() { log "[CMD]" "$CYAN" "${BOLD}$*${RESET}"; }
log_debug() { log "[DBG]" "$GRAY" "$@"; }
# ------------------------
# Banner
# ------------------------
print_banner() {
echo -e "${MAGENTA}${BOLD}"
cat << "EOF"
_____ _____ _
| |___ ___ _ _| __ |___| |_
| | | | .'| | | | __ -| . | _|
|_|_|_|__,|_|_|_ |_____|___|_|
|___|
EOF
echo -e "${RESET}"
}
print_banner
log_info "Inicializando setup..."
# ------------------------
# Executar comandos
# ------------------------
run_cmd() {
log_cmd "$*"
"$@"
log_ok "Comando finalizado: $1"
}
# ------------------------
# Download
# ------------------------
download_file() {
local url="$1"
local dest="$2"
log_debug "download_file(url=$url, dest=$dest)"
if [[ -f "$dest" ]]; then
log_warn "Arquivo já existe: $dest"
return
fi
log_info "Baixando $url"
log_debug "Destino: $dest"
if command -v curl >/dev/null 2>&1; then
log_debug "Downloader: curl"
curl -L "$url" -o "$dest"
elif command -v wget >/dev/null 2>&1; then
log_debug "Downloader: wget"
wget "$url" -O "$dest"
else
log_error "curl ou wget não encontrados"
exit 1
fi
chmod +x "$dest" 2>/dev/null || true
log_ok "Arquivo pronto: $dest"
}
# ------------------------
# Detectar plataforma
# ------------------------
log_info "Detectando plataforma"
UNAME="$(uname -s)"
ARCH="$(uname -m)"
PLATFORM=""
case "$UNAME" in
Linux*) PLATFORM="linux";;
Darwin*) PLATFORM="mac";;
MINGW*|MSYS*|CYGWIN*) PLATFORM="win";;
*) PLATFORM="unknown";;
esac
log_info "Sistema: $UNAME"
log_info "Arquitetura: $ARCH"
log_info "Plataforma: $PLATFORM"