From af232a356818b6c72dbd4b0d8550a6b89eefaad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Eduardo=20Garc=C3=ADa=20M=C3=A1rquez?= Date: Thu, 26 Mar 2026 06:49:26 -0500 Subject: [PATCH] feat: agregar instalador, bashrc-snippet y gitignore - install.sh: instalacion automatica desde cero - bashrc-snippet.sh: autostart + aliases para copiar a .bashrc - .gitignore: excluir datos runtime (private, logs, pids) - README.md: seccion de instalacion rapida Co-Authored-By: Claude Opus 4.6 --- .gitignore | 8 +++++ README.md | 28 +++++++++++++++ bashrc-snippet.sh | 21 +++++++++++ install.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 .gitignore create mode 100644 bashrc-snippet.sh create mode 100755 install.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92f7348 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +private/ +lock/ +state/ +cache/ +cores/ +*.pid +*.log +*.bak-* diff --git a/README.md b/README.md index 69c9103..cbbc702 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,34 @@ > Actualizado: 2026-03-24 +## Instalacion rapida + +```bash +git clone https://devops.ingeniumcodex.com/andresgarcia0313/termux-samba.git +cd termux-samba +bash install.sh +``` + +El instalador: +1. Instala `samba` y `python-zeroconf` +2. Crea directorios de config +3. Copia `smb.conf` y `mdns-publish.py` +4. Crea usuario Samba (pide usuario y contrasena) +5. Agrega autostart y aliases a `.bashrc` +6. Inicia ambos servicios + +## Archivos del repo + +| Archivo | Proposito | +|---------|-----------| +| `smb.conf` | Config principal de Samba | +| `mdns-publish.py` | Script de descubrimiento en red (SSH + SMB) | +| `install.sh` | Instalador automatico | +| `bashrc-snippet.sh` | Autostart + aliases para .bashrc | +| `.gitignore` | Excluye datos runtime (logs, pids, private) | + +--- + ## Resumen Samba 4.20.8 corriendo en Termux (Android) con descubrimiento automatico en red local via mDNS. Compatible con Windows 11, Kubuntu 24 y macOS. diff --git a/bashrc-snippet.sh b/bashrc-snippet.sh new file mode 100644 index 0000000..f2809de --- /dev/null +++ b/bashrc-snippet.sh @@ -0,0 +1,21 @@ + +# --- Samba (puerto 4450) --- +if ! pgrep -x smbd > /dev/null; then + smbd -D -s ~/.config/samba/smb.conf 2>/dev/null +fi + +alias smb-start='smbd -D -s ~/.config/samba/smb.conf && echo "Samba iniciado en puerto 4450"' +alias smb-stop='pkill smbd && echo "Samba detenido"' +alias smb-restart='pkill smbd 2>/dev/null; sleep 1; smbd -D -s ~/.config/samba/smb.conf && echo "Samba reiniciado"' +alias smb-status='pgrep -a smbd && echo "Puerto: 4450" || echo "Samba no esta corriendo"' +alias smb-log='tail -50 ~/.config/samba/samba.log' + +# --- mDNS (movil.local: SSH + SMB) --- +if ! pgrep -f mdns-publish.py > /dev/null; then + nohup python ~/.local/bin/mdns-publish.py > /dev/null 2>&1 & + disown +fi + +alias mdns-status='pgrep -af mdns-publish || echo "mDNS no esta corriendo"' +alias mdns-restart='pkill -f mdns-publish; sleep 1; nohup python ~/.local/bin/mdns-publish.py > /dev/null 2>&1 & disown && echo "mDNS reiniciado"' +alias mdns-stop='pkill -f mdns-publish && echo "mDNS detenido"' diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..9af630d --- /dev/null +++ b/install.sh @@ -0,0 +1,91 @@ +#!/data/data/com.termux/files/usr/bin/bash +# Instalador de Samba + mDNS para Termux +# Uso: bash install.sh +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +SAMBA_DIR="$HOME/.config/samba" +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +info() { echo -e "${GREEN}[+]${NC} $1"; } +warn() { echo -e "${YELLOW}[!]${NC} $1"; } +error() { echo -e "${RED}[x]${NC} $1"; exit 1; } + +# 1. Verificar Termux +[ -n "$PREFIX" ] || error "No es Termux. Este script solo funciona en Termux." + +# 2. Instalar dependencias +info "Instalando paquetes..." +pkg install -y samba python 2>/dev/null +pip install -q zeroconf 2>/dev/null + +# 3. Crear directorios +info "Creando directorios..." +mkdir -p "$SAMBA_DIR"/{private,lock,state,cache} +chmod 0755 "$SAMBA_DIR"/{lock,state,cache} + +# 4. Copiar config +info "Copiando smb.conf..." +cp "$SCRIPT_DIR/smb.conf" "$SAMBA_DIR/smb.conf" + +# 5. Copiar script mDNS +info "Instalando mdns-publish.py..." +mkdir -p "$HOME/.local/bin" +cp "$SCRIPT_DIR/mdns-publish.py" "$HOME/.local/bin/mdns-publish.py" +chmod +x "$HOME/.local/bin/mdns-publish.py" + +# 6. Crear usuario Samba +info "Configurando usuario Samba..." +read -p "Usuario Samba [andres]: " SMB_USER +SMB_USER="${SMB_USER:-andres}" +read -s -p "Contrasena Samba: " SMB_PASS +echo "" +printf '%s\n%s\n' "$SMB_PASS" "$SMB_PASS" | \ + smbpasswd -L -s -c "$SAMBA_DIR/smb.conf" -a "$SMB_USER" 2>/dev/null || \ + printf '%s\n%s\n' "$SMB_PASS" "$SMB_PASS" | \ + smbpasswd -L -s -c "$SAMBA_DIR/smb.conf" "$SMB_USER" + +# 7. Verificar storage +if [ ! -d "/storage/emulated/0" ]; then + warn "Storage no accesible. Ejecuta: termux-setup-storage" +fi + +# 8. Agregar a .bashrc si no existe +if ! grep -q "smbd" "$HOME/.bashrc" 2>/dev/null; then + info "Agregando autostart a .bashrc..." + cat "$SCRIPT_DIR/bashrc-snippet.sh" >> "$HOME/.bashrc" +else + warn "Autostart ya existe en .bashrc, no se modifica" +fi + +# 9. Iniciar servicios +info "Iniciando Samba..." +pkill smbd 2>/dev/null || true +sleep 1 +smbd -D -s "$SAMBA_DIR/smb.conf" + +info "Iniciando mDNS..." +pkill -f mdns-publish.py 2>/dev/null || true +sleep 1 +nohup python "$HOME/.local/bin/mdns-publish.py" > /dev/null 2>&1 & +disown + +# 10. Verificar +sleep 2 +if pgrep -x smbd > /dev/null && pgrep -f mdns-publish > /dev/null; then + info "Todo corriendo." + echo "" + echo " Nombre en red: movil" + echo " Puerto: 4450" + echo " Usuario: $SMB_USER" + echo "" + echo " Desde Linux: smb://movil.local:4450/" + echo " Desde Windows: \\\\IP:4450\\" + echo "" +else + error "Algo fallo. Revisa: smb-status / mdns-status" +fi