Changeset - 741d8e825ee6
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-05 14:29:02
branko@majic.rs
Noticket: Refactor all existing commands in Factorio Manager to use generic function for picking Factorio version.
1 file changed with 5 insertions and 95 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -1626,43 +1626,16 @@ elif [[ $command == set-version ]]; then
 
    fi
 

	
 
    # Load instance configuration.
 
    source "$instance_config"
 

	
 
    # Display list of available Factorio versions.
 
    echo
 
    echo "The following versions of Factorio are locally available:"
 
    echo
 

	
 
    for candidate in "$game_installations_directory"/*; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            candidate_version=$(basename "$candidate")
 
            if [[ $candidate_version == $game_version ]]; then
 
                echo "  - $candidate_version $(colorecho -n green "[current]")"
 
            else
 
                echo "  - $candidate_version"
 
            fi
 

	
 
        fi
 
    done
 
    echo
 

	
 
    # Display current version.
 
    echo "Current version used for instance $(colorecho -n green "$instance") is $(colorecho -n green "$game_version")."
 
    echo
 
    read -p "Please specify what version you would like to use (enter to keep current): " game_version_selected
 

	
 
    if [[ -z $game_version_selected ]]; then
 
        game_version_selected="$game_version"
 
    fi
 

	
 
    # Validate user input.
 
    if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
        error "Requested version not locally available: $game_version_selected"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 
    select_factorio_version "$game_installations_directory" "$game_version" "current" || exit "$ERROR_GENERAL"
 
    echo
 

	
 
    # Change instance game version.
 
    if [[ $game_version_selected == $game_version ]]; then
 
        info "Current version has been kept."
 
    else
 
        sed -i -e "s/^game_version=.*/game_version=$game_version_selected/" "$instance_config"
 
@@ -2013,42 +1986,16 @@ elif [[ $command == copy ]]; then
 
        source "$source_instance_config"
 

	
 
        # Display list of available Factorio versions.
 
        echo
 
        echo "If you wish to, you can now change version of Factorio used for destination instance, or keep the same version as for source instance."
 
        echo
 
        echo "The following versions of Factorio are locally available:"
 
        echo
 

	
 
        for candidate in "$game_installations_directory"/*; do
 
            if [[ -f $candidate/bin/x64/factorio ]]; then
 
                candidate_version=$(basename "$candidate")
 
                if [[ $candidate_version == $game_version ]]; then
 
                    echo "  - $candidate_version $(colorecho -n green "[current]")"
 
                else
 
                    echo "  - $candidate_version"
 
                fi
 
            fi
 
        done
 
        select_factorio_version "$game_installations_directory" "$game_version" "current" | exit "$ERROR_GENERAL"
 
        echo
 

	
 
        # Display current version.
 
        echo "Current version used for instance $(colorecho -n green "$source_instance") is $(colorecho -n green "$game_version")."
 
        echo
 
        read -p "Please specify what version you would like to use for new instance (press enter to keep the current version): " game_version_selected
 

	
 
        if [[ -z $game_version_selected ]]; then
 
            game_version_selected="$game_version"
 
        fi
 

	
 
        # Validate user input.
 
        if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
            error "Requested version not locally available: $game_version_selected"
 
            exit "$ERROR_ARGUMENTS"
 
        fi
 

	
 
        # Check if user wants to copy backup files as well.
 
        copy_backups=""
 

	
 
        until [[ $copy_backups == "y" || $copy_backups == "n" ]]; do
 
            echo
 
            read -n1 -p "Would you like to copy backup files as well? (y/n)" copy_backups
 
@@ -2147,31 +2094,13 @@ elif [[ $command == import ]]; then
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 

	
 
    # Display list of available Factorio versions and let user pick one.
 
    echo "Factorio version must  be selected manually for imported instances."
 
    echo
 
    echo "The following versions of Factorio are locally available:"
 
    echo
 

	
 
    for candidate in "$game_installations_directory"/*; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            echo "  - $(basename "$candidate")"
 
        fi
 
    done
 

	
 
    echo
 

	
 
    echo -n "Please specify what version you would like to use: "
 
    read game_version_selected
 

	
 
    # Validate user input.
 
    if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
        error "Requested version not locally available: $game_version_selected"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 
    select_factorio_version "$game_installations_directory" || exit "$ERROR_GENERAL"
 

	
 
    (
 

	
 
        # Obtain lock - Factorio uses the same mechanism, so we should
 
        # be able to detect the game is running in this way.
 
        flock --exclusive --nonblock 200
 
@@ -2274,32 +2203,13 @@ elif [[ $command == create-server ]]; then
 
        error "Missing argument: INSTANCE"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 

	
 
    validate_path_or_terminate "instance_directory_new" "$instance_directory" "$ERROR_ARGUMENTS"
 

	
 
    # Display list of available Factorio versions and let user pick one.
 
    echo "The following versions of Factorio are locally available:"
 
    echo
 

	
 
    for candidate in "$game_installations_directory"/*; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            echo "  - $(basename "$candidate")"
 
        fi
 
    done
 

	
 
    echo
 

	
 
    echo -n "Please specify what version you would like to use: "
 
    read game_version_selected
 

	
 
    # Validate user input.
 
    if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
        error "Requested version not locally available: $game_version_selected"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 
    select_factorio_version "$game_installations_directory" || exit "$ERROR_GENERAL"
 

	
 
    # Grab server settings from user.
 
    echo "You will now be prompted to provide settings for the server, with some pre-filled settings."
 
    echo "Do not change settings marked with [EXPERT] unless you know what you are doing."
 
    echo
 
    read_server_settings "$instance"
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now