[fix] tirando o bot_prefix e melhorando o script de update

This commit is contained in:
synt-xerror
2026-03-24 01:35:55 -03:00
parent 95767ee0d5
commit 05f521d78b
3 changed files with 59 additions and 53 deletions

104
update
View File

@@ -11,8 +11,18 @@ set -euo pipefail
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
tmp_dir="$dir/tmp"
log_file="$dir/update.log"
bin_dir="$dir/bin"
config_items=(".wwebjs_auth" ".wwebjs_cache" "node_modules")
# Detecta plataforma automaticamente se PLATFORM não estiver definido
: "${PLATFORM:=}"
if [[ -z "$PLATFORM" ]]; then
case "$(uname -s)" in
MINGW*|CYGWIN*|MSYS*) PLATFORM="win" ;;
*) PLATFORM="unix" ;;
esac
fi
# ------------------------------------------------------------------------------
# Logging
# ------------------------------------------------------------------------------
@@ -32,7 +42,7 @@ cleanup_on_error() {
log "ERROR" "Falha durante a atualização (código: $exit_code)."
if [ -d "$tmp_dir" ] && [ "$(ls -A "$tmp_dir" 2>/dev/null)" ]; then
log "WARN" "Arquivos de configuração preservados em: $tmp_dir"
log "WARN" "Restaure manualmente com: mv $tmp_dir/* $dir/"
log "WARN" "Restaure manualmente com: mv \"$tmp_dir\"/* \"$dir\"/"
fi
exit $exit_code
}
@@ -42,6 +52,7 @@ trap cleanup_on_error ERR
# Validações iniciais
# ------------------------------------------------------------------------------
log "INFO" "Iniciando atualização do ManyBot..."
log "INFO" "Plataforma detectada: $PLATFORM"
# Verifica dependências obrigatórias
for cmd in git npm; do
@@ -109,67 +120,62 @@ else
fi
# ------------------------------------------------------------------------------
# Instalação de dependências
# Instalação de dependências Node
# ------------------------------------------------------------------------------
log "INFO" "Instalando dependências..."
log "INFO" "Instalando dependências Node..."
npm ci --omit=dev 2>&1 | tee -a "$log_file"
# ------------------------
# Download
# ------------------------
# ------------------------------------------------------------------------------
# Download de binários por plataforma
# ------------------------------------------------------------------------------
# Cria o diretório de binários se não existir
mkdir -p "$bin_dir"
# Função de download com fallback curl → wget
download_file() {
local url="$1"
local dest="$2"
local url="$1"
local dest="$2"
log "download_file(url=$url, dest=$dest)"
log "INFO" "Baixando: $url → $dest"
log "Baixando $url"
log "Destino: $dest"
if command -v curl &>/dev/null; then
log "INFO" "Downloader: curl"
curl -fsSL "$url" -o "$dest"
elif command -v wget &>/dev/null; then
log "INFO" "Downloader: wget"
wget -q "$url" -O "$dest"
else
log "ERROR" "Nenhum downloader encontrado (curl ou wget são necessários)."
exit 1
fi
if command -v curl >/dev/null 2>&1; then
log "Downloader: curl"
curl -L "$url" -o "$dest"
elif command -v wget >/dev/null 2>&1; then
log "Downloader: wget"
wget "$url" -O "$dest"
else
log "curl ou wget não encontrados"
exit 1
fi
chmod +x "$dest" 2>/dev/null || true
log "Arquivo pronto: $dest"
chmod +x "$dest" 2>/dev/null || true
log "INFO" "Arquivo pronto: $dest"
}
# ------------------------
# Arquivos por plataforma
# ------------------------
log "Selecionando dependências binárias"
log "INFO" "Selecionando binários para plataforma: $PLATFORM"
files=()
if [[ "$PLATFORM" == "win" ]]; then
log "Usando binários Windows"
files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe bin/yt-dlp.exe"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe bin/ffmpeg.exe"
)
log "INFO" "Usando binários Windows"
files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe $bin_dir/yt-dlp.exe"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe $bin_dir/ffmpeg.exe"
)
else
log "Usando binários Unix"
files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp bin/yt-dlp"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg bin/ffmpeg"
)
log "Total de arquivos para baixar: ${#files[@]}"
log "INFO" "Usando binários Unix"
files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp $bin_dir/yt-dlp"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg $bin_dir/ffmpeg"
)
fi # <-- fi que estava faltando no original
log "INFO" "Total de arquivos para baixar: ${#files[@]}"
# ------------------------
# Download
# ------------------------
for file in "${files[@]}"; do
url="${file%% *}"
dest="${file##* }"
log "Processando dependência"
download_file "$url" "$dest"
url="${file%% *}"
dest="${file##* }"
download_file "$url" "$dest"
done
# ------------------------------------------------------------------------------
@@ -183,7 +189,7 @@ if [ ${#backed_up[@]} -gt 0 ]; then
# Remove o que npm possa ter criado (ex: node_modules)
rm -rf "$dst"
mv "$src" "$dst"
l"INFO" "Restaurado: $item"
log "INFO" "Restaurado: $item"
else
log "WARN" "Item esperado no backup não encontrado: $item"
fi