Compare commits

3 Commits
main ... dev

Author SHA1 Message Date
SyntaxError
2d77fb0080 auto commit 2 2026-01-04 22:34:38 -03:00
SyntaxError
25f45787e1 auto commit 1 2025-12-19 01:11:11 -03:00
SyntaxError
27508d609f fix conflict bug with playaudio 2025-12-19 00:37:13 -03:00
2 changed files with 70 additions and 218 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
auto-commit.txt

291
toybox.sh
View File

@@ -6,62 +6,40 @@ BLUE='\033[0;34m'
LBLUE='\033[94m' LBLUE='\033[94m'
NC='\033[0m' NC='\033[0m'
cmd_ok() { player_ok() {
"$@" >/dev/null 2>&1 & "$@" >/dev/null 2>&1
local pid=$! return $? # se rodou com sucesso -> ok
# espera 0.2s para saber se o processo morreu (erro) ou continua (ok)
sleep 0.2
if ! kill -0 "$pid" 2>/dev/null; then
return 1 # morreu -> falhou
fi
kill "$pid" 2>/dev/null
return 0 # funciona
} }
playaudio() { playaudio() {
local file="$1" local file="$1"
[[ -f "$file" ]] || return 1 [[ -f "$file" ]] || return 1
# aplay local player_cmds=("aplay" "paplay" "play" "ffplay")
if command -v aplay >/dev/null 2>&1; then local cmd
if cmd_ok aplay "$file"; then
nohup aplay "$file" >/dev/null 2>&1 &
return 0
fi
fi
# paplay for cmd in "${player_cmds[@]}"; do
if command -v paplay >/dev/null 2>&1; then if command -v "$cmd" >/dev/null 2>&1; then
if cmd_ok paplay "$file"; then if [[ "$cmd" == "ffplay" ]]; then
nohup paplay "$file" >/dev/null 2>&1 & ffplay -nodisp -autoexit -loglevel quiet "$file" &
return 0 return 0
else
# testa se funciona
"$cmd" "$file" >/dev/null 2>&1 &
local pid=$!
sleep 0.2
if kill -0 "$pid" 2>/dev/null; then
return 0 # já está tocando, não inicia outro
fi fi
fi fi
fi
done
# play (SoX) return 2
if command -v play >/dev/null 2>&1; then
if cmd_ok play "$file"; then
nohup play "$file" >/dev/null 2>&1 &
return 0
fi
fi
# ffplay
if command -v ffplay >/dev/null 2>&1; then
if cmd_ok ffplay -nodisp -autoexit -loglevel quiet "$file"; then
ffplay -nodisp -autoexit -loglevel quiet "$file"
return 0
fi
fi
return 2 # nenhum player funcional
} }
anime() { anime() {
frames=("$@") frames=("$@")
time=${frames[-1]} time=${frames[-1]}
@@ -322,198 +300,71 @@ set_status() {
} }
detect_base() { detect_base() {
# Detecta pela pkgbase (se nada mais funcionar)
if command -v apt &> /dev/null; then if command -v apt &> /dev/null; then
PKG="debian"
elif command -v dnf &> /dev/null; then
PKG="fedora"
elif command -v pacman &> /dev/null; then
PKG="arch"
elif command -v zypper &> /dev/null; then
PKG="suse"
elif command -v apk &> /dev/null; then
PKG="alpine"
else
PKG="none"
fi
# 1) Prioriza os-release
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ -n "$ID_LIKE" ]; then
read -r -a like_arr <<< "$ID_LIKE"
BASE="${like_arr[0]}"
return
fi
if [ -n "$ID" ]; then
BASE="$ID"
return
fi
fi
# 2) Fallback para outros arquivos
for file in /etc/*release /etc/*_version /etc/*-release; do
[ -f "$file" ] || continue
. "$file"
if [ -n "$ID_LIKE" ]; then
read -r -a like_arr <<< "$ID_LIKE"
BASE="${like_arr[0]}"
return
elif [ -n "$ID" ]; then
BASE="$ID"
return
elif [ -n "$DISTRIB_ID" ]; then
BASE="$DISTRIB_ID"
return
else
BASE="$(head -n1 "$file")"
return
fi
done
# 3) Ajustes baseados no PKG
if [[ "$ID" == "ubuntu" && "$PKG" == "debian" ]]; then
BASE="debian" BASE="debian"
return elif command -v dnf &> /dev/null; then
fi BASE="fedora"
elif command -v pacman &> /dev/null; then
if [[ "$ID" != "$PKG" ]]; then BASE="arch"
BASE="unknown" elif command -v zypper &> /dev/null; then
return BASE="opensuse"
fi elif command -v apk &> /dev/null; then
BASE="alpine"
if [[ "$ID" == "$PKG" ]]; then
BASE="$ID"
return
fi
return 127
}
# Result:
#detect_base
#echo $BASE
#> arch
detect_distro() {
# 1) Prioriza os-release
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO="${NAME:-$PRETTY_NAME}"
return
fi
# 2) Fallback para arquivos específicos
shopt -s nullglob
for file in /etc/*release /etc/*_version /etc/*-release; do
[ -e "$file" ] || continue
. "$file"
if [ -n "${NAME:-}" ]; then
DISTRO="$NAME"
shopt -u nullglob
return
elif [ -n "${DISTRIB_ID:-}" ]; then
DISTRO="$DISTRIB_ID"
shopt -u nullglob
return
else else
DISTRO="$(head -n1 "$file")" BASE=""
shopt -u nullglob
return
fi fi
done
shopt -u nullglob
return 127 # Leitura do /etc/os-release
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS_ID="${ID}"
OS_LIKE="${ID_LIKE}"
fi
OS_LIKE_MAIN=$(echo "$OS_LIKE" | awk '{print $1}')
} if [[ -z "$OS_LIKE_MAIN" && -n "$OS_ID" ]]; then
# Result OS_LIKE_MAIN="$OS_ID"
# detect_distro fi
# echo "$NAME"
# > Arch Linux
detect_windows() { LIKE_BASE=""
# 1) Git Bash / MSYS2 / MinGW case "$OS_LIKE_MAIN" in
case "$(uname -s)" in debian|ubuntu) LIKE_BASE="debian" ;;
MINGW*|MSYS*) rhel|fedora) LIKE_BASE="fedora" ;;
windows_env="Git Bash / MSYS2" arch) LIKE_BASE="arch" ;;
return 0 suse|opensuse) LIKE_BASE="opensuse" ;;
;; alpine) LIKE_BASE="alpine" ;;
esac esac
# 2) Windows environment variable (Git Bash, MSYS, Cygwin) if [[ -z "$BASE" && -z "$LIKE_BASE" ]]; then
if [ "$is_windows" = false ] && [ "$OS" = "Windows_NT" ]; then echo "Erro: não foi possível determinar a base."
windows_env="Windows_NT (Git Bash/Cygwin/MSYS)"
return 0
fi
# 3) WSL
if [ "$is_windows" = false ] && grep -qi microsoft /proc/version 2>/dev/null; then
windows_env="Windows Subsystem for Linux"
return 0
fi
# 4) cmd.exe (fallback)
if [ "$is_windows" = false ] && command -v cmd.exe >/dev/null 2>&1; then
windows_env="Windows (via cmd.exe)"
return 0
fi
return 1 return 1
fi
# Result if [[ -n "$BASE" && -n "$LIKE_BASE" && "$BASE" != "$LIKE_BASE" ]]; then
# if detect_windows; then BASE="$LIKE_BASE"
# echo "Windows detected ($windows_env)" fi
# else
# echo "Isn't windows." if [[ -z "$BASE" && -n "$LIKE_BASE" ]]; then
# fi BASE="$LIKE_BASE"
fi
} }
detect_android() { # echo -e "toybox.sh - detect_base: ${RED}NotFound${NC}: Could not detect distribution base."
# 1) build.prop
if grep -qi android /system/build.prop 2>/dev/null; then detect_distro() {
android_env="build.prop" for f in /etc/os-release /usr/lib/os-release /etc/lsb-release; do
if [ -r "$f" ]; then
. "$f"
DISTRO="${NAME:-$DISTRIB_ID}"
return 0 return 0
fi fi
done
# 2) getprop echo "toybox.sh - detect_distro: NotFound: Could not detect distribution name."
if command -v getprop >/dev/null 2>&1; then return 127
if [ -n "$(getprop ro.build.version.release 2>/dev/null)" ]; then }
android_env="getprop"
return 0 run() {
fi "$@" &
fi (( $(jobs -r | wc -l) >= 3 )) && wait -n
# 3) common directories
if [ -d /sdcard ] && [ -d /system ]; then
android_env="paths típicos"
return 0
fi
# 4) Termux
if [[ "$PREFIX" == /data/data/*com.termux* ]]; then
android_env="Termux"
return 0
fi
# 5) kernel
if uname -a | grep -qi android; then
android_env="kernel string"
return 0
fi
return 1
# Result
# if detect_android; then
# echo "Android detected ($android_env)"
# else
# echo "Isn't Android"
# fi
} }