|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# -------------------- UPGRADE SCRIPT TEMPLATE -------------------- |
| 4 | +# Instructions: |
| 5 | +# 1. Set the TARGET_VERSION to the version you're upgrading to. |
| 6 | +# 2. Add your file updates in the designated section using the update_file function. |
| 7 | +# 3. Ensure all paths are correct for your specific upgrade scenario. |
| 8 | +# 4. Add any additional upgrade steps as needed. |
| 9 | + |
| 10 | +# Define the target version for this upgrade script |
| 11 | +TARGET_VERSION="3.3.1" # Replace X.Y.Z with your target version number |
| 12 | + |
| 13 | +/mnt/SDCARD/spruce/scripts/helperFunctions.sh |
| 14 | + |
| 15 | +# Source the helper functions |
| 16 | +HELPER_FUNCTIONS="/mnt/SDCARD/spruce/scripts/helperFunctions.sh" |
| 17 | +if [ -f "$HELPER_FUNCTIONS" ]; then |
| 18 | + . "$HELPER_FUNCTIONS" |
| 19 | +else |
| 20 | + echo "Error: helperFunctions.sh not found, cannot proceed with the upgrade" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Function to update specific settings in a file |
| 25 | +# Usage: update_file "file_path" "setting1=value1" "setting2=value2" ... |
| 26 | +update_file() { |
| 27 | + file="$1" |
| 28 | + shift |
| 29 | + |
| 30 | + for setting in "$@"; do |
| 31 | + if grep -q "${setting%%=*}" "$file"; then |
| 32 | + sed -i "s|^${setting%%=*}.*|$setting|" "$file" |
| 33 | + else |
| 34 | + echo "$setting" >> "$file" |
| 35 | + fi |
| 36 | + done |
| 37 | + |
| 38 | + log_message "Updated $file" |
| 39 | +} |
| 40 | + |
| 41 | +# Function to update launch paths in JSON files |
| 42 | +update_launch_paths() { |
| 43 | + input_file="$1" |
| 44 | + if [ -f "$input_file" ]; then |
| 45 | + # Create a temporary file |
| 46 | + TEMP_FILE="${input_file}.tmp" |
| 47 | + |
| 48 | + # Process the file line by line |
| 49 | + while IFS= read -r line; do |
| 50 | + # Check if line contains old launch path pattern |
| 51 | + if echo "$line" | grep -q '"/mnt/SDCARD/Emu/.*/launch.sh"'; then |
| 52 | + # Replace the launch path pattern |
| 53 | + echo "$line" | sed 's|/launch.sh"|/../.emu_setup/standard_launch.sh"|' >> "$TEMP_FILE" |
| 54 | + else |
| 55 | + echo "$line" >> "$TEMP_FILE" |
| 56 | + fi |
| 57 | + done < "$input_file" |
| 58 | + |
| 59 | + # Replace original file with updated content |
| 60 | + mv "$TEMP_FILE" "$input_file" |
| 61 | + log_message "Updated launch paths in $(basename "$input_file")" |
| 62 | + fi |
| 63 | +} |
| 64 | + |
| 65 | +# Main execution |
| 66 | +log_message "Starting upgrade to version $TARGET_VERSION" |
| 67 | + |
| 68 | +# -------------------- FILE UPDATES -------------------- |
| 69 | +# Remove boot_to=Game Switcher if it exists, this is to fix a bad migration for a few early adopters |
| 70 | +CONFIG_FILE="/mnt/SDCARD/spruce/settings/spruce.cfg" |
| 71 | +if [ -f "$CONFIG_FILE" ]; then |
| 72 | + sed -i '/^boot_to=Game Switcher$/d' "$CONFIG_FILE" |
| 73 | + log_message "Removed boot_to=Game Switcher from spruce.cfg if it existed" |
| 74 | +fi |
| 75 | + |
| 76 | + |
| 77 | +FAVOURITE_FILE="/mnt/SDCARD/Roms/favourite.json" |
| 78 | +RECENT_FILE="/mnt/SDCARD/Roms/recentlist.json" |
| 79 | + |
| 80 | +# Update launch paths in favourite.json and recentlist.json if they exist |
| 81 | +update_launch_paths "$FAVOURITE_FILE" |
| 82 | +update_launch_paths "$RECENT_FILE" |
| 83 | + |
| 84 | + |
| 85 | +# update launch paths in Game Switcher list if necessary |
| 86 | +GS_LIST="/mnt/SDCARD/spruce/settings/gs_list" |
| 87 | +sed -i "s|/launch.sh|/../.emu_setup/standard_launch.sh|g" "$GS_LIST" |
| 88 | + |
| 89 | +# -------------------- ADDITIONAL UPGRADE STEPS -------------------- |
| 90 | + |
| 91 | + |
| 92 | +# -------------------- UPGRADE COMPLETION -------------------- |
| 93 | +# Check if the update was successful |
| 94 | +if [ $? -eq 0 ]; then |
| 95 | + log_message "Upgrade to version $TARGET_VERSION completed successfully" |
| 96 | + exit 0 |
| 97 | +else |
| 98 | + log_message "Error: Upgrade to version $TARGET_VERSION failed" |
| 99 | + exit 1 |
| 100 | +fi |
0 commit comments