feat: add source code — builder, build scripts, config, shell scripts

This commit is contained in:
MR CYBER
2026-07-12 18:45:16 -07:00
parent 3a649efcc8
commit 75beb667c0
10 changed files with 4920 additions and 0 deletions
+423
View File
@@ -0,0 +1,423 @@
#!/system/bin/sh
# ============================================================
# WSA WebDAV Control Panel
# ============================================================
# Usage:
# sh app.sh Interactive menu
# sh app.sh -verbose Interactive menu (verbose)
# sh app.sh <command> Direct command
# sh app.sh -verbose <command> Direct command (verbose)
#
# Commands:
# start, stop, restart, status, health, log, config,
# port, root, connections, auto-start, clear, help
# ============================================================
PKG="com.wsa.webdav"
DATA_DIR="/data/data/$PKG/files"
RECV="$PKG/.AdbCommandReceiver"
ACT_PREFIX="com.wsa.webdav"
RESULT_ACT="$ACT_PREFIX.RESULT"
RESULT_FILE="$DATA_DIR/result.json"
CONFIG_PATH="$DATA_DIR/config.json"
DEFAULT_PORT=8088
VERBOSE=0
JSON_OUT=0
# --- Colors ---
c_r='\033[0;31m'
c_g='\033[0;32m'
c_y='\033[0;33m'
c_b='\033[0;34m'
c_c='\033[0;36m'
c_w='\033[1;37m'
c_d='\033[0m'
# --- Helpers ---
ok() { printf "${c_g}[OK]${c_d} %s\n" "$1"; }
err() { printf "${c_r}[ERR]${c_d} %s\n" "$1"; }
info() { printf "${c_c}[INFO]${c_d} %s\n" "$1"; }
warn() { printf "${c_y}[WARN]${c_d} %s\n" "$1"; }
vlog() { [ "$VERBOSE" -eq 1 ] && printf "${c_b}[*]${c_d} %s\n" "$1" || true; }
# Extract JSON field without jq
json_val() {
echo "$1" | sed 's/[{}]//g' | tr ',' '\n' | grep "\"$2\"" | head -1 | sed 's/.*"'"$2"'"[[:space:]]*:[[:space:]]*//' | sed 's/[",]//g' | sed 's/^ *//;s/ *$//'
}
# Send broadcast command, return result from file
send_cmd() {
local action="$1"
shift
local t1=$(date +%s%N 2>/dev/null || echo 0)
rm -f "$RESULT_FILE" 2>/dev/null
local out
out=$(am broadcast -a "$ACT_PREFIX.$action" "$@" -n "$RECV" 2>&1)
local t2=$(date +%s%N 2>/dev/null || echo 0)
vlog "Broadcast: $action | am output: $out"
[ "$VERBOSE" -eq 1 ] && [ "$t1" != "0" ] && vlog "Time: $(( (t2 - t1) / 1000000 ))ms"
sleep 0.2
if [ -f "$RESULT_FILE" ]; then
local result=$(cat "$RESULT_FILE" 2>/dev/null)
rm -f "$RESULT_FILE" 2>/dev/null
vlog "Result: $result"
echo "$result"
else
echo "$out"
fi
}
# Check if port is open
port_open() {
local port=${1:-$DEFAULT_PORT}
local hex_port=$(printf "%04X" "$port")
grep -q ":${hex_port}" /proc/net/tcp /proc/net/tcp6 2>/dev/null && return 0 || return 1
}
# Format uptime from ms
fmt_uptime() {
local ms=$1
local s=$(( ms / 1000 ))
local m=$(( s / 60 ))
local h=$(( m / 60 ))
if [ "$h" -gt 0 ]; then
echo "${h}h $(( m % 60 ))m"
elif [ "$m" -gt 0 ]; then
echo "${m}m $(( s % 60 ))s"
else
echo "${s}s"
fi
}
get_port() {
if [ -f "$CONFIG_PATH" ]; then
local p=$(cat "$CONFIG_PATH" 2>/dev/null | tr -d ' \r\n' | grep -o '"port":[0-9]*' | head -1 | sed 's/"port"://')
[ -n "$p" ] && [ "$p" -gt 0 ] 2>/dev/null && echo "$p" && return
fi
echo "$DEFAULT_PORT"
}
# ============================================================
# Commands
# ============================================================
cmd_start() {
info "Starting WebDAV server..."
send_cmd "START" > /dev/null
sleep 1
local port=$(get_port)
if port_open "$port"; then
ok "Server running on 127.0.0.1:$port"
else
am start -n "$PKG/.MainActivity" > /dev/null 2>&1
sleep 2
if port_open "$port"; then
ok "Server running on 127.0.0.1:$port"
else
err "Server may not have started. Check: sh app.sh log"
fi
fi
}
cmd_stop() {
info "Stopping WebDAV server..."
send_cmd "STOP" > /dev/null
sleep 1
ok "Stop command sent"
}
cmd_restart() {
info "Restarting WebDAV server..."
send_cmd "RESTART" > /dev/null
sleep 2
local port=$(get_port)
if port_open "$port"; then
ok "Server restarted on 127.0.0.1:$port"
else
warn "Restarting... check status in a moment"
fi
}
cmd_status() {
local port=$(get_port)
local running="stopped"
port_open "$port" && running="running"
if [ "$running" = "running" ]; then
ok "Server: RUNNING"
else
err "Server: STOPPED"
fi
info "Port: $port"
if [ -f "$CONFIG_PATH" ]; then
local auto_start=$(grep -o '"auto_start":[^,}]*' "$CONFIG_PATH" 2>/dev/null | sed 's/.*://')
[ "$auto_start" = "true" ] && info "Auto-start: ON" || info "Auto-start: OFF"
fi
local root_out
root_out=$(send_cmd "ROOT_STATUS" 2>/dev/null)
local root_avail=$(echo "$root_out" | grep -o '"root_available"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
[ "$root_avail" = "true" ] && info "Root: available" || info "Root: unavailable"
}
cmd_health() {
info "Checking health..."
local out=$(send_cmd "HEALTH" 2>/dev/null)
local port_open_v=$(echo "$out" | grep -o '"port_open"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
local mem_used=$(echo "$out" | grep -o '"memory_used_mb"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
local mem_max=$(echo "$out" | grep -o '"memory_max_mb"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
local threads=$(echo "$out" | grep -o '"threads"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
local root_v=$(echo "$out" | grep -o '"root_available"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
[ "$port_open_v" = "true" ] && ok "Port: open" || err "Port: closed"
info "Memory: ${mem_used}MB / ${mem_max}MB"
info "Threads: $threads"
[ "$root_v" = "true" ] && ok "Root: available" || info "Root: unavailable"
[ "$VERBOSE" -eq 1 ] && info "Raw: $out"
}
cmd_log() {
local lines=${1:-50}
local logfile="$DATA_DIR/server.log"
if [ -f "$logfile" ]; then
info "Last $lines log lines:"
echo "---"
tail -"$lines" "$logfile"
echo "---"
else
warn "Log file not found"
fi
}
cmd_clear() {
send_cmd "LOG_CLEAR" > /dev/null 2>&1
logcat -c 2>/dev/null
ok "Logs cleared"
}
cmd_config() {
if [ -f "$CONFIG_PATH" ]; then
info "Config: $CONFIG_PATH"
echo "---"
cat "$CONFIG_PATH"
echo ""
echo "---"
else
warn "Config file not found at $CONFIG_PATH"
info "Fetching from service..."
send_cmd "CONFIG_SHOW" 2>/dev/null
fi
}
cmd_port() {
local new_port=$1
if [ -z "$new_port" ]; then
local port=$(get_port)
info "Current port: $port"
return
fi
if ! [ "$new_port" -gt 0 ] 2>/dev/null; then
err "Invalid port: $new_port"
return
fi
info "Setting port to $new_port (will restart)..."
send_cmd "SET_PORT" --ei port "$new_port" > /dev/null
sleep 2
if port_open "$new_port"; then
ok "Server running on port $new_port"
else
warn "Port changed, server may be restarting..."
fi
}
cmd_root() {
info "Checking root access..."
local out=$(send_cmd "ROOT_STATUS" 2>/dev/null)
local avail=$(echo "$out" | grep -o '"root_available"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
local configured=$(echo "$out" | grep -o '"root_configured"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
[ "$avail" = "true" ] && ok "Root: available" || err "Root: unavailable"
[ "$configured" = "true" ] && info "Root access: enabled" || info "Root access: disabled"
if [ "$avail" != "true" ]; then
info "Attempting to reacquire root..."
send_cmd "REACQUIRE_ROOT" > /dev/null 2>&1
sleep 1
out=$(send_cmd "ROOT_STATUS" 2>/dev/null)
avail=$(echo "$out" | grep -o '"root_available":[^,}]*' | sed 's/.*://')
[ "$avail" = "true" ] && ok "Root acquired!" || warn "Root still unavailable"
fi
[ "$VERBOSE" -eq 1 ] && info "Raw: $out"
}
cmd_connections() {
local out=$(send_cmd "CONNECTIONS" 2>/dev/null)
local threads=$(echo "$out" | grep -o '"active_threads"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
local running=$(echo "$out" | grep -o '"server_running"[[:space:]]*:[[:space:]]*[^,}]*' | sed 's/.*://' | sed 's/[",]//g; s/^ *//;s/ *$//')
[ "$running" = "true" ] && ok "Server: running" || err "Server: stopped"
info "Active threads: $threads"
[ "$VERBOSE" -eq 1 ] && info "Raw: $out"
}
cmd_autostart() {
local state=$1
case "$state" in
on|1|true|enable)
send_cmd "ENABLE_AUTO_START" > /dev/null 2>&1
ok "Auto-start: enabled"
;;
off|0|false|disable)
send_cmd "DISABLE_AUTO_START" > /dev/null 2>&1
ok "Auto-start: disabled"
;;
*)
if [ -f "$CONFIG_PATH" ]; then
local val=$(grep -o '"auto_start":[^,}]*' "$CONFIG_PATH" 2>/dev/null | sed 's/.*://')
info "Auto-start: $val"
fi
;;
esac
}
cmd_help() {
echo "${c_w}WSA WebDAV Control Panel${c_d}"
echo ""
echo "Usage: sh app.sh [-verbose] <command> [args]"
echo ""
echo "Commands:"
echo " start Start the WebDAV server"
echo " stop Stop the server"
echo " restart Restart the server"
echo " status Show server status"
echo " health Health check (memory, threads)"
echo " log [N] Show last N log lines (default 50)"
echo " clear Clear logs"
echo " config Show configuration"
echo " port [NNNN] Show or set port"
echo " root Check root access"
echo " connections Show active connections"
echo " auto-start [on|off] Toggle auto-start"
echo " help Show this help"
echo ""
echo "Flags:"
echo " -verbose Verbose output"
echo " -json Raw JSON output"
echo ""
echo "Interactive: sh app.sh (no arguments)"
}
# ============================================================
# Interactive Menu
# ============================================================
show_menu() {
echo ""
echo "${c_w}+--------------------------------------+${c_d}"
echo "${c_w}| WSA WebDAV Control Panel |${c_d}"
echo "${c_w}+--------------------------------------+${c_d}"
echo "${c_d} ${c_c}[1]${c_d} Start Server"
echo "${c_d} ${c_c}[2]${c_d} Stop Server"
echo "${c_d} ${c_c}[3]${c_d} Restart Server"
echo "${c_d} ${c_c}[4]${c_d} Server Status"
echo "${c_d} ${c_c}[5]${c_d} Health Check"
echo "${c_d} ${c_c}[6]${c_d} View Logs"
echo "${c_d} ${c_c}[7]${c_d} Show Config"
echo "${c_d} ${c_c}[8]${c_d} Change Port"
echo "${c_d} ${c_c}[9]${c_d} Root Status"
echo "${c_d} ${c_c}[10]${c_d} Connections"
echo "${c_d} ${c_c}[11]${c_d} Toggle Auto-Start"
echo "${c_d} ${c_c}[12]${c_d} Clear Logs"
echo "${c_d} ${c_c}[0]${c_d} Exit"
echo "${c_w}+--------------------------------------+${c_d}"
echo ""
}
run_menu() {
while true; do
show_menu
printf "${c_w}Choice: ${c_d}"
read choice
echo ""
case "$choice" in
1) cmd_start ;;
2) cmd_stop ;;
3) cmd_restart ;;
4) cmd_status ;;
5) cmd_health ;;
6)
printf "Lines (default 50): "
read n
cmd_log "${n:-50}"
;;
7) cmd_config ;;
8)
printf "New port (empty to show): "
read p
cmd_port "$p"
;;
9) cmd_root ;;
10) cmd_connections ;;
11)
printf "Auto-start [on/off]: "
read s
cmd_autostart "$s"
;;
12) cmd_clear ;;
0|"")
ok "Bye"
exit 0
;;
*) err "Invalid choice: $choice" ;;
esac
echo ""
printf "${c_d}Press Enter to continue..."
read dummy
done
}
# ============================================================
# Main
# ============================================================
# Parse flags
CMDS=""
for arg in "$@"; do
case "$arg" in
-verbose|-v) VERBOSE=1 ;;
-json|-j) JSON_OUT=1 ;;
*) CMDS="$CMDS $arg" ;;
esac
done
CMDS=$(echo "$CMDS" | xargs) # trim
if [ -z "$CMDS" ]; then
[ "$VERBOSE" -eq 1 ] && info "Verbose mode enabled"
run_menu
else
# Direct command mode
set -- $CMDS
cmd=$1
shift
case "$cmd" in
start|s) cmd_start ;;
stop|q) cmd_stop ;;
restart|r) cmd_restart ;;
status|st) cmd_status ;;
health|h) cmd_health ;;
log|l) cmd_log "$@" ;;
clear|cl) cmd_clear ;;
config|c) cmd_config ;;
port|p) cmd_port "$@" ;;
root|ro) cmd_root ;;
connections|cn) cmd_connections ;;
auto-start|as) cmd_autostart "$@" ;;
help|--help|-h) cmd_help ;;
*) err "Unknown command: $cmd"; cmd_help ;;
esac
fi
+174
View File
@@ -0,0 +1,174 @@
@echo off
title WSA WebDAV APK Builder
setlocal enabledelayedexpansion
echo.
echo ================================================================
echo WSA Embedded CPython WebDAV Server - APK Builder
echo ================================================================
echo.
echo [%time%] Starting build process...
echo.
REM ============================================
REM STEP 1: Check Python
REM ============================================
echo ================================================================
echo STEP 1/6: PYTHON SETUP
echo ================================================================
echo.
echo [%time%] Checking Python...
python --version >nul 2>&1
if errorlevel 1 (
echo [%time%] [!] Python NOT FOUND
echo [%time%] Installing Python via winget...
winget install Python.Python.3.11 --accept-package-agreements --accept-source-agreements
set "PATH=C:\Python311;C:\Python311\Scripts;%LOCALAPPDATA%\Programs\Python\Python311;%LOCALAPPDATA%\Programs\Python\Python311\Scripts;%PATH%"
)
python --version >nul 2>&1
if errorlevel 1 (
echo [%time%] [x] Python install failed
pause
exit /b 1
)
echo [%time%] [+] Python OK
python --version
echo.
REM ============================================
REM STEP 2: Check Java
REM ============================================
echo ================================================================
echo STEP 2/6: JAVA SETUP
echo ================================================================
echo.
echo [%time%] Checking Java...
REM First check if java is in PATH
java -version >nul 2>&1
if not errorlevel 1 (
echo [%time%] [+] Java found in PATH
java -version 2>&1
goto :java_done
)
REM Search common installation paths
echo [%time%] Java not in PATH, searching common locations...
set "JAVA_FOUND=0"
REM Check Microsoft JDK
for /d %%i in ("C:\Program Files\Microsoft\jdk-*") do (
if exist "%%i\bin\java.exe" (
set "JAVA_HOME=%%i"
set "PATH=%%i\bin;!PATH!"
set "JAVA_FOUND=1"
echo [%time%] [+] Found: %%i
goto :java_found
)
)
REM Check Eclipse Adoptium
for /d %%i in ("C:\Program Files\Eclipse Adoptium\jdk-*") do (
if exist "%%i\bin\java.exe" (
set "JAVA_HOME=%%i"
set "PATH=%%i\bin;!PATH!"
set "JAVA_FOUND=1"
echo [%time%] [+] Found: %%i
goto :java_found
)
)
REM Check Oracle Java
for /d %%i in ("C:\Program Files\Java\jdk-*") do (
if exist "%%i\bin\java.exe" (
set "JAVA_HOME=%%i"
set "PATH=%%i\bin;!PATH!"
set "JAVA_FOUND=1"
echo [%time%] [+] Found: %%i
goto :java_found
)
)
REM Check Amazon Corretto
for /d %%i in ("C:\Program Files\Amazon Corretto\jdk-*") do (
if exist "%%i\bin\java.exe" (
set "JAVA_HOME=%%i"
set "PATH=%%i\bin;!PATH!"
set "JAVA_FOUND=1"
echo [%time%] [+] Found: %%i
goto :java_found
)
)
REM Check local user installations
for /d %%i in ("%LOCALAPPDATA%\Programs\Microsoft\jdk-*") do (
if exist "%%i\bin\java.exe" (
set "JAVA_HOME=%%i"
set "PATH=%%i\bin;!PATH!"
set "JAVA_FOUND=1"
echo [%time%] [+] Found: %%i
goto :java_found
)
)
:java_found
if "%JAVA_FOUND%"=="0" (
echo [%time%] [!] Java NOT FOUND anywhere
echo [%time%] Installing JDK 17 via winget...
winget install Microsoft.OpenJDK.17 --accept-package-agreements --accept-source-agreements
REM Try to find again after install
for /d %%i in ("C:\Program Files\Microsoft\jdk-*") do (
if exist "%%i\bin\java.exe" (
set "JAVA_HOME=%%i"
set "PATH=%%i\bin;!PATH!"
echo [%time%] [+] Installed: %%i
goto :java_final_check
)
)
)
:java_final_check
java -version >nul 2>&1
if errorlevel 1 (
echo [%time%] [x] Java not working
pause
exit /b 1
)
:java_done
echo [%time%] [+] Java OK
echo.
REM ============================================
REM STEP 3-6: Run Python Build Script
REM ============================================
echo ================================================================
echo STEP 3-6/6: RUNNING BUILD SCRIPT
echo ================================================================
echo.
echo [%time%] Starting build...
echo.
python "%~dp0builder\build.py" --verbose
if errorlevel 1 (
echo.
echo ================================================================
echo BUILD FAILED
echo ================================================================
pause
exit /b 1
)
echo.
echo ================================================================
echo BUILD COMPLETE!
echo ================================================================
echo.
echo APK: output\app-release.apk
echo.
pause
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
# ============================================
# WSA WebDAV - One-Click APK Builder (CLI)
# ============================================
# Run to build. No Android Studio.
# ============================================
set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
if ! command -v python3 &>/dev/null && ! command -v python &>/dev/null; then
echo "[x] Python not found. Install Python 3.8+"
exit 1
fi
PY=$(command -v python3 || command -v python)
$PY "$DIR/builder/build.py" "$@"
+2380
View File
File diff suppressed because it is too large Load Diff
+1639
View File
File diff suppressed because it is too large Load Diff
+24
View File
@@ -0,0 +1,24 @@
{
"enabled": true,
"port": 8088,
"host": "127.0.0.1",
"auto_start": true,
"anonymous_access": true,
"enable_root_access": true,
"user_storage_path": "/storage/emulated/0",
"root_storage_path": "/",
"max_connections": 50,
"timeout": 300,
"log_level": "INFO",
"enable_ssl": false,
"ssl_cert_file": "",
"ssl_key_file": "",
"user": "",
"password": "",
"allowed_ips": [],
"blocked_ips": [],
"max_upload_size": 0,
"enable_directory_listing": true,
"enable_cors": false,
"cors_origins": ["*"]
}
+3
View File
@@ -0,0 +1,3 @@
# WSA Embedded CPython WebDAV Server
# No external Python dependencies required - uses only stdlib
# Python 3.8+ compatible
+18
View File
@@ -0,0 +1,18 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "WSAWebDAV"
include ':app'
+104
View File
@@ -0,0 +1,104 @@
@echo off
REM ============================================================================
REM Windows Build Helper for WSA WebDAV Server
REM ============================================================================
REM This script helps prepare the embedded Python for the APK on Windows.
REM For full CPython cross-compilation, use Linux or WSL.
REM ============================================================================
setlocal enabledelayedexpansion
set PROJECT_DIR=%~dp0..
set PYTHON_BUILD_DIR=%PROJECT_DIR%\python_build
set OUTPUT_DIR=%PYTHON_BUILD_DIR%\output
set ASSETS_DIR=%PROJECT_DIR%\app\src\main\assets\python
echo ============================================
echo WSA WebDAV - Embedded Python Setup
echo ============================================
echo.
REM Check for Python
python --version >nul 2>&1
if errorlevel 1 (
echo ERROR: Python not found. Please install Python 3.8+
echo Download from: https://www.python.org/downloads/
exit /b 1
)
REM Check for required tools
echo Checking prerequisites...
python -c "import urllib.request" >nul 2>&1
if errorlevel 1 (
echo ERROR: urllib not available
exit /b 1
)
echo.
echo Choose setup method:
echo 1. Download pre-built Python binaries (Recommended)
echo 2. Create minimal bootstrap (requires system Python on device)
echo 3. Build from source (requires Linux/WSL)
echo.
set /p choice="Enter choice (1-3): "
if "%choice%"=="1" (
echo.
echo Downloading pre-built Python binaries...
python "%PYTHON_BUILD_DIR%\scripts\download_python.py" --output "%OUTPUT_DIR%"
if errorlevel 1 (
echo.
echo Download failed. Trying minimal bootstrap...
python "%PYTHON_BUILD_DIR%\scripts\download_python.py" --output "%OUTPUT_DIR%" --minimal
)
) else if "%choice%"=="2" (
echo.
echo Creating minimal Python bootstrap...
python "%PYTHON_BUILD_DIR%\scripts\download_python.py" --output "%OUTPUT_DIR%" --minimal
) else if "%choice%"=="3" (
echo.
echo For source compilation, please use Linux or WSL.
echo See: python_build\README.md
echo.
echo Alternatively, run the Docker build:
echo cd %PYTHON_BUILD_DIR%
echo docker build -t cpython-android .
echo docker run -v %OUTPUT_DIR%:/output cpython-android
exit /b 0
) else (
echo Invalid choice
exit /b 1
)
REM Copy to assets
echo.
echo Copying Python to APK assets...
if exist "%ASSETS_DIR%" (
rmdir /s /q "%ASSETS_DIR%"
)
mkdir "%ASSETS_DIR%" 2>nul
if exist "%OUTPUT_DIR%\arm64-v8a" (
echo Copying arm64-v8a...
xcopy /E /I /Y "%OUTPUT_DIR%\arm64-v8a" "%ASSETS_DIR%\arm64-v8a"
)
if exist "%OUTPUT_DIR%\x86_64" (
echo Copying x86_64...
xcopy /E /I /Y "%OUTPUT_DIR%\x86_64" "%ASSETS_DIR%\x86_64"
)
echo.
echo ============================================
echo Setup Complete!
echo ============================================
echo.
echo Next steps:
echo 1. Open project in Android Studio
echo 2. Build APK: Build > Build Bundle(s) / APK(s)
echo 3. Install APK on WSA device
echo.
echo APK output will be at:
echo app\build\outputs\apk\debug\app-debug.apk
echo.
pause
+138
View File
@@ -0,0 +1,138 @@
#!/bin/bash
# WSA WebDAV Server - Service Control Script
# Usage: ./wsa_webdav.sh {start|stop|restart|status|log|config|root|health|help}
APP_NAME="WSA WebDAV Server"
LOG_DIR="/data/local/tmp/wsa_webdav"
PID_FILE="$LOG_DIR/server.pid"
LOG_FILE="$LOG_DIR/server.log"
PYTHON_DIR="$(dirname "$0")/python_runtime"
PYTHON_SCRIPT="$PYTHON_DIR/main.py"
CONFIG_FILE="$(dirname "$0")/config.json"
DEFAULT_PORT=8088
start() {
if [ -f "$PID_FILE" ]; then
pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
echo "$APP_NAME is already running (PID: $pid)"
return 0
fi
fi
echo "Starting $APP_NAME..."
mkdir -p "$LOG_DIR"
nohup python3 "$PYTHON_SCRIPT" --config "$CONFIG_FILE" --log "$LOG_FILE" > /dev/null 2>&1 &
echo $! > "$PID_FILE"
echo "$APP_NAME started (PID: $!)"
}
stop() {
if [ ! -f "$PID_FILE" ]; then
echo "$APP_NAME is not running"
return 1
fi
pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
echo "Stopping $APP_NAME (PID: $pid)..."
kill "$pid"
sleep 2
if kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid"
fi
rm -f "$PID_FILE"
echo "$APP_NAME stopped"
else
echo "$APP_NAME is not running (stale PID file)"
rm -f "$PID_FILE"
fi
}
restart() {
stop
sleep 1
start
}
status() {
if [ -f "$PID_FILE" ]; then
pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
echo "$APP_NAME: RUNNING (PID: $pid)"
echo "Port: $DEFAULT_PORT"
echo "Log: $LOG_FILE"
else
echo "$APP_NAME: DEAD (stale PID file)"
fi
else
echo "$APP_NAME: STOPPED"
fi
}
log() {
if [ -f "$LOG_FILE" ]; then
tail -${1:-50} "$LOG_FILE"
else
echo "No log file found"
fi
}
config() {
if [ -f "$CONFIG_FILE" ]; then
cat "$CONFIG_FILE"
else
echo "No config file found"
fi
}
root() {
if su -c "id" 2>/dev/null | grep -q "uid=0"; then
echo "Root: AVAILABLE"
else
echo "Root: NOT AVAILABLE"
fi
}
health() {
if [ -f "$PID_FILE" ]; then
pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
echo "Health: OK"
else
echo "Health: PROCESS DEAD"
fi
else
echo "Health: NOT RUNNING"
fi
}
help() {
echo "$APP_NAME - Control Script"
echo ""
echo "Usage: $0 {start|stop|restart|status|log|config|root|health|help}"
echo ""
echo "Commands:"
echo " start Start the server"
echo " stop Stop the server"
echo " restart Restart the server"
echo " status Show server status"
echo " log [N] Show last N lines of log (default: 50)"
echo " config Show configuration"
echo " root Check root access"
echo " health Check server health"
echo " help Show this help"
}
case "$1" in
start) start ;;
stop) stop ;;
restart) restart ;;
status) status ;;
log) log "$2" ;;
config) config ;;
root) root ;;
health) health ;;
help|*) help ;;
esac