Changeset - 837351f99204
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-17 15:07:24
branko@majic.rs
Noticket: [factorio_manager.sh] Added command for installing new versions of game from game archive.
1 file changed with 89 insertions and 1 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -38,9 +38,10 @@ Usage:
 
  $program [OPTIONS] copy SOURCE_INSTANCE DESTINATION_INSTANCE
 
  $program [OPTIONS] remove INSTANCE
 
  $program [OPTIONS] import INSTANCE SOURCE_DIRECTORY
 
  $program [OPTIONS] set-version INSTANCE
 

	
 
  $program [OPTIONS] versions
 
  $program [OPTIONS] set-version INSTANCE
 
  $program [OPTIONS] install GAME_ARCHIVE
 

	
 
  $program [OPTIONS] list-backups INSTANCE
 
  $program [OPTIONS] backup INSTANCE [DESCRIPTION]
 
@@ -143,6 +144,14 @@ info INSTANCE
 
        - list of enabled/disabled mods
 
        - list of backups
 

	
 
install GAME_ARCHIVE
 

	
 
    Installs Factorio from the provided archive into the game
 
    installations directory. Version is automatically detected from
 
    the archive. All extracted game files are set-up to be read-only
 
    to prevent accidentally running the game directly from its own
 
    directory.
 

	
 
launch INSTANCE
 

	
 
    Launches the instance with specified name. See the note for the
 
@@ -925,6 +934,9 @@ function read_server_settings() {
 
#       instance_import_source
 
#         Checks if path is usable as source for importing an instance.
 
#
 
#       game_archive
 
#         Checks if file at designated path is a valid game archive.
 
#
 
#   $2 (path)
 
#     Path that should be validated.
 
#
 
@@ -1010,6 +1022,16 @@ function validate_path_or_terminate() {
 
            exit "$ERROR_ARGUMENTS"
 
        fi
 

	
 
    elif [[ $path_test == "game_archive" ]]; then
 
        if [[ ! -f $path ]]; then
 
            error "Supplied path does not point to a valid game archive."
 
            exit "$ERROR_ARGUMENTS"
 
        fi
 

	
 
        if ! tar --occurrence=1 --list --file "$game_archive" "factorio/bin/x64/factorio" > /dev/null; then
 
            error "Supplied path does not point to a valid game archive."
 
            exit "$ERROR_ARGUMENTS"
 
        fi
 
    else
 
        error "Unable to validate path '$path', unsupported test requested: '$path_test'."
 
        exit "$ERROR_GENERAL"
 
@@ -2405,6 +2427,72 @@ EOF
 
    fi
 

	
 
    success "Created new server instance $(colorecho -n green "$instance")"
 

	
 

	
 
#=========#
 
# install #
 
#=========#
 
elif [[ $command == install ]]; then
 

	
 
    # Make sure game installations directory has been set.
 
    validate_path_or_terminate "game_installations_directory" "$game_installations_directory" "$ERROR_CONFIGURATION"
 

	
 
    # Read positional arguments.
 
    game_archive="${1-}"
 
    shift
 

	
 
    # Calculate derived variables.
 
    staging_directory="$game_installations_directory/.staging"
 
    game_staging_directory="$staging_directory/factorio"
 
    staging_factorio_bin="$game_staging_directory/bin/x64/factorio"
 

	
 
    # Verify arguments.
 
    if [[ -z $game_archive ]]; then
 
        error "Missing argument: GAME_ARCHIVE"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 

	
 
    validate_path_or_terminate "game_archive" "$game_archive" "$ERROR_ARGUMENTS"
 

	
 
    # Prepare staging directory.
 
    rm -rf "$staging_directory"
 
    mkdir "$staging_directory"
 

	
 
    # Extract the game version and verify it.
 
    tar --occurrence=1 --extract --file "$game_archive" --directory "$staging_directory" "factorio/bin/x64/factorio"
 

	
 
    game_version=$("$staging_factorio_bin" --version | grep '^Version' | sed -e 's/^Version: //;s/ .*//')
 

	
 
    if ! [[ $game_version =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then
 
        error "Could not parse version from output of command: $staging_factorio_bin --version"
 
        exit "$ERROR_GENERAL"
 
    fi
 

	
 
    # Check if version has already been installed.
 
    game_destination_directory="$game_installations_directory/$game_version"
 
    if [[ -e "$game_destination_directory" ]]; then
 
        error "Factorio $game_version already available under: $game_destination_directory"
 
        exit "$ERROR_GENERAL"
 
    fi
 

	
 
    # Unpack the full installation.
 
    info "Extracting the game installation, this might take a while."
 
    if ! tar --extract --file "$game_archive" --directory "$staging_directory"; then
 
        error "Could not extract game archive ($game_archive) to its staging directory ($staging_directory)."
 
        exit "$ERROR_GENERAL"
 
    fi
 

	
 
    # Move the game installation, and make it read-only.
 
    if ! mv "$game_staging_directory" "$game_destination_directory"; then
 
        error "Could not move the game from its staging directory ($game_staging_directory) to its destination directory ($game_destination_directory)."
 
        exit "$ERROR_GENERAL"
 
    fi
 
    if ! chmod -R u-w,g-w,o-w "$game_destination_directory"; then
 
        error "Could not write-protect the game directory ($game_destination_directory). Manual intervention might be required."
 
        exit "$ERROR_GENERAL"
 
    fi
 

	
 
    success "Successfully installed game version: $(colorecho -n green "$game_version")"
 
else
 
    error "Invalid command: $command"
 

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