← paintstorm-distrobox-legacy

Refactor: Extract embedded scripts into separate files for better organization

01b9c94314a65d847e862f692c93eb6e8558b3c4 · Claude · Jan 23, 2026 23:54

Breaking change: Script structure reorganized for maintainability

Changes:
- Extracted INNER_SCRIPT heredoc to container-setup.sh
- Extracted LAUNCHER heredoc to paintstorm-launcher.sh
- Extracted management script heredoc to paintstorm-manage.sh
- Main script now copies and executes separate files instead of inline heredocs
- Added SCRIPT_DIR variable to locate companion scripts
- Added validation to ensure required scripts exist before running

Benefits:
- Much cleaner and more maintainable code structure
- Easier to edit individual components
- Better separation of concerns
- Scripts can be version controlled independently
- Easier to test individual components
- No more deeply nested heredocs making code hard to read

Migration:
Users don't need to do anything - the main install script now looks for
the separate script files in the same directory and copies them as needed.

Files:
- paintstorm-install-distrobox.sh: Main orchestration (simplified)
- container-setup.sh: Container initialization (was INNER_SCRIPT)
- paintstorm-launcher.sh: App launcher (was LAUNCHER)
- paintstorm-manage.sh: Container management (was inline heredoc)

+373 −360 · 4 files changed

  • container-setup.sh +172 −0
  • paintstorm-install-distrobox.sh +49 −360
  • paintstorm-launcher.sh +53 −0
  • paintstorm-manage.sh +99 −0
diff --git a/container-setup.sh b/container-setup.sh
new file mode 100755
index 0000000..8c03737
--- /dev/null
+++ b/container-setup.sh
@@ -0,0 +1,172 @@
+#!/bin/bash
+# Paintstorm Container Setup Script
+# Runs inside the distrobox container to install dependencies and configure the environment
+
+set -e
+
+echo "==================================="
+echo "Container Setup"
+echo "==================================="
+
+# Configure locale
+echo "Configuring UTF-8 locale..."
+sudo apt update
+sudo apt install -y locales
+sudo locale-gen en_US.UTF-8
+sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
+
+if ! grep -q "export LC_ALL=en_US.UTF-8" ~/.bashrc; then
+    echo 'export LANG=en_US.UTF-8' >> ~/.bashrc
+    echo 'export LC_ALL=en_US.UTF-8' >> ~/.bashrc
+fi
+
+export LANG=en_US.UTF-8
+export LC_ALL=en_US.UTF-8
+
+echo ""
+echo "Installing build dependencies..."
+export DEBIAN_FRONTEND=noninteractive
+sudo apt install -y \
+    build-essential \
+    wget \
+    tar \
+    libgl1-mesa-dev \
+    libglu1-mesa-dev \
+    libx11-dev \
+    libxext-dev \
+    libxi-dev \
+    libxmu-dev \
+    patchelf
+
+echo ""
+echo "Installing runtime dependencies..."
+sudo apt install -y \
+    libgl1-mesa-glx \
+    libglu1-mesa \
+    libx11-6 \
+    libxext6 \
+    libxi6 \
+    libxrandr2 \
+    libxrender1 \
+    libgtk2.0-0 \
+    libpng16-16 \
+    libfreetype6 \
+    libfontconfig1 \
+    libxinerama1 \
+    libxcursor1 \
+    libxcomposite1 \
+    libxdamage1 \
+    libxfixes3 \
+    libftgl-dev \
+    libftgl2 \
+    libcurl4-gnutls-dev \
+    evtest
+
+# Install X11 input libraries for tablet support
+echo ""
+echo "Installing X11 input libraries for tablet support..."
+sudo apt install -y \
+    libxi6 \
+    libxtst6 \
+    libxinerama1 \
+    x11-xserver-utils \
+    xinput \
+    x11-apps \
+    x11-utils
+
+# NVIDIA environment
+if lspci | grep -i nvidia &> /dev/null; then
+    echo "Configuring NVIDIA environment..."
+    if ! grep -q "export __GLX_VENDOR_LIBRARY_NAME=nvidia" ~/.bashrc; then
+        echo 'export __GLX_VENDOR_LIBRARY_NAME=nvidia' >> ~/.bashrc
+    fi
+    export __GLX_VENDOR_LIBRARY_NAME=nvidia
+fi
+
+echo ""
+echo "Installing fonts (basic set, no CJK)..."
+sudo apt install -y \
+    fonts-liberation \
+    fonts-liberation2 \
+    fonts-dejavu \
+    fonts-dejavu-extra \
+    fonts-freefont-ttf \
+    fonts-ubuntu \
+    ttf-mscorefonts-installer
+
+echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
+
+echo ""
+echo "Rebuilding font cache..."
+sudo fc-cache -fv
+
+echo ""
+echo "Building GLEW 1.13.0 from source..."
+cd /tmp
+if [ ! -f "glew-1.13.0.tgz" ]; then
+    wget -q https://downloads.sourceforge.net/glew/glew-1.13.0.tgz
+fi
+tar xzf glew-1.13.0.tgz
+cd glew-1.13.0
+sed -i 's|lib64|lib|' config/Makefile.linux
+make -j$(nproc)
+echo "GLEW compiled successfully!"
+
+echo ""
+echo "Setting up Paintstorm directory..."
+sudo mkdir -p /usr/share/paintstorm
+sudo chown -R $USER:$USER /usr/share/paintstorm
+
+echo ""
+echo "Creating font directories (crash prevention)..."
+sudo mkdir -p /usr/share/fonts/opentype
+sudo mkdir -p /usr/share/fonts/truetype
+sudo touch /usr/share/fonts/opentype/.paintstorm
+sudo touch /usr/share/fonts/truetype/.paintstorm
+
+# Check device access in container
+echo ""
+echo "Checking device access..."
+
+# Check input devices
+if [ -d "/dev/input" ]; then
+    echo "Input devices in container:"
+    ls -la /dev/input/by-id/ 2>/dev/null || echo "  No input devices found"
+
+    # Test xinput
+    echo ""
+    echo "Testing xinput..."
+    xinput list 2>/dev/null || echo "  xinput not available or no devices"
+fi
+
+# Check hidraw devices (critical for pressure/tilt)
+echo ""
+echo "Checking hidraw devices (pressure/tilt data)..."
+if ls /dev/hidraw* &> /dev/null; then
+    ls -la /dev/hidraw* | sed 's/^/  /'
+    echo ""
+    echo "✓ Hidraw devices are available in container!"
+    echo "  This enables pressure/tilt support with OpenTabletDriver"
+else
+    echo "⚠ No hidraw devices found in container"
+    echo "  Pressure/tilt may not work"
+    echo "  Make sure OpenTabletDriver (otd-daemon) is running on host"
+fi
+
+# Add user to input group for device access (if group exists)
+echo ""
+echo "Configuring device permissions..."
+if getent group input > /dev/null 2>&1; then
+    if ! groups | grep -q input; then
+        sudo usermod -a -G input $USER
+        echo "✓ Added user to 'input' group"
+        echo "  You may need to logout/login for group changes to take effect"
+    else
+        echo "✓ User already in 'input' group"
+    fi
+else
+    echo "ℹ 'input' group not present in container (not needed - devices accessible)"
+fi
+
+echo ""
+echo "Container setup complete!"
diff --git a/paintstorm-install-distrobox.sh b/paintstorm-install-distrobox.sh
index 90eb486..88eef5e 100755
--- a/paintstorm-install-distrobox.sh
+++ b/paintstorm-install-distrobox.sh
@@ -3,7 +3,7 @@ set -e
 
 echo "=========================================="
 echo "Paintstorm Studio Distrobox Setup"
-echo "v2.3 - With Pen Tablet Support (Fixed)"
+echo "v2.4 - With Hidraw Passthrough"
 echo "=========================================="
 echo ""
 
@@ -11,6 +11,7 @@ echo ""
 CONTAINER_NAME="paintstorm-legacy"
 PAINTSTORM_DIR="/usr/share/paintstorm"
 WRAPPER_SCRIPT="$HOME/paintstorm"
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 
 # Colors
 RED='\033[0;31m'
@@ -39,6 +40,17 @@ if [ -z "$DISPLAY" ]; then
     exit 1
 fi
 
+# Check required scripts exist
+if [ ! -f "$SCRIPT_DIR/container-setup.sh" ]; then
+    echo -e "${RED}Error: container-setup.sh not found in $SCRIPT_DIR${NC}"
+    exit 1
+fi
+
+if [ ! -f "$SCRIPT_DIR/paintstorm-launcher.sh" ]; then
+    echo -e "${RED}Error: paintstorm-launcher.sh not found in $SCRIPT_DIR${NC}"
+    exit 1
+fi
+
 # Detect NVIDIA GPU
 NVIDIA_FLAG=""
 if lspci | grep -i nvidia &> /dev/null; then
@@ -138,179 +150,8 @@ fi
 echo ""
 echo -e "${GREEN}Step 2: Setting up Paintstorm environment in container...${NC}"
 
-# Create setup script
-cat > /tmp/paintstorm-container-setup.sh << 'INNER_SCRIPT'
-#!/bin/bash
-set -e
-
-echo "==================================="
-echo "Container Setup"
-echo "==================================="
-
-# Configure locale
-echo "Configuring UTF-8 locale..."
-sudo apt update
-sudo apt install -y locales
-sudo locale-gen en_US.UTF-8
-sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
-
-if ! grep -q "export LC_ALL=en_US.UTF-8" ~/.bashrc; then
-    echo 'export LANG=en_US.UTF-8' >> ~/.bashrc
-    echo 'export LC_ALL=en_US.UTF-8' >> ~/.bashrc
-fi
-
-export LANG=en_US.UTF-8
-export LC_ALL=en_US.UTF-8
-
-echo ""
-echo "Installing build dependencies..."
-export DEBIAN_FRONTEND=noninteractive
-sudo apt install -y \
-    build-essential \
-    wget \
-    tar \
-    libgl1-mesa-dev \
-    libglu1-mesa-dev \
-    libx11-dev \
-    libxext-dev \
-    libxi-dev \
-    libxmu-dev \
-    patchelf
-
-echo ""
-echo "Installing runtime dependencies..."
-sudo apt install -y \
-    libgl1-mesa-glx \
-    libglu1-mesa \
-    libx11-6 \
-    libxext6 \
-    libxi6 \
-    libxrandr2 \
-    libxrender1 \
-    libgtk2.0-0 \
-    libpng16-16 \
-    libfreetype6 \
-    libfontconfig1 \
-    libxinerama1 \
-    libxcursor1 \
-    libxcomposite1 \
-    libxdamage1 \
-    libxfixes3 \
-    libftgl-dev \
-    libftgl2 \
-    libcurl4-gnutls-dev \
-    evtest
-
-# Install X11 input libraries for tablet support
-echo ""
-echo "Installing X11 input libraries for tablet support..."
-sudo apt install -y \
-    libxi6 \
-    libxtst6 \
-    libxinerama1 \
-    x11-xserver-utils \
-    xinput \
-    x11-apps \
-    x11-utils
-
-# NVIDIA environment
-if lspci | grep -i nvidia &> /dev/null; then
-    echo "Configuring NVIDIA environment..."
-    if ! grep -q "export __GLX_VENDOR_LIBRARY_NAME=nvidia" ~/.bashrc; then
-        echo 'export __GLX_VENDOR_LIBRARY_NAME=nvidia' >> ~/.bashrc
-    fi
-    export __GLX_VENDOR_LIBRARY_NAME=nvidia
-fi
-
-echo ""
-echo "Installing fonts (basic set, no CJK)..."
-sudo apt install -y \
-    fonts-liberation \
-    fonts-liberation2 \
-    fonts-dejavu \
-    fonts-dejavu-extra \
-    fonts-freefont-ttf \
-    fonts-ubuntu \
-    ttf-mscorefonts-installer
-
-echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
-
-echo ""
-echo "Rebuilding font cache..."
-sudo fc-cache -fv
-
-echo ""
-echo "Building GLEW 1.13.0 from source..."
-cd /tmp
-if [ ! -f "glew-1.13.0.tgz" ]; then
-    wget -q https://downloads.sourceforge.net/glew/glew-1.13.0.tgz
-fi
-tar xzf glew-1.13.0.tgz
-cd glew-1.13.0
-sed -i 's|lib64|lib|' config/Makefile.linux
-make -j$(nproc)
-echo "GLEW compiled successfully!"
-
-echo ""
-echo "Setting up Paintstorm directory..."
-sudo mkdir -p /usr/share/paintstorm
-sudo chown -R $USER:$USER /usr/share/paintstorm
-
-echo ""
-echo "Creating font directories (crash prevention)..."
-sudo mkdir -p /usr/share/fonts/opentype
-sudo mkdir -p /usr/share/fonts/truetype
-sudo touch /usr/share/fonts/opentype/.paintstorm
-sudo touch /usr/share/fonts/truetype/.paintstorm
-
-# Check device access in container
-echo ""
-echo "Checking device access..."
-
-# Check input devices
-if [ -d "/dev/input" ]; then
-    echo "Input devices in container:"
-    ls -la /dev/input/by-id/ 2>/dev/null || echo "  No input devices found"
-
-    # Test xinput
-    echo ""
-    echo "Testing xinput..."
-    xinput list 2>/dev/null || echo "  xinput not available or no devices"
-fi
-
-# Check hidraw devices (critical for pressure/tilt)
-echo ""
-echo "Checking hidraw devices (pressure/tilt data)..."
-if ls /dev/hidraw* &> /dev/null; then
-    ls -la /dev/hidraw* | sed 's/^/  /'
-    echo ""
-    echo "✓ Hidraw devices are available in container!"
-    echo "  This enables pressure/tilt support with OpenTabletDriver"
-else
-    echo "⚠ No hidraw devices found in container"
-    echo "  Pressure/tilt may not work"
-    echo "  Make sure OpenTabletDriver (otd-daemon) is running on host"
-fi
-
-# Add user to input group for device access (if group exists)
-echo ""
-echo "Configuring device permissions..."
-if getent group input > /dev/null 2>&1; then
-    if ! groups | grep -q input; then
-        sudo usermod -a -G input $USER
-        echo "✓ Added user to 'input' group"
-        echo "  You may need to logout/login for group changes to take effect"
-    else
-        echo "✓ User already in 'input' group"
-    fi
-else
-    echo "ℹ 'input' group not present in container (not needed - devices accessible)"
-fi
-
-echo ""
-echo "Container setup complete!"
-INNER_SCRIPT
-
+# Copy container setup script to /tmp and execute it
+cp "$SCRIPT_DIR/container-setup.sh" /tmp/paintstorm-container-setup.sh
 chmod +x /tmp/paintstorm-container-setup.sh
 distrobox enter "$CONTAINER_NAME" -- bash /tmp/paintstorm-container-setup.sh
 
@@ -350,60 +191,60 @@ fi
 if [ -n "$INSTALLER_PATH" ]; then
     echo ""
     echo "Installing Paintstorm..."
-    
+
     # Extract to a clean temp directory
     EXTRACT_DIR="/tmp/paintstorm-extract-$$"
     mkdir -p "$EXTRACT_DIR"
-    
+
     echo "Extracting installer..."
     # We use --target, but we will find the actual folder dynamically
     sh "$INSTALLER_PATH" --noexec --target "$EXTRACT_DIR"
-    
+
     # Dynamically find where the 'paintstorm' binary folder is
     ACTUAL_SRC=$(find "$EXTRACT_DIR" -type d -name "paintstorm" | head -n 1)
-    
+
     if [ -z "$ACTUAL_SRC" ]; then
         echo -e "${RED}Error: Extraction failed to produce a 'paintstorm' directory${NC}"
         ls -R "$EXTRACT_DIR"
         exit 1
     fi
-    
+
     echo "Copying files from $ACTUAL_SRC to container..."
     distrobox enter "$CONTAINER_NAME" -- bash << INSTALL_CMD
         set -e
-        
+
         # Copy Paintstorm files using the dynamically found path
         sudo cp -r "$ACTUAL_SRC/"* /usr/share/paintstorm/
-        
+
         # Copy GLEW libraries
         if [ -f /tmp/glew-1.13.0/lib/libGLEW.so ]; then
             sudo cp /tmp/glew-1.13.0/lib/libGLEW.so* /usr/share/paintstorm/
         fi
-        
+
         # Fix RPATH
         sudo patchelf --set-rpath '\$ORIGIN' /usr/share/paintstorm/Paintstorm
-        
+
         # Set permissions
         sudo chown -R \$USER:\$USER /usr/share/paintstorm
         sudo chmod +x /usr/share/paintstorm/Paintstorm
-        
+
         echo "Installation complete!"
 INSTALL_CMD
-    
+
     # Cleanup
     rm -rf "$EXTRACT_DIR"
-    
+
 else
     echo -e "${YELLOW}Paintstorm installer not found.${NC}"
     echo ""
     read -p "Enter path to Paintstorm_linux_v2.50.run (or 'skip'): " user_path
-    
+
     if [ "$user_path" != "skip" ] && [ -f "$user_path" ]; then
         EXTRACT_DIR="/tmp/paintstorm-extract-$$"
         mkdir -p "$EXTRACT_DIR"
         cd "$EXTRACT_DIR"
         sh "$user_path" --noexec --target "$EXTRACT_DIR/paintstorm_files"
-        
+
         distrobox enter "$CONTAINER_NAME" -- bash << INSTALL_CMD
             sudo cp -r "$EXTRACT_DIR/paintstorm_files/PaintstormInstall/paintstorm/"* /usr/share/paintstorm/
             sudo cp /tmp/glew-1.13.0/lib/libGLEW.so* /usr/share/paintstorm/
@@ -422,81 +263,28 @@ echo -e "${GREEN}Step 3: Verifying installation...${NC}"
 
 if distrobox enter "$CONTAINER_NAME" -- test -f "$PAINTSTORM_DIR/Paintstorm"; then
     echo -e "${GREEN}✓ Paintstorm binary found!${NC}"
-    
+
     # Verify GLEW
     if distrobox enter "$CONTAINER_NAME" -- test -f "$PAINTSTORM_DIR/libGLEW.so.1.13"; then
         echo -e "${GREEN}✓ GLEW 1.13 libraries installed!${NC}"
     fi
-    
+
     # Verify font directories
     if distrobox enter "$CONTAINER_NAME" -- test -d "/usr/share/fonts/opentype"; then
         echo -e "${GREEN}✓ Font crash prevention configured!${NC}"
     fi
-    
+
     echo ""
     echo -e "${GREEN}Step 4: Creating wrapper script with tablet support...${NC}"
-    
-    # Get X11 socket path
-    X11_SOCKET="/tmp/.X11-unix/X$(echo $DISPLAY | cut -d: -f2 | cut -d. -f1)"
-    
-    cat > "$WRAPPER_SCRIPT" << 'LAUNCHER'
-#!/bin/bash
-# Set up environment for tablet support
-export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
-export WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-}
-export QT_QPA_PLATFORM=${QT_QPA_PLATFORM:-xcb}
-export GDK_BACKEND=${GDK_BACKEND:-x11}
-export SDL_VIDEODRIVER=${SDL_VIDEODRIVER:-x11}
-
-# Additional tablet environment variables
-export WACOMDEBUG=1
-export XINPUT_GXI=1
-
-# Debug info
-echo "=== Paintstorm Launch Debug ==="
-echo "DISPLAY: $DISPLAY"
-echo "XAUTHORITY: ${XAUTHORITY:-$HOME/.Xauthority}"
-echo ""
-echo "Input devices:"
-ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E "(tablet|wacom|pen|huion)" || echo "  No tablet devices found"
-echo ""
-echo "Hidraw devices (pressure/tilt):"
-ls -la /dev/hidraw* 2>/dev/null || echo "  No hidraw devices (pressure/tilt won't work!)"
-echo "==============================="
-
-# Launch Paintstorm
-distrobox-enter -n paintstorm-legacy -- bash -c "
-    export LANG=en_US.UTF-8
-    export LC_ALL=en_US.UTF-8
-    export DISPLAY=$DISPLAY
-    export XAUTHORITY=${XAUTHORITY:-$HOME/.Xauthority}
-    export __GLX_VENDOR_LIBRARY_NAME=nvidia
-    
-    # Additional tablet env vars
-    export WACOMDEBUG=1
-    export XINPUT_GXI=1
-    
-    # Debug container devices
-    echo ''
-    echo 'Container input devices:'
-    ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion)' || echo '  No tablet devices in container'
-    echo ''
-    echo 'Container hidraw devices (pressure/tilt):'
-    ls -la /dev/hidraw* 2>/dev/null || echo '  No hidraw devices (pressure/tilt will NOT work!)'
-    echo ''
-    echo 'xinput list:'
-    xinput list 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion|stylus)' || echo '  No tablet in xinput'
-    
-    cd /usr/share/paintstorm
-    exec ./Paintstorm \"\$@\"
-"
-LAUNCHER
+
+    # Copy launcher script to home directory
+    cp "$SCRIPT_DIR/paintstorm-launcher.sh" "$WRAPPER_SCRIPT"
     chmod +x "$WRAPPER_SCRIPT"
-    echo -e "${GREEN}✓ Created $WRAPPER_SCRIPT with tablet support${NC}"
-    
+    echo -e "${GREEN}✓ Created $WRAPPER_SCRIPT${NC}"
+
     echo ""
     echo -e "${GREEN}Step 5: Creating desktop launcher...${NC}"
-    
+
     mkdir -p ~/.local/share/applications
     cat > ~/.local/share/applications/paintstorm.desktop << EOF
 [Desktop Entry]
@@ -518,11 +306,11 @@ EOF
             echo -e "${GREEN}✓ Desktop file is valid${NC}"
         fi
     fi
-    
+
     echo ""
     echo -e "${GREEN}Step 6: Setting up icon...${NC}"
     mkdir -p ~/.local/share/icons/hicolor/256x256/apps
-    
+
     # Check for paintstorm-icon.png
     if [ -f "paintstorm-icon.png" ]; then
         cp paintstorm-icon.png ~/.local/share/icons/hicolor/256x256/apps/paintstorm.png
@@ -534,18 +322,18 @@ EOF
         echo -e "${YELLOW}⚠ paintstorm-icon.png not found in current directory${NC}"
         echo "  Place paintstorm-icon.png here and run: cp paintstorm-icon.png ~/.local/share/icons/hicolor/256x256/apps/paintstorm.png"
     fi
-    
+
     # Update databases
     update-desktop-database ~/.local/share/applications 2>/dev/null || true
     gtk-update-icon-cache ~/.local/share/icons/hicolor/ -f 2>/dev/null || true
-    
+
     # XFCE restart
     if command -v xfce4-panel &> /dev/null; then
         echo ""
         echo -e "${BLUE}Restarting XFCE panel...${NC}"
         xfce4-panel --restart 2>/dev/null || true
     fi
-    
+
     echo ""
     echo -e "${GREEN}=========================================="
     echo "✓ Installation Complete!"
@@ -578,7 +366,7 @@ EOF
     echo "  • Hidraw devices must be present on host AND in container"
     echo "  • Run './test-tablet-pressure.sh' to diagnose issues"
     echo ""
-    
+
 else
     echo -e "${RED}✗ Paintstorm not found${NC}"
     echo ""
@@ -588,109 +376,10 @@ else
     echo "  sudo patchelf --set-rpath '\$ORIGIN' /usr/share/paintstorm/Paintstorm"
 fi
 
-# Create management script
-cat > ~/paintstorm-manage.sh << 'MANAGE_SCRIPT'
-#!/bin/bash
-CONTAINER_NAME="paintstorm-legacy"
-EXPORT_FILE="paintstorm-container-$(date +%Y%m%d).tar"
-
-echo "Paintstorm Container Management"
-echo "================================"
-echo "1) Export container"
-echo "2) Import container"
-echo "3) Container info"
-echo "4) Test tablet input"
-echo "5) Fix tablet permissions"
-echo "6) Exit"
-read -p "Choice: " choice
-
-case $choice in
-    1)
-        if command -v podman &> /dev/null; then
-            podman commit $CONTAINER_NAME paintstorm-legacy-image
-            podman save paintstorm-legacy-image -o "$EXPORT_FILE"
-        else
-            docker commit $CONTAINER_NAME paintstorm-legacy-image
-            docker save paintstorm-legacy-image -o "$EXPORT_FILE"
-        fi
-        echo "✓ Exported to $EXPORT_FILE"
-        ;;
-    2)
-        read -p "Enter .tar file: " tarfile
-        if [ -f "$tarfile" ]; then
-            if command -v podman &> /dev/null; then
-                podman load -i "$tarfile"
-                NVIDIA_FLAG=$(lspci | grep -qi nvidia && echo "--nvidia" || echo "")
-                distrobox create --image localhost/paintstorm-legacy-image:latest --name $CONTAINER_NAME $NVIDIA_FLAG
-            else
-                docker load -i "$tarfile"
-                distrobox create --image paintstorm-legacy-image:latest --name $CONTAINER_NAME
-            fi
-            echo "✓ Imported!"
-        fi
-        ;;
-    3)
-        distrobox list | grep $CONTAINER_NAME
-        distrobox enter $CONTAINER_NAME -- bash -c "echo 'Fonts: '\$(fc-list | wc -l)"
-        ;;
-    4)
-        echo "=== Testing tablet input ==="
-        echo ""
-        echo "HOST SYSTEM:"
-        echo "------------"
-        echo "Input devices:"
-        ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E "(tablet|wacom|pen|huion)" || echo "  No tablet devices found"
-        echo ""
-        echo "Hidraw devices (pressure/tilt):"
-        ls -la /dev/hidraw* 2>/dev/null || echo "  No hidraw devices found"
-        echo ""
-        echo "CONTAINER:"
-        echo "----------"
-        echo "Input devices:"
-        distrobox enter $CONTAINER_NAME -- bash -c "ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion)' || echo '  No tablet devices found'"
-        echo ""
-        echo "Hidraw devices (pressure/tilt):"
-        distrobox enter $CONTAINER_NAME -- bash -c "ls -la /dev/hidraw* 2>/dev/null || echo '  No hidraw devices found'"
-        echo ""
-        echo "XInput in container:"
-        distrobox enter $CONTAINER_NAME -- bash -c "xinput list 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion)' || echo '  No tablet in xinput'"
-        echo ""
-        echo "DIAGNOSIS:"
-        HOST_HIDRAW=$(ls /dev/hidraw* 2>/dev/null | wc -l)
-        CONTAINER_HIDRAW=$(distrobox enter $CONTAINER_NAME -- bash -c "ls /dev/hidraw* 2>/dev/null | wc -l" 2>/dev/null || echo 0)
-        echo "  Host hidraw count: $HOST_HIDRAW"
-        echo "  Container hidraw count: $CONTAINER_HIDRAW"
-        if [ "$HOST_HIDRAW" -gt 0 ] && [ "$CONTAINER_HIDRAW" -eq 0 ]; then
-            echo ""
-            echo "  ✗ PROBLEM: Hidraw devices on host but not in container!"
-            echo "    You need to recreate the container to pass hidraw devices"
-        elif [ "$HOST_HIDRAW" -eq 0 ]; then
-            echo ""
-            echo "  ✗ PROBLEM: No hidraw devices on host"
-            echo "    Make sure OpenTabletDriver is running: otd-daemon"
-        elif [ "$CONTAINER_HIDRAW" -gt 0 ]; then
-            echo ""
-            echo "  ✓ Hidraw devices present in container - pressure/tilt should work!"
-        fi
-        ;;
-    5)
-        echo "=== Fixing tablet permissions ==="
-        echo "This will add your user to the input group and fix device permissions..."
-        sudo usermod -a -G input $USER
-        echo "You may need to logout/login for group changes to take effect"
-        echo ""
-        echo "Current input device permissions:"
-        ls -la /dev/input/event* 2>/dev/null | head -5
-        echo ""
-        echo "To fix permissions temporarily:"
-        echo "  sudo chmod a+rw /dev/input/event*"
-        ;;
-esac
-MANAGE_SCRIPT
-
-chmod +x ~/paintstorm-manage.sh
-
+# Create management script in home directory
 echo ""
-echo -e "${GREEN}✓ Created ~/paintstorm-manage.sh${NC}"
+echo -e "${GREEN}Step 7: Installing management script...${NC}"
+cp "$SCRIPT_DIR/paintstorm-manage.sh" ~/paintstorm-manage.sh
+chmod +x ~/paintstorm-manage.sh
+echo -e "${GREEN}✓ Installed ~/paintstorm-manage.sh${NC}"
 echo ""
-
diff --git a/paintstorm-launcher.sh b/paintstorm-launcher.sh
new file mode 100755
index 0000000..06d365e
--- /dev/null
+++ b/paintstorm-launcher.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+# Paintstorm Studio Launcher Script
+# Launches Paintstorm in the distrobox container with proper environment setup
+
+# Set up environment for tablet support
+export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
+export WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-}
+export QT_QPA_PLATFORM=${QT_QPA_PLATFORM:-xcb}
+export GDK_BACKEND=${GDK_BACKEND:-x11}
+export SDL_VIDEODRIVER=${SDL_VIDEODRIVER:-x11}
+
+# Additional tablet environment variables
+export WACOMDEBUG=1
+export XINPUT_GXI=1
+
+# Debug info
+echo "=== Paintstorm Launch Debug ==="
+echo "DISPLAY: $DISPLAY"
+echo "XAUTHORITY: ${XAUTHORITY:-$HOME/.Xauthority}"
+echo ""
+echo "Input devices:"
+ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E "(tablet|wacom|pen|huion)" || echo "  No tablet devices found"
+echo ""
+echo "Hidraw devices (pressure/tilt):"
+ls -la /dev/hidraw* 2>/dev/null || echo "  No hidraw devices (pressure/tilt won't work!)"
+echo "==============================="
+
+# Launch Paintstorm
+distrobox-enter -n paintstorm-legacy -- bash -c "
+    export LANG=en_US.UTF-8
+    export LC_ALL=en_US.UTF-8
+    export DISPLAY=$DISPLAY
+    export XAUTHORITY=${XAUTHORITY:-$HOME/.Xauthority}
+    export __GLX_VENDOR_LIBRARY_NAME=nvidia
+
+    # Additional tablet env vars
+    export WACOMDEBUG=1
+    export XINPUT_GXI=1
+
+    # Debug container devices
+    echo ''
+    echo 'Container input devices:'
+    ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion)' || echo '  No tablet devices in container'
+    echo ''
+    echo 'Container hidraw devices (pressure/tilt):'
+    ls -la /dev/hidraw* 2>/dev/null || echo '  No hidraw devices (pressure/tilt will NOT work!)'
+    echo ''
+    echo 'xinput list:'
+    xinput list 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion|stylus)' || echo '  No tablet in xinput'
+
+    cd /usr/share/paintstorm
+    exec ./Paintstorm \"\$@\"
+"
diff --git a/paintstorm-manage.sh b/paintstorm-manage.sh
new file mode 100755
index 0000000..ee178f3
--- /dev/null
+++ b/paintstorm-manage.sh
@@ -0,0 +1,99 @@
+#!/bin/bash
+# Paintstorm Container Management Script
+# Provides utilities for managing the Paintstorm distrobox container
+
+CONTAINER_NAME="paintstorm-legacy"
+EXPORT_FILE="paintstorm-container-$(date +%Y%m%d).tar"
+
+echo "Paintstorm Container Management"
+echo "================================"
+echo "1) Export container"
+echo "2) Import container"
+echo "3) Container info"
+echo "4) Test tablet input"
+echo "5) Fix tablet permissions"
+echo "6) Exit"
+read -p "Choice: " choice
+
+case $choice in
+    1)
+        if command -v podman &> /dev/null; then
+            podman commit $CONTAINER_NAME paintstorm-legacy-image
+            podman save paintstorm-legacy-image -o "$EXPORT_FILE"
+        else
+            docker commit $CONTAINER_NAME paintstorm-legacy-image
+            docker save paintstorm-legacy-image -o "$EXPORT_FILE"
+        fi
+        echo "✓ Exported to $EXPORT_FILE"
+        ;;
+    2)
+        read -p "Enter .tar file: " tarfile
+        if [ -f "$tarfile" ]; then
+            if command -v podman &> /dev/null; then
+                podman load -i "$tarfile"
+                NVIDIA_FLAG=$(lspci | grep -qi nvidia && echo "--nvidia" || echo "")
+                distrobox create --image localhost/paintstorm-legacy-image:latest --name $CONTAINER_NAME $NVIDIA_FLAG
+            else
+                docker load -i "$tarfile"
+                distrobox create --image paintstorm-legacy-image:latest --name $CONTAINER_NAME
+            fi
+            echo "✓ Imported!"
+        fi
+        ;;
+    3)
+        distrobox list | grep $CONTAINER_NAME
+        distrobox enter $CONTAINER_NAME -- bash -c "echo 'Fonts: '\$(fc-list | wc -l)"
+        ;;
+    4)
+        echo "=== Testing tablet input ==="
+        echo ""
+        echo "HOST SYSTEM:"
+        echo "------------"
+        echo "Input devices:"
+        ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E "(tablet|wacom|pen|huion)" || echo "  No tablet devices found"
+        echo ""
+        echo "Hidraw devices (pressure/tilt):"
+        ls -la /dev/hidraw* 2>/dev/null || echo "  No hidraw devices found"
+        echo ""
+        echo "CONTAINER:"
+        echo "----------"
+        echo "Input devices:"
+        distrobox enter $CONTAINER_NAME -- bash -c "ls -la /dev/input/by-id/ 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion)' || echo '  No tablet devices found'"
+        echo ""
+        echo "Hidraw devices (pressure/tilt):"
+        distrobox enter $CONTAINER_NAME -- bash -c "ls -la /dev/hidraw* 2>/dev/null || echo '  No hidraw devices found'"
+        echo ""
+        echo "XInput in container:"
+        distrobox enter $CONTAINER_NAME -- bash -c "xinput list 2>/dev/null | grep -i -E '(tablet|wacom|pen|huion)' || echo '  No tablet in xinput'"
+        echo ""
+        echo "DIAGNOSIS:"
+        HOST_HIDRAW=$(ls /dev/hidraw* 2>/dev/null | wc -l)
+        CONTAINER_HIDRAW=$(distrobox enter $CONTAINER_NAME -- bash -c "ls /dev/hidraw* 2>/dev/null | wc -l" 2>/dev/null || echo 0)
+        echo "  Host hidraw count: $HOST_HIDRAW"
+        echo "  Container hidraw count: $CONTAINER_HIDRAW"
+        if [ "$HOST_HIDRAW" -gt 0 ] && [ "$CONTAINER_HIDRAW" -eq 0 ]; then
+            echo ""
+            echo "  ✗ PROBLEM: Hidraw devices on host but not in container!"
+            echo "    You need to recreate the container to pass hidraw devices"
+        elif [ "$HOST_HIDRAW" -eq 0 ]; then
+            echo ""
+            echo "  ✗ PROBLEM: No hidraw devices on host"
+            echo "    Make sure OpenTabletDriver is running: otd-daemon"
+        elif [ "$CONTAINER_HIDRAW" -gt 0 ]; then
+            echo ""
+            echo "  ✓ Hidraw devices present in container - pressure/tilt should work!"
+        fi
+        ;;
+    5)
+        echo "=== Fixing tablet permissions ==="
+        echo "This will add your user to the input group and fix device permissions..."
+        sudo usermod -a -G input $USER
+        echo "You may need to logout/login for group changes to take effect"
+        echo ""
+        echo "Current input device permissions:"
+        ls -la /dev/input/event* 2>/dev/null | head -5
+        echo ""
+        echo "To fix permissions temporarily:"
+        echo "  sudo chmod a+rw /dev/input/event*"
+        ;;
+esac