Compare commits

..

3 Commits

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

287
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
BASE="fedora"
elif command -v pacman &> /dev/null; then
BASE="arch"
elif command -v zypper &> /dev/null; then
BASE="opensuse"
elif command -v apk &> /dev/null; then
BASE="alpine"
else
BASE=""
fi fi
if [[ "$ID" != "$PKG" ]]; then # Leitura do /etc/os-release
BASE="unknown" if [[ -f /etc/os-release ]]; then
return
fi
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 . /etc/os-release
DISTRO="${NAME:-$PRETTY_NAME}" OS_ID="${ID}"
return OS_LIKE="${ID_LIKE}"
fi
OS_LIKE_MAIN=$(echo "$OS_LIKE" | awk '{print $1}')
if [[ -z "$OS_LIKE_MAIN" && -n "$OS_ID" ]]; then
OS_LIKE_MAIN="$OS_ID"
fi fi
# 2) Fallback para arquivos específicos LIKE_BASE=""
shopt -s nullglob case "$OS_LIKE_MAIN" in
for file in /etc/*release /etc/*_version /etc/*-release; do debian|ubuntu) LIKE_BASE="debian" ;;
[ -e "$file" ] || continue rhel|fedora) LIKE_BASE="fedora" ;;
arch) LIKE_BASE="arch" ;;
. "$file" suse|opensuse) LIKE_BASE="opensuse" ;;
alpine) LIKE_BASE="alpine" ;;
if [ -n "${NAME:-}" ]; then
DISTRO="$NAME"
shopt -u nullglob
return
elif [ -n "${DISTRIB_ID:-}" ]; then
DISTRO="$DISTRIB_ID"
shopt -u nullglob
return
else
DISTRO="$(head -n1 "$file")"
shopt -u nullglob
return
fi
done
shopt -u nullglob
return 127
}
# Result
# detect_distro
# echo "$NAME"
# > Arch Linux
detect_windows() {
# 1) Git Bash / MSYS2 / MinGW
case "$(uname -s)" in
MINGW*|MSYS*)
windows_env="Git Bash / MSYS2"
return 0
;;
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 1
return 0
fi fi
# 3) WSL if [[ -n "$BASE" && -n "$LIKE_BASE" && "$BASE" != "$LIKE_BASE" ]]; then
if [ "$is_windows" = false ] && grep -qi microsoft /proc/version 2>/dev/null; then BASE="$LIKE_BASE"
windows_env="Windows Subsystem for Linux"
return 0
fi fi
# 4) cmd.exe (fallback) if [[ -z "$BASE" && -n "$LIKE_BASE" ]]; then
if [ "$is_windows" = false ] && command -v cmd.exe >/dev/null 2>&1; then BASE="$LIKE_BASE"
windows_env="Windows (via cmd.exe)"
return 0
fi fi
return 1
# Result
# if detect_windows; then
# echo "Windows detected ($windows_env)"
# else
# echo "Isn't windows."
# 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
android_env="build.prop"
return 0
fi
# 2) getprop detect_distro() {
if command -v getprop >/dev/null 2>&1; then for f in /etc/os-release /usr/lib/os-release /etc/lsb-release; do
if [ -n "$(getprop ro.build.version.release 2>/dev/null)" ]; then if [ -r "$f" ]; then
android_env="getprop" . "$f"
DISTRO="${NAME:-$DISTRIB_ID}"
return 0 return 0
fi fi
fi done
# 3) common directories echo "toybox.sh - detect_distro: NotFound: Could not detect distribution name."
if [ -d /sdcard ] && [ -d /system ]; then return 127
android_env="paths típicos" }
return 0
fi run() {
"$@" &
# 4) Termux (( $(jobs -r | wc -l) >= 3 )) && wait -n
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
} }