Changeset - ad978ac39cbc
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-06 15:55:41
branko@majic.rs
Noticket: [factorio_manager.sh] Use quotes around right-hand sides of operators:

- Right-hand side is treated as glob, so quoting is necessary to avoid
errors. For example, if var='[a]', then [[ $a == $a ]] will always
be false.
1 file changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -507,13 +507,13 @@ function validate_server_setting_value() {
 

	
 
    elif [[ $type =~ ^.+\|.+$ ]]; then
 
        readarray -d "|" -t possible_values < <(echo -n "$type")
 

	
 
        for i in "${possible_values[@]}"; do
 
            # Allow strings without quotes to be specified by the user.
 
            [[ $value == $i || \"$value\" == $i ]] && result=0
 
            [[ $value == "$i" || \"$value\" == "$i" ]] && result=0
 
        done
 

	
 
        [[ $result == 0 ]] || colorecho red "$name must be one of listed values [$type]."
 
    else
 
        error "Unsupported type associated with '$name': $type"
 
        result=2
 
@@ -863,13 +863,13 @@ function read_server_settings() {
 
        # Used for selecting between multiple values.
 
        elif [[ ${settings_type[$key]} =~ ^.+\|.+$ ]]; then
 
            readarray -d "|" -t possible_values < <(echo -n "${settings_type[$key]}")
 

	
 
            for i in "${possible_values[@]}"; do
 
                # Convenience for allowing strings without quotes specified by the user.
 
                [[ \"${settings_value[$key]}\" == $i ]] && settings_value[$key]="\"${settings_value[$key]}\""
 
                [[ \"${settings_value[$key]}\" == "$i" ]] && settings_value[$key]="\"${settings_value[$key]}\""
 
            done
 

	
 
        # List of strings.
 
        elif [[ ${settings_type[$key]} == "list" ]]; then
 
            value=""
 

	
 
@@ -1057,14 +1057,14 @@ function select_factorio_version() {
 

	
 
    for i in "${!game_versions_available[@]}"; do
 
        let i++
 
        echo -n "  [$i] $(basename "${game_versions_available[$i-1]}")"
 

	
 
        # Highlight default version.
 
        if [[ -z $default_version && $i == ${#game_versions_available[@]} ]] || \
 
               [[ -n $default_version && ${game_versions_available[i-1]} == $default_version ]]; then
 
        if [[ -z $default_version && $i == "${#game_versions_available[@]}" ]] || \
 
               [[ -n $default_version && ${game_versions_available[i-1]} == "$default_version" ]]; then
 
            colorecho boldgreen " [$default_marker]"
 
            default_option="$i"
 
        else
 
            echo
 
        fi
 
    done
 
@@ -1383,13 +1383,13 @@ elif [[ $command == launch ]]; then
 
    # Update instance write directory prior to launching - this is a
 
    # failsafe in case it got changed by hand or perhaps the value
 
    # comes from backups of a copied instance.
 
    current_write_data=$(grep "^write-data=" "$game_config")
 
    expected_write_data="write-data=${instance_directory}"
 

	
 
    if [[ $current_write_data != $expected_write_data ]]; then
 
    if [[ $current_write_data != "$expected_write_data" ]]; then
 
        warning "Incorrect path specified for write-data in game configuration file: $game_config"
 
        warning "Current configuration is: $current_write_data"
 
        warning "Configuration will be replaced with: $expected_write_data"
 
        sed -i -e "s#^write-data=.*#$expected_write_data#" "$game_config"
 
    fi
 

	
 
@@ -1755,13 +1755,13 @@ elif [[ $command == set-version ]]; then
 
    echo "Current version used for instance $(colorecho -n green "$instance") is $(colorecho -n green "$game_version")."
 
    echo
 
    select_factorio_version "$game_installations_directory" "$game_version" "current" || exit "$ERROR_GENERAL"
 
    echo
 

	
 
    # Change instance game version.
 
    if [[ $game_version_selected == $game_version ]]; then
 
    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"
 
        success "Version changed to: $(colorecho -n green "$game_version_selected")"
 
    fi
 

	
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now