|
5 | 5 | # |
6 | 6 | # This is the new, clean modular entry point for the Minecraft Splitscreen installer. |
7 | 7 | # All functionality has been moved to organized modules for better maintainability. |
| 8 | +# Required modules are automatically downloaded as temporary files when the script runs. |
8 | 9 | # |
9 | 10 | # Features: |
| 11 | +# - Automatic temporary module downloading (modules are cleaned up after completion) |
10 | 12 | # - Automatic Java detection and installation |
11 | 13 | # - Complete Fabric dependency chain implementation |
12 | 14 | # - API filtering for Fabric-compatible mods (Modrinth + CurseForge) |
|
15 | 17 | # - Steam Deck optimized installation |
16 | 18 | # - Comprehensive Steam and desktop integration |
17 | 19 | # |
18 | | -# No additional setup, Java installation, or token files are required - just run this script. |
| 20 | +# No additional setup, Java installation, token files, or module downloads required - just run this script. |
| 21 | +# Modules are downloaded temporarily and automatically cleaned up when the script completes. |
19 | 22 | # |
20 | 23 | # ============================================================================= |
21 | 24 |
|
22 | 25 | set -euo pipefail # Exit on error, undefined vars, pipe failures |
23 | 26 |
|
24 | 27 | # ============================================================================= |
25 | | -# MODULE LOADING |
| 28 | +# CLEANUP AND SIGNAL HANDLING |
| 29 | +# ============================================================================= |
| 30 | + |
| 31 | +# Global variable for modules directory (will be set later) |
| 32 | +MODULES_DIR="" |
| 33 | + |
| 34 | +# Cleanup function to remove temporary modules directory |
| 35 | +cleanup() { |
| 36 | + if [[ -n "$MODULES_DIR" ]] && [[ -d "$MODULES_DIR" ]]; then |
| 37 | + echo "🧹 Cleaning up temporary modules..." |
| 38 | + rm -rf "$MODULES_DIR" |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +# Set up trap to cleanup on script exit (normal or error) |
| 43 | +trap cleanup EXIT INT TERM |
| 44 | + |
| 45 | +# ============================================================================= |
| 46 | +# MODULE DOWNLOADING AND LOADING |
26 | 47 | # ============================================================================= |
27 | 48 |
|
28 | 49 | # Get the directory where this script is located |
29 | 50 | readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
30 | | -readonly MODULES_DIR="$SCRIPT_DIR/modules" |
| 51 | +# Create a temporary directory for modules that will be cleaned up automatically |
| 52 | +MODULES_DIR="$(mktemp -d -t minecraft-modules-XXXXXX)" |
31 | 53 |
|
32 | | -# Verify modules directory exists |
33 | | -if [[ ! -d "$MODULES_DIR" ]]; then |
34 | | - echo "❌ Error: modules directory not found at $MODULES_DIR" |
35 | | - echo "Please ensure all module files are present in the modules/ directory" |
36 | | - exit 1 |
| 54 | +# GitHub repository information (modify these URLs to match your actual repository) |
| 55 | +readonly REPO_BASE_URL="https://raw.githubusercontent.com/FlyingEwok/MinecraftSplitscreenSteamdeck/main/modules" |
| 56 | + |
| 57 | +# List of required module files |
| 58 | +readonly MODULE_FILES=( |
| 59 | + "utilities.sh" |
| 60 | + "java_management.sh" |
| 61 | + "launcher_setup.sh" |
| 62 | + "version_management.sh" |
| 63 | + "lwjgl_management.sh" |
| 64 | + "mod_management.sh" |
| 65 | + "instance_creation.sh" |
| 66 | + "pollymc_setup.sh" |
| 67 | + "steam_integration.sh" |
| 68 | + "desktop_launcher.sh" |
| 69 | + "main_workflow.sh" |
| 70 | +) |
| 71 | + |
| 72 | +# Function to download modules if they don't exist |
| 73 | +download_modules() { |
| 74 | + echo "🔄 Downloading required modules to temporary directory..." |
| 75 | + echo "📁 Temporary modules directory: $MODULES_DIR" |
| 76 | + echo "🌐 Repository URL: $REPO_BASE_URL" |
| 77 | + |
| 78 | + # Temporarily disable strict error handling for downloads |
| 79 | + set +e |
| 80 | + |
| 81 | + # The temporary directory is already created by mktemp |
| 82 | + local downloaded_count=0 |
| 83 | + local failed_count=0 |
| 84 | + |
| 85 | + # Download each required module |
| 86 | + for module in "${MODULE_FILES[@]}"; do |
| 87 | + local module_path="$MODULES_DIR/$module" |
| 88 | + local module_url="$REPO_BASE_URL/$module" |
| 89 | + |
| 90 | + echo "⬇️ Downloading module: $module" |
| 91 | + echo " URL: $module_url" |
| 92 | + |
| 93 | + # Download the module file |
| 94 | + if command -v curl >/dev/null 2>&1; then |
| 95 | + curl_output=$(curl -fsSL "$module_url" -o "$module_path" 2>&1) |
| 96 | + curl_exit_code=$? |
| 97 | + if [[ $curl_exit_code -eq 0 ]]; then |
| 98 | + chmod +x "$module_path" |
| 99 | + ((downloaded_count++)) |
| 100 | + echo "✅ Downloaded: $module" |
| 101 | + else |
| 102 | + echo "❌ Failed to download: $module" |
| 103 | + echo " Curl exit code: $curl_exit_code" |
| 104 | + echo " Error: $curl_output" |
| 105 | + ((failed_count++)) |
| 106 | + fi |
| 107 | + elif command -v wget >/dev/null 2>&1; then |
| 108 | + wget_output=$(wget -q "$module_url" -O "$module_path" 2>&1) |
| 109 | + wget_exit_code=$? |
| 110 | + if [[ $wget_exit_code -eq 0 ]]; then |
| 111 | + chmod +x "$module_path" |
| 112 | + ((downloaded_count++)) |
| 113 | + echo "✅ Downloaded: $module" |
| 114 | + else |
| 115 | + echo "❌ Failed to download: $module" |
| 116 | + echo " Wget exit code: $wget_exit_code" |
| 117 | + echo " Error: $wget_output" |
| 118 | + ((failed_count++)) |
| 119 | + fi |
| 120 | + else |
| 121 | + echo "❌ Error: Neither curl nor wget is available" |
| 122 | + echo "Please install curl or wget to download modules automatically" |
| 123 | + echo "Or manually download all modules from: $REPO_BASE_URL" |
| 124 | + # Re-enable strict error handling before exiting |
| 125 | + set -euo pipefail |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | + done |
| 129 | + |
| 130 | + # Re-enable strict error handling |
| 131 | + set -euo pipefail |
| 132 | + |
| 133 | + if [[ $failed_count -gt 0 ]]; then |
| 134 | + echo "❌ Failed to download $failed_count module(s)" |
| 135 | + echo "ℹ️ This might be because:" |
| 136 | + echo " - The repository doesn't exist or is private" |
| 137 | + echo " - The modules haven't been uploaded to the repository yet" |
| 138 | + echo " - Network connectivity issues" |
| 139 | + echo "" |
| 140 | + echo "🔧 For now, you can place the modules manually in the same directory as this script:" |
| 141 | + echo " mkdir -p '$SCRIPT_DIR/modules'" |
| 142 | + echo " # Then copy all .sh module files to that directory" |
| 143 | + echo "" |
| 144 | + echo "🌐 Or check if the repository exists at: https://github.com/FlyingEwok/MinecraftSplitscreenSteamdeck" |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | + |
| 148 | + echo "✅ Downloaded $downloaded_count module(s) to temporary directory" |
| 149 | + echo "ℹ️ Modules will be automatically cleaned up when script completes" |
| 150 | +} |
| 151 | + |
| 152 | +# Download modules if needed |
| 153 | +# First check if modules exist locally, if not try to download them |
| 154 | +if [[ -d "$SCRIPT_DIR/modules" ]]; then |
| 155 | + echo "📁 Found local modules directory, copying to temporary location..." |
| 156 | + cp -r "$SCRIPT_DIR/modules/"* "$MODULES_DIR/" |
| 157 | + chmod +x "$MODULES_DIR"/*.sh |
| 158 | + echo "✅ Copied local modules to temporary directory" |
| 159 | +else |
| 160 | + download_modules |
37 | 161 | fi |
38 | 162 |
|
| 163 | +# Verify all modules are now present |
| 164 | +for module in "${MODULE_FILES[@]}"; do |
| 165 | + if [[ ! -f "$MODULES_DIR/$module" ]]; then |
| 166 | + echo "❌ Error: Required module missing: $module" |
| 167 | + echo "Please check your internet connection or download manually from:" |
| 168 | + echo "$REPO_BASE_URL/$module" |
| 169 | + exit 1 |
| 170 | + fi |
| 171 | +done |
| 172 | + |
39 | 173 | # Source all module files to load their functions |
40 | 174 | # Load modules in dependency order |
41 | 175 | source "$MODULES_DIR/utilities.sh" |
|
0 commit comments