Skip to content

Commit

Permalink
Sync last updater version
Browse files Browse the repository at this point in the history
  • Loading branch information
xchwarze committed Dec 3, 2024
1 parent e61676e commit a79e755
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 40 deletions.
26 changes: 24 additions & 2 deletions bin/updater/README.ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ re_download = die_win64_portable_(?:\S+).zip

[Portmon]
folder = Monitor\Portmon
url = https://docs.microsoft.com/en-us/sysinternals/downloads/portmon
url = https://raw.githubusercontent.com/MicrosoftDocs/sysinternals/main/sysinternals/downloads/portmon.md
update_url = https://download.sysinternals.com/files/PortMon.zip
re_version = <h1 [^>]*>Portmon for Windows v(.*?)</h1>
from = web
re_version = # Portmon v(\d+\.\d+)
```

Los valores utilizados para la configuración son:
Expand Down Expand Up @@ -65,6 +66,27 @@ Combinando el uso de `update_url` y `re_download` se consiguen las siguientes es
Esto es útil para arreglar los links de descarga de GitHub o Sourceforge.
4. También se dispone de un método de detección de nuevas versiones que en lugar de regex usa las cabeceras http con las que responde el servidor.

## Parámetros de Línea de Comandos

El actualizador ofrece un conjunto flexible de parámetros para controlar su comportamiento:

| Parámetro | Descripción |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| `-h, --help` | Muestra este mensaje de ayuda y finaliza. |
| `-v, --version` | Muestra el número de versión del programa y finaliza. |
| `-u [UPDATE ...], --update [UPDATE ...]` | Especifica una lista de herramientas a actualizar. Si no se proporciona, se actualizarán todas. |
| `-dsu, --disable-self-update` | Desactiva la auto-actualización automática del script. |
| `-dfc, --disable-folder-clean` | Evita limpiar la carpeta de herramientas durante las actualizaciones. |
| `-dr, --disable-repack` | Impide empaquetar nuevamente las herramientas después del proceso de actualización. |
| `-dic, --disable-install-check` | Omite la verificación de si las herramientas están instaladas correctamente. |
| `-dpb, --disable-progress-bar` | Desactiva la barra de progreso durante las descargas. |
| `-sft {full,version,name}, --save-format-type {full,version,name}` | Especifica el tipo de formato para guardar las actualizaciones comprimidas: `full`, `version` o `name`. |
| `-f, --force` | Fuerza la descarga de actualizaciones, incluso si ya están actualizadas. |
| `-uga USE_GITHUB_API, --use-github-api USE_GITHUB_API` | Usa la API de GitHub para actualizaciones, especificando el token para autenticarse. |
| `-udp, --update-default-params` | Actualiza los parámetros predeterminados almacenados en la configuración. |
| `-dmc, --disable-mutex-check` | Permite ejecutar múltiples instancias del script desactivando la verificación de mutex. |
| `-d, --debug` | Activa la salida detallada de depuración para resolver problemas. |

## Ejemplos

La herramienta soporta varios comandos y combinaciones. Estos son los mas usados.
Expand Down
26 changes: 24 additions & 2 deletions bin/updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ re_download = die_win64_portable_(?:\S+).zip

[Portmon]
folder = Monitor\Portmon
url = https://docs.microsoft.com/en-us/sysinternals/downloads/portmon
url = https://raw.githubusercontent.com/MicrosoftDocs/sysinternals/main/sysinternals/downloads/portmon.md
update_url = https://download.sysinternals.com/files/PortMon.zip
re_version = <h1 [^>]*>Portmon for Windows v(.*?)</h1>
from = web
re_version = # Portmon v(\d+\.\d+)
```

The values used for configuration are:
Expand Down Expand Up @@ -63,6 +64,27 @@ Combining the use of `update_url` and `re_download` the following download strat
This is useful for fixing GitHub or Sourceforge download links.
4. A new version detection method is also available that instead of regex uses the http headers with which the server responds.

## Command-line Parameters

The updater provides a flexible set of parameters to control its behavior:

| Parameter | Description |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| `-h, --help` | Show this help message and exit. |
| `-v, --version` | Display the program's version number and exit. |
| `-u [UPDATE ...], --update [UPDATE ...]` | Specify a list of tools to update. Defaults to updating all tools if not provided. |
| `-dsu, --disable-self-update` | Disable automatic self-update of this script. |
| `-dfc, --disable-folder-clean` | Skip cleaning the tool's folder during updates. |
| `-dr, --disable-repack` | Prevent repacking of tools after the update process. |
| `-dic, --disable-install-check` | Skip checking if the tools are properly installed. |
| `-dpb, --disable-progress-bar` | Disable the download progress bar for updates. |
| `-sft {full,version,name}, --save-format-type {full,version,name}` | Specify the save format type for compressed updates: `full`, `version`, or `name`. |
| `-f, --force` | Force the download of updates, even if they appear up to date. |
| `-uga USE_GITHUB_API, --use-github-api USE_GITHUB_API` | Use the GitHub API for updates, specifying the token to authenticate. |
| `-udp, --update-default-params` | Update the default parameters stored in the configuration. |
| `-dmc, --disable-mutex-check` | Allow multiple instances of the script to run simultaneously by disabling the mutex check. |
| `-d, --debug` | Enable detailed debug output for troubleshooting. |

## Examples

The tool supports various commands and combinations. These are the most used.
Expand Down
3 changes: 3 additions & 0 deletions bin/updater/scripts/Toolkit-Updater.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ echo Update all Universal Update stuff and restart...
:: Kill updater process to be able to update all the files
taskkill /IM updater.exe /F

:: Clean updater mutex
del mutex.lock

:: Backup user tools.ini
move tools.ini tools.ini.old

Expand Down
102 changes: 76 additions & 26 deletions bin/updater/src/UpdateManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import colorama
import logging
import psutil

from universal_updater.Updater import Updater
from universal_updater.ConfigManager import ConfigManager
Expand All @@ -19,7 +20,8 @@ def __init__(self):
"""
Initialize the UpdateManager with a ConfigManager instance and command-line arguments.
"""
self.version = '2.2.0'
self.version = '2.3.1'
self.process_mutex = 'mutex.lock'
self.config_file_name = 'tools.ini'
self.config_section_defaults = 'UpdaterConfig'
self.config_section_self_update = 'UpdaterAutoUpdater'
Expand All @@ -43,16 +45,49 @@ def print_banner(self):
Version: {self.version}
""")

def exit_handler(self, signal, frame):
def exit_handler(self, signum, frame):
"""
Handles signals like SIGINT for graceful exit.
Handles signals like SIGINT or SIGTERM for graceful exit.
:param signal: Signal type
:param signum: Signal type (e.g., SIGINT, SIGTERM)
:param frame: Current stack frame
"""
print(colorama.Fore.YELLOW + 'SIGINT or CTRL-C detected. Exiting gracefully')
signal_name = 'SIGINT' if signum == signal.SIGINT else 'SIGTERM'
print(colorama.Fore.YELLOW + f'{signal_name} detected. Exiting gracefully')
self.cleanup_mutex()
sys.exit(0)

def check_single_instance(self):
"""
Ensures only a single instance of the script is running by creating a lock file with the current PID.
If the lock file exists and contains a different PID, the script will exit.
"""
if self.arguments.disable_mutex_check:
print('Mutex check is disabled. Multiple instances can run concurrently.')
return

if os.path.exists(self.process_mutex):
with open(self.process_mutex, 'r') as lock:
existing_pid = int(lock.read().strip())

# Verify if the process with the PID exists
if existing_pid and psutil.pid_exists(existing_pid):
print(f"Another instance of the script is already running (PID: {existing_pid}). Exiting.")
sys.exit(1)
else:
print(f"Stale mutex detected (PID: {existing_pid}). Regenerating with current PID.")

# Create a new lock file with the current PID
with open(self.process_mutex, 'w') as lock:
lock.write(str(os.getpid()))

def cleanup_mutex(self):
"""
Removes the mutex file if mutex check is enabled and the file exists.
"""
if not self.arguments.disable_mutex_check and os.path.exists(self.process_mutex):
os.remove(self.process_mutex)

def get_argparse_default(self, option, default, is_bool=True):
"""
Retrieves the default value for a given argparse option from the configuration.
Expand Down Expand Up @@ -83,86 +118,94 @@ def parse_arguments(self):
'-u',
'--update',
dest='update',
help='list of tools (default: all)',
help='Specify a list of tools to update. Defaults to updating all tools if not provided.',
nargs='*'
)
parser.add_argument(
'-dsu',
'--disable-self-update',
dest='disable_self_update',
help='disable self update of this script',
action=argparse.BooleanOptionalAction,
help='Disable automatic self-update of this script.',
action='store_true',
default=False
)
parser.add_argument(
'-dfc',
'--disable-folder-clean',
dest='disable_clean',
help='disable tool folder clean',
action=argparse.BooleanOptionalAction,
help='Skip cleaning the tool\'s folder during updates.',
action='store_true',
default=self.get_argparse_default('disable_clean', True)
)
parser.add_argument(
'-dr',
'--disable-repack',
dest='disable_repack',
help='disable tool repack',
action=argparse.BooleanOptionalAction,
help='Prevent repacking of tools after the update process.',
action='store_true',
default=self.get_argparse_default('disable_repack', True)
)
parser.add_argument(
'-dic',
'--disable-install-check',
dest='disable_install_check',
help='disable tool install check',
action=argparse.BooleanOptionalAction,
help='Skip checking if the tools are properly installed.',
action='store_true',
default=self.get_argparse_default('disable_install_check', False)
)
parser.add_argument(
'-dpb',
'--disable-progress-bar',
dest='disable_progress',
help='disable download progress bar',
action=argparse.BooleanOptionalAction,
help='Disable the download progress bar for updates.',
action='store_true',
default=self.get_argparse_default('disable_progress', False)
)
parser.add_argument(
'-sft',
'--save-format-type',
dest='save_format_type',
help='compress save format name',
help='Specify the save format type for compressed updates: "full", "version", or "name".',
choices=['full', 'version', 'name'],
default=self.get_argparse_default('save_format_type', 'full', False)
)
parser.add_argument(
'-f',
'--force',
dest='force_download',
help='force download',
action=argparse.BooleanOptionalAction,
help='Force the download of updates, even if they appear up to date.',
action='store_true',
default=False
)
parser.add_argument(
'-uga',
'--use-github-api',
dest='use_github_api',
help='use github api with this token',
help='Use the GitHub API for updates, specifying the token to authenticate.',
default=self.get_argparse_default('use_github_api', '', False)
)
parser.add_argument(
'-udp',
'--update-default-params',
dest='update_default_params',
help='update default params',
action=argparse.BooleanOptionalAction,
help='Update the default parameters stored in the configuration.',
action='store_true',
default=False
)
parser.add_argument(
'-dmc',
'--disable-mutex-check',
dest='disable_mutex_check',
help='Allow multiple instances of the script to run simultaneously by disabling the mutex check.',
action='store_true',
default=False
)
parser.add_argument(
'-d',
'--debug',
dest='debug',
help='enable debug output',
action=argparse.BooleanOptionalAction,
help='Enable detailed debug output for troubleshooting.',
action='store_true',
default=False
)

Expand Down Expand Up @@ -249,7 +292,7 @@ def handle_auto_update(self):
try:
updater.update(self.config_section_self_update)
except Exception as exception:
logging.info(exception)
logging.error(exception)

# add missing new line separator
logging.info("\n")
Expand All @@ -269,7 +312,8 @@ def handle_tool_updates(self, updater, update_list):
try:
updater.update(tool)
except Exception as exception:
logging.info(exception)
failed_updates += 1
logging.error(exception)

logging.info(colorama.Fore.YELLOW + f"\n[*] Update process completed: {total_updates - failed_updates} succeeded, {failed_updates} failed out of {total_updates} total updates.")

Expand All @@ -293,13 +337,19 @@ def main(self):
"""
Main entry point for the UpdateManager.
"""
# setup signals
signal.signal(signal.SIGINT, self.exit_handler)
signal.signal(signal.SIGTERM, self.exit_handler)

# setup script
self.change_current_directory()
self.print_banner()
self.parse_arguments()
self.set_logging_level()
self.check_single_instance()
self.update_default_params()
self.handle_updates()
self.cleanup_mutex()


# Entry point for the script
Expand Down
1 change: 1 addition & 0 deletions bin/updater/src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ colorama>=0.4.4
tqdm>=4.62.3
py7zr>=0.16.1
rarfile>=4.0
psutil>=6.1.0
1 change: 1 addition & 0 deletions bin/updater/src/universal_updater/Packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def unpack_rar(self, file_path, unpack_path, file_pass=None):
"""
# download first "UnRAR for Windows" from https://www.rarlab.com/rar_add.htm
# direct link: https://www.rarlab.com/rar/unrarw32.exe
# new link: https://www.win-rar.com/predownload.html?&Version=32bit&L=0.
with rarfile.RarFile(file_path, 'r') as compressed:
compressed.extractall(unpack_path, pwd=file_pass)

Expand Down
Loading

0 comments on commit a79e755

Please sign in to comment.