Changeset - 41ffa4707502
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-06 16:44:26
branko@majic.rs
Noticket: [factorio_manager.sh] Use globbing for reading list of available backup directories instead of ls with grep.
1 file changed with 19 insertions and 20 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -1513,41 +1513,40 @@ elif [[ $command == list-backups ]]; then
 
    # Validate that instance directory contains valid instance.
 
    validate_path_or_terminate "instance_directory" "$instance_directory" "$ERROR_ARGUMENTS"
 

	
 
    # Extended regular expression for matching YYYY-MM-DD-hh:mm:ss format.
 
    backup_destination_name_pattern="[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}_[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}"
 

	
 
    # Read current game version.
 
    # shellcheck source=/dev/null
 
    source "$instance_config"
 
    current_game_version="$game_version"
 
    unset game_version
 

	
 
    # Detect and show available backups to the user.
 
    # shellcheck disable=SC2010 # Using ls with quoting style shell-escape will produce one filename per line.
 
    if [[ ! -d $instance_backup_directory ]] || ! ls --quoting-style=shell-escape "$instance_backup_directory" | grep -q -E "^$backup_destination_name_pattern\$"; then
 
    # Set-up list of backup directories.
 
    shopt -s nullglob
 
    # Glob expression for matching YYYY-MM-DD-hh:mm:ss format.
 
    backup_directories=("$instance_backup_directory"/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]:[0-9][0-9]:[0-9][0-9])
 
    shopt -s nullglob
 

	
 
    # Show available backups to the user.
 
    if (( ${#backup_directories[@]} == 0 )); then
 
        echo "No backups are available for instance $(colorecho -n green "$instance")."
 
    else
 
        echo "Available backups for instance $(colorecho -n green "$instance") (current version $(colorecho -n green "$current_game_version"))."
 
        echo
 

	
 
        for backup_destination in "$instance_backup_directory"/*; do
 

	
 
            if [[ $backup_destination =~ $backup_destination_name_pattern ]]; then
 
                backup_date=$(basename "$backup_destination")
 
        for backup_directory in "${backup_directories[@]}"; do
 

	
 
                # Read instance configuration for backup.
 
                # shellcheck source=/dev/null
 
                source "$backup_destination/instance.conf"
 

	
 
                if [[ -f "$backup_destination/.description" ]]; then
 
                    backup_description=$(<"$backup_destination/.description")
 
                    echo "  - $backup_date - version $(colorecho -n green "$game_version") ($backup_description)"
 
                else
 
                    echo "  - $backup_date - version $(colorecho -n green "$game_version")"
 
                fi
 
            backup_date=$(basename "$backup_directory")
 

	
 
            # Read instance configuration for backup.
 
            # shellcheck source=/dev/null
 
            source "$backup_directory/instance.conf"
 

	
 
            if [[ -f "$backup_directory/.description" ]]; then
 
                backup_description=$(<"$backup_directory/.description")
 
                echo "  - $backup_date - version $(colorecho -n green "$game_version") ($backup_description)"
 
            else
 
                echo "  - $backup_date - version $(colorecho -n green "$game_version")"
 
            fi
 

	
 
        done
 

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