Ver código fonte

add dw touch

tuanchris 1 mês atrás
pai
commit
025a00c810
2 arquivos alterados com 108 adições e 32 exclusões
  1. 71 2
      dw
  2. 37 30
      setup-pi.sh

+ 71 - 2
dw

@@ -13,6 +13,7 @@
 #   logs        View live logs (Ctrl+C to exit)
 #   status      Show container status
 #   shell       Open a shell in the container
+#   touch       Manage touch screen app
 #   help        Show this help message
 #
 
@@ -130,12 +131,17 @@ cmd_update() {
     echo "Pulling latest code..."
     git pull
 
+    # Update dw CLI
+    echo "Updating dw command..."
+    sudo cp "$INSTALL_DIR/dw" /usr/local/bin/dw
+    sudo chmod +x /usr/local/bin/dw
+
     if is_docker_mode; then
         echo "Pulling latest Docker image..."
         sudo docker compose pull
 
         echo "Restarting with new version..."
-        sudo docker compose up -d
+        sudo docker compose up -d --quiet-pull
     else
         echo "Updating Python dependencies..."
         source .venv/bin/activate
@@ -145,7 +151,18 @@ cmd_update() {
         sudo systemctl restart dune-weaver
     fi
 
-    echo -e "${GREEN}Updated!${NC}"
+    # Update touch app if installed
+    local touch_dir="/home/pi/dune-weaver-touch"
+    if [[ -d "$touch_dir" ]]; then
+        echo ""
+        echo -e "${BLUE}Updating touch app...${NC}"
+        cd "$touch_dir"
+        git pull
+        sudo systemctl restart dune-weaver-touch
+        echo -e "${GREEN}Touch app updated!${NC}"
+    fi
+
+    echo -e "${GREEN}Update complete!${NC}"
 }
 
 cmd_logs() {
@@ -194,6 +211,53 @@ cmd_shell() {
     fi
 }
 
+# Touch app commands (systemd service)
+cmd_touch() {
+    local subcmd="${1:-help}"
+
+    case "$subcmd" in
+        logs)
+            local lines="${2:-}"
+            if [[ -n "$lines" ]]; then
+                sudo journalctl -u dune-weaver-touch -n "$lines"
+            else
+                sudo journalctl -u dune-weaver-touch -f
+            fi
+            ;;
+        restart)
+            echo -e "${BLUE}Restarting touch app...${NC}"
+            sudo systemctl restart dune-weaver-touch
+            echo -e "${GREEN}Touch app restarted${NC}"
+            ;;
+        stop)
+            echo -e "${BLUE}Stopping touch app...${NC}"
+            sudo systemctl stop dune-weaver-touch
+            echo -e "${GREEN}Touch app stopped${NC}"
+            ;;
+        start)
+            echo -e "${BLUE}Starting touch app...${NC}"
+            sudo systemctl start dune-weaver-touch
+            echo -e "${GREEN}Touch app started${NC}"
+            ;;
+        status)
+            sudo systemctl status dune-weaver-touch
+            ;;
+        help|*)
+            echo -e "${GREEN}Touch App Commands${NC}"
+            echo ""
+            echo "Usage: dw touch <command>"
+            echo ""
+            echo "Commands:"
+            echo "  logs [N]    View logs (N lines or follow if omitted)"
+            echo "  restart     Restart touch app"
+            echo "  stop        Stop touch app"
+            echo "  start       Start touch app"
+            echo "  status      Show touch app status"
+            echo "  help        Show this help message"
+            ;;
+    esac
+}
+
 cmd_help() {
     echo -e "${GREEN}Dune Weaver CLI${NC}"
     echo ""
@@ -208,6 +272,7 @@ cmd_help() {
     echo "  logs [N]    View logs (N=number of lines, or follow if omitted)"
     echo "  status      Show container status"
     echo "  shell       Open a shell in the container"
+    echo "  touch       Manage touch screen app (run 'dw touch help')"
     echo "  help        Show this help message"
     echo ""
     if [[ -n "$INSTALL_DIR" ]]; then
@@ -242,6 +307,10 @@ case "${1:-help}" in
     shell)
         cmd_shell
         ;;
+    touch)
+        shift
+        cmd_touch "$@"
+        ;;
     help|--help|-h)
         cmd_help
         ;;

+ 37 - 30
setup-pi.sh

@@ -2,17 +2,18 @@
 #
 # Dune Weaver Raspberry Pi Setup Script
 #
-# One-command setup for deploying Dune Weaver on Raspberry Pi
-# Run this script from the cloned dune-weaver directory:
+# ONE-COMMAND INSTALL (recommended):
+#   curl -fsSL https://raw.githubusercontent.com/tuanchris/dune-weaver/main/setup-pi.sh | bash
 #
+# OR from existing clone:
 #   git clone https://github.com/tuanchris/dune-weaver --single-branch
 #   cd dune-weaver
 #   bash setup-pi.sh
 #
 # Options:
-#   bash setup-pi.sh --no-docker    # Use Python venv instead of Docker
-#   bash setup-pi.sh --no-wifi-fix  # Skip WiFi stability fix
-#   bash setup-pi.sh --help         # Show help
+#   --no-docker     Use Python venv instead of Docker
+#   --no-wifi-fix   Skip WiFi stability fix
+#   --help          Show help
 #
 
 set -e
@@ -27,7 +28,8 @@ NC='\033[0m' # No Color
 # Default options
 USE_DOCKER=true
 FIX_WIFI=true  # Applied by default for stability
-INSTALL_DIR="$(pwd)"  # Assume running from cloned dune-weaver directory
+INSTALL_DIR="$HOME/dune-weaver"
+REPO_URL="https://github.com/tuanchris/dune-weaver"
 
 # Parse arguments
 while [[ $# -gt 0 ]]; do
@@ -43,19 +45,16 @@ while [[ $# -gt 0 ]]; do
         --help|-h)
             echo "Dune Weaver Raspberry Pi Setup Script"
             echo ""
-            echo "Usage:"
-            echo "  git clone https://github.com/tuanchris/dune-weaver --single-branch"
-            echo "  cd dune-weaver"
-            echo "  bash setup-pi.sh [OPTIONS]"
+            echo "One-command install:"
+            echo "  curl -fsSL https://raw.githubusercontent.com/tuanchris/dune-weaver/main/setup-pi.sh | bash"
+            echo ""
+            echo "Or from existing clone:"
+            echo "  cd ~/dune-weaver && bash setup-pi.sh [OPTIONS]"
             echo ""
             echo "Options:"
             echo "  --no-docker     Use Python venv instead of Docker"
             echo "  --no-wifi-fix   Skip WiFi stability fix (applied by default)"
             echo "  --help, -h      Show this help message"
-            echo ""
-            echo "Examples:"
-            echo "  bash setup-pi.sh              # Standard Docker installation + WiFi fix"
-            echo "  bash setup-pi.sh --no-docker  # Python venv installation + WiFi fix"
             exit 0
             ;;
         *)
@@ -196,22 +195,30 @@ install_python_deps() {
 }
 
 # Verify we're in the dune-weaver directory
-check_directory() {
-    print_step "Verifying dune-weaver directory..."
-
-    # Check for key files that indicate we're in the right directory
-    if [[ ! -f "docker-compose.yml" ]] || [[ ! -f "main.py" ]]; then
-        print_error "This script must be run from the dune-weaver directory"
-        echo ""
-        echo "Please run:"
-        echo "  git clone https://github.com/tuanchris/dune-weaver --single-branch"
-        echo "  cd dune-weaver"
-        echo "  bash setup-pi.sh"
-        exit 1
+ensure_repo() {
+    print_step "Setting up dune-weaver repository..."
+
+    # Check if we're already in the dune-weaver directory
+    if [[ -f "docker-compose.yml" ]] && [[ -f "main.py" ]]; then
+        INSTALL_DIR="$(pwd)"
+        print_success "Using existing repo at $INSTALL_DIR"
+        return
     fi
 
-    INSTALL_DIR="$(pwd)"
-    print_success "Running from $INSTALL_DIR"
+    # Check if repo exists in home directory
+    if [[ -d "$INSTALL_DIR" ]] && [[ -f "$INSTALL_DIR/main.py" ]]; then
+        print_success "Found existing repo at $INSTALL_DIR"
+        cd "$INSTALL_DIR"
+        echo "Pulling latest changes..."
+        git pull
+        return
+    fi
+
+    # Clone the repository
+    print_step "Cloning dune-weaver repository..."
+    git clone "$REPO_URL" --single-branch "$INSTALL_DIR"
+    cd "$INSTALL_DIR"
+    print_success "Cloned to $INSTALL_DIR"
 }
 
 # Install dw CLI command
@@ -230,7 +237,7 @@ deploy_docker() {
     print_step "Deploying Dune Weaver with Docker Compose..."
 
     cd "$INSTALL_DIR"
-    sudo docker compose up -d
+    sudo docker compose up -d --quiet-pull
 
     print_success "Docker deployment complete!"
 }
@@ -350,8 +357,8 @@ main() {
     echo ""
 
     # Run setup steps
-    check_directory
     check_raspberry_pi
+    ensure_repo
     update_system
     disable_wlan_powersave