Changeset - b996dd49a6c7
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-05 16:52:29
branko@majic.rs
Noticket: Updated help for Factorio Manager, and bumped the script version to 0.2.
1 file changed with 90 insertions and 40 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
#!/bin/bash
 
#
 
# factorio_manager.sh
 
#
 
# Copyright (C) 2020, Branko Majic <branko@majic.rs>
 
#
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
#
 

	
 
# Treat unset variables as errors.
 
set -u
 

	
 
program="factorio_manager.sh"
 
version="0.1"
 
version="0.2"
 

	
 
function synopsis() {
 
cat <<EOF
 
$program $version, helper tool for managing Factorio instances
 

	
 
Usage:
 
  $program [OPTIONS] launch INSTANCE
 
  $program [OPTIONS] info INSTANCE
 
  $program [OPTIONS] list
 

	
 
  $program [OPTIONS] create INSTANCE
 
  $program [OPTIONS] create-server INSTANCE
 
  $program [OPTIONS] copy SOURCE_INSTANCE DESTINATION_INSTANCE
 
  $program [OPTIONS] remove INSTANCE
 
  $program [OPTIONS] import INSTANCE SOURCE_DIRECTORY
 

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

	
 
  $program [OPTIONS] list-backups INSTANCE
 
  $program [OPTIONS] backup INSTANCE [DESCRIPTION]
 
  $program [OPTIONS] restore INSTANCE BACKUP_NAME
 
  $program [OPTIONS] remove-backup INSTANCE BACKUP_NAME
 

	
 
  $program [OPTIONS] set-game-dir GAME_INSTALLATIONS_DIRECTORY
 
EOF
 
}
 

	
 
function short_usage() {
 
cat <<EOF
 
$(synopsis)
 

	
 
For more details see $program -h.
 
EOF
 
}
 

	
 
function usage() {
 
    cat <<EOF
 
$(synopsis)
 

	
 
$program is a helper tool for managing multiple Factorio
 
instances.
 
$program is a helper tool for managing multiple Factorio instances.
 

	
 
Each instance is designated a dedicated directory, which contains all
 
of its configuration files, saves games, and mods, and is kept
 
separate from all other instances.
 

	
 
A single Factorio version installation (base files) can be used by
 
multiple instances, but each instance is bound to a specific version
 
of Factorio.
 
Each instance is bound to a specific game version, and the manager
 
fully supports working with multiple versions of Factorio. Base game
 
files are kept intact and can be shared by multiple instances.
 

	
 
Factorio Manager keeps instances in sub-directories under the
 
~/.factorio/ directory. Sub-directories are named after the
 
instances. The following instance names are reserved for special use
 
by the tool:
 
~/.factorio/ directory. Sub-directories correspond to instance
 
names.
 

	
 
The following instance names are reserved for special use by
 
the tool:
 

	
 
 - .game_installations (used for storing symlink towards directory
 
   containing Factorio installations)
 

	
 
Multiple commands are provided for managing Factorio instances, and
 
they all expect different positional parameters:
 

	
 

	
 
set-game-dir GAME_INSTALLATIONS_DIRECTORY
 
Multiple commands are provided for managing Factorio instances. Each
 
command accepts its own set of positional arguments.
 

	
 
    Sets the passed-in directory path as the base directory where
 
    different versions of Factorio will be looked-up. Each
 
    sub-directory within this directory should be named after the
 
    version of Factorio it represents, and should be the base
 
    directory under which the Factorio installation files can be
 
    found.
 

	
 

	
 
versions
 

	
 
    Shows locally available Factorio versions.
 
backup INSTANCE [DESCRIPTION]
 

	
 
    Creates backup of an instance. All backups will be stored as
 
    subdirectories under the .bak directory within the instance
 
    directory. An optional description can be passed-in to make it
 
    easier to distinguish between different backups. Hidden files
 
    (names starting with '.') will be omitted from the backup.
 

	
 
list
 

	
 
    Lists available Factorio instances, and shows some basic
 
    information about them.
 
copy SOURCE_INSTANCE DESTINATION_INSTANCE
 

	
 
    Creates a copy of an existing instance. Requires name of an
 
    existing instance and name of the new instance to be passed-in as
 
    arguments. Command will refuse to overwrite destination instance
 
    if it already exists. Command will prompt user to specify desired
 
    version for the copy, and to choose whether the backups should be
 
    copied as well.
 

	
 
create INSTANCE
 

	
 
    Creates a new Factorio instance with the given name. Command will
 
    prompt the user to pick between locally available Factorio
 
    versions.
 

	
 

	
 
launch INSTANCE
 

	
 
    Launches an instance with the given name.
 

	
 
    NOTE:: When launching the instance for the first time, Factorio
 
    NOTE: When launching the instance for the first time, Factorio
 
    will report that its configuration file is invalid, and offer to
 
    fix it. The reason is that the manager creates a minimal
 
    configuration file when creating an instance, and Factorio does
 
    not like this. It should be safe to allow Factorio to fix the
 
    configuration file (this will populate it with the necessary
 
    commented-out options).
 

	
 
create-server INSTANCE
 

	
 
backup INSTANCE [DESCRIPTION]
 
    Creates a new Factorio server instance with the given
 
    name. Command will prompt the user to pick between locally
 
    available Factorio versions, and to provide settings for server.
 

	
 
    Creates backup of an instance. All backups will be stored as
 
    subdirectories under the .bak directory within the instance
 
    directory. An optional description can be passed-in to make it
 
    easier to distinguish between different backups. Hidden files
 
    (names starting with '.') will be omitted from the backup.
 
import INSTANCE
 

	
 
    Creates a new instance out of existing files found within a
 
    Factorio installation directory. This command is useful when
 
    migrating from Factorio installations that store all data in the
 
    root of the game installation directory. Command will prompt the
 
    user to pick between locally available Factorio versions.
 

	
 
info INSTANCE
 

	
 
    Shows information about the specified instance. This includes:
 

	
 
        - instance name
 
        - game version
 
        - instance directory path
 
        - list of enabled/disabled mods
 
        - list of backups
 

	
 
launch INSTANCE
 

	
 
    Launches the instance with specified name. See the note for the
 
    "create" command.
 

	
 
list
 

	
 
    Lists available Factorio instances.
 

	
 
list-backups INSTANCE
 

	
 
    Lists available backups of an instance, including description (if any is set).
 
    Lists available backups for the specified instance.
 

	
 
remove-backup INSTANCE BACKUP_NAME
 

	
 
    Removes the specified backup for the specified instance. User must
 
    confirm the action prior to any files being removed.
 

	
 
remove INSTANCE
 

	
 
    Removes the specified instance. User must confirm the action prior
 
    to any files being removed.
 

	
 
restore INSTANCE BACKUP_NAME
 

	
 
    Restores the specified instance from the specified backup. User
 
    must confirm the action prior to any files being replaced.
 

	
 
set-game-dir GAME_INSTALLATIONS_DIRECTORY
 

	
 
    Sets the base directory where Factorio game installations can be
 
    found. Each sub-directory within this directory should be named
 
    after the version of Factorio it represents. For example:
 

	
 
        - ~/local/games/factorio/0.17.79/
 
        - ~/local/games/factorio/0.18.30/
 
        - ~/local/games/factorio/0.18.34/
 

	
 
set-version INSTANCE
 

	
 
    Sets Factorio version for the specified instance. User is prompted
 
    to pick between locally available versions.
 

	
 
versions
 

	
 
    Shows locally available Factorio versions.
 

	
 

	
 
$program accepts the following options:
 

	
 
    -q
 
        Quiet mode. Output a message only if newer packages are available.
 
    -d
 
        Enable debug mode.
 
    -v
 
        Show script licensing information.
 
    -h
 
        Show usage help.
 

	
 

	
 
Please report bugs and send feature requests to <branko@majic.rs>.
 
EOF
 
}
 

	
 
function version() {
 
    cat <<EOF
 
$program, version $version
 

	
 
+-----------------------------------------------------------------------+
 
| Copyright (C) 2020, Branko Majic <branko@majic.rs>                    |
 
|                                                                       |
 
| This program is free software: you can redistribute it and/or modify  |
 
| it under the terms of the GNU General Public License as published by  |
 
| the Free Software Foundation, either version 3 of the License, or     |
 
| (at your option) any later version.                                   |
 
|                                                                       |
 
| This program is distributed in the hope that it will be useful,       |
 
| but WITHOUT ANY WARRANTY; without even the implied warranty of        |
 
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
 
| GNU General Public License for more details.                          |
 
|                                                                       |
 
| You should have received a copy of the GNU General Public License     |
 
| along with this program.  If not, see <http://www.gnu.org/licenses/>. |
 
+-----------------------------------------------------------------------+
 

	
 
EOF
 
}
 

	
 
# Set-up colours for message printing if we're not piping and terminal is
 
# capable of outputting the colors.
 
_color_terminal=$(tput colors 2>&1)
 
if [[ -t 1 ]] && (( ${_color_terminal} > 0 )); then
 
    _text_black=$(tput setaf 0)
 
    _text_red=$(tput setaf 1)
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now