Skip to content

Commit a79e755

Browse files
committed
Sync last updater version
1 parent e61676e commit a79e755

File tree

11 files changed

+175
-40
lines changed

11 files changed

+175
-40
lines changed

bin/updater/README.ES.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ re_download = die_win64_portable_(?:\S+).zip
3131

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

3940
Los valores utilizados para la configuración son:
@@ -65,6 +66,27 @@ Combinando el uso de `update_url` y `re_download` se consiguen las siguientes es
6566
Esto es útil para arreglar los links de descarga de GitHub o Sourceforge.
6667
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.
6768

69+
## Parámetros de Línea de Comandos
70+
71+
El actualizador ofrece un conjunto flexible de parámetros para controlar su comportamiento:
72+
73+
| Parámetro | Descripción |
74+
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
75+
| `-h, --help` | Muestra este mensaje de ayuda y finaliza. |
76+
| `-v, --version` | Muestra el número de versión del programa y finaliza. |
77+
| `-u [UPDATE ...], --update [UPDATE ...]` | Especifica una lista de herramientas a actualizar. Si no se proporciona, se actualizarán todas. |
78+
| `-dsu, --disable-self-update` | Desactiva la auto-actualización automática del script. |
79+
| `-dfc, --disable-folder-clean` | Evita limpiar la carpeta de herramientas durante las actualizaciones. |
80+
| `-dr, --disable-repack` | Impide empaquetar nuevamente las herramientas después del proceso de actualización. |
81+
| `-dic, --disable-install-check` | Omite la verificación de si las herramientas están instaladas correctamente. |
82+
| `-dpb, --disable-progress-bar` | Desactiva la barra de progreso durante las descargas. |
83+
| `-sft {full,version,name}, --save-format-type {full,version,name}` | Especifica el tipo de formato para guardar las actualizaciones comprimidas: `full`, `version` o `name`. |
84+
| `-f, --force` | Fuerza la descarga de actualizaciones, incluso si ya están actualizadas. |
85+
| `-uga USE_GITHUB_API, --use-github-api USE_GITHUB_API` | Usa la API de GitHub para actualizaciones, especificando el token para autenticarse. |
86+
| `-udp, --update-default-params` | Actualiza los parámetros predeterminados almacenados en la configuración. |
87+
| `-dmc, --disable-mutex-check` | Permite ejecutar múltiples instancias del script desactivando la verificación de mutex. |
88+
| `-d, --debug` | Activa la salida detallada de depuración para resolver problemas. |
89+
6890
## Ejemplos
6991

7092
La herramienta soporta varios comandos y combinaciones. Estos son los mas usados.

bin/updater/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ re_download = die_win64_portable_(?:\S+).zip
3131

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

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

67+
## Command-line Parameters
68+
69+
The updater provides a flexible set of parameters to control its behavior:
70+
71+
| Parameter | Description |
72+
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
73+
| `-h, --help` | Show this help message and exit. |
74+
| `-v, --version` | Display the program's version number and exit. |
75+
| `-u [UPDATE ...], --update [UPDATE ...]` | Specify a list of tools to update. Defaults to updating all tools if not provided. |
76+
| `-dsu, --disable-self-update` | Disable automatic self-update of this script. |
77+
| `-dfc, --disable-folder-clean` | Skip cleaning the tool's folder during updates. |
78+
| `-dr, --disable-repack` | Prevent repacking of tools after the update process. |
79+
| `-dic, --disable-install-check` | Skip checking if the tools are properly installed. |
80+
| `-dpb, --disable-progress-bar` | Disable the download progress bar for updates. |
81+
| `-sft {full,version,name}, --save-format-type {full,version,name}` | Specify the save format type for compressed updates: `full`, `version`, or `name`. |
82+
| `-f, --force` | Force the download of updates, even if they appear up to date. |
83+
| `-uga USE_GITHUB_API, --use-github-api USE_GITHUB_API` | Use the GitHub API for updates, specifying the token to authenticate. |
84+
| `-udp, --update-default-params` | Update the default parameters stored in the configuration. |
85+
| `-dmc, --disable-mutex-check` | Allow multiple instances of the script to run simultaneously by disabling the mutex check. |
86+
| `-d, --debug` | Enable detailed debug output for troubleshooting. |
87+
6688
## Examples
6789

6890
The tool supports various commands and combinations. These are the most used.

bin/updater/scripts/Toolkit-Updater.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ echo Update all Universal Update stuff and restart...
44
:: Kill updater process to be able to update all the files
55
taskkill /IM updater.exe /F
66

7+
:: Clean updater mutex
8+
del mutex.lock
9+
710
:: Backup user tools.ini
811
move tools.ini tools.ini.old
912

bin/updater/src/UpdateManager.py

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import colorama
66
import logging
7+
import psutil
78

89
from universal_updater.Updater import Updater
910
from universal_updater.ConfigManager import ConfigManager
@@ -19,7 +20,8 @@ def __init__(self):
1920
"""
2021
Initialize the UpdateManager with a ConfigManager instance and command-line arguments.
2122
"""
22-
self.version = '2.2.0'
23+
self.version = '2.3.1'
24+
self.process_mutex = 'mutex.lock'
2325
self.config_file_name = 'tools.ini'
2426
self.config_section_defaults = 'UpdaterConfig'
2527
self.config_section_self_update = 'UpdaterAutoUpdater'
@@ -43,16 +45,49 @@ def print_banner(self):
4345
Version: {self.version}
4446
""")
4547

46-
def exit_handler(self, signal, frame):
48+
def exit_handler(self, signum, frame):
4749
"""
48-
Handles signals like SIGINT for graceful exit.
50+
Handles signals like SIGINT or SIGTERM for graceful exit.
4951
50-
:param signal: Signal type
52+
:param signum: Signal type (e.g., SIGINT, SIGTERM)
5153
:param frame: Current stack frame
5254
"""
53-
print(colorama.Fore.YELLOW + 'SIGINT or CTRL-C detected. Exiting gracefully')
55+
signal_name = 'SIGINT' if signum == signal.SIGINT else 'SIGTERM'
56+
print(colorama.Fore.YELLOW + f'{signal_name} detected. Exiting gracefully')
57+
self.cleanup_mutex()
5458
sys.exit(0)
5559

60+
def check_single_instance(self):
61+
"""
62+
Ensures only a single instance of the script is running by creating a lock file with the current PID.
63+
If the lock file exists and contains a different PID, the script will exit.
64+
"""
65+
if self.arguments.disable_mutex_check:
66+
print('Mutex check is disabled. Multiple instances can run concurrently.')
67+
return
68+
69+
if os.path.exists(self.process_mutex):
70+
with open(self.process_mutex, 'r') as lock:
71+
existing_pid = int(lock.read().strip())
72+
73+
# Verify if the process with the PID exists
74+
if existing_pid and psutil.pid_exists(existing_pid):
75+
print(f"Another instance of the script is already running (PID: {existing_pid}). Exiting.")
76+
sys.exit(1)
77+
else:
78+
print(f"Stale mutex detected (PID: {existing_pid}). Regenerating with current PID.")
79+
80+
# Create a new lock file with the current PID
81+
with open(self.process_mutex, 'w') as lock:
82+
lock.write(str(os.getpid()))
83+
84+
def cleanup_mutex(self):
85+
"""
86+
Removes the mutex file if mutex check is enabled and the file exists.
87+
"""
88+
if not self.arguments.disable_mutex_check and os.path.exists(self.process_mutex):
89+
os.remove(self.process_mutex)
90+
5691
def get_argparse_default(self, option, default, is_bool=True):
5792
"""
5893
Retrieves the default value for a given argparse option from the configuration.
@@ -83,86 +118,94 @@ def parse_arguments(self):
83118
'-u',
84119
'--update',
85120
dest='update',
86-
help='list of tools (default: all)',
121+
help='Specify a list of tools to update. Defaults to updating all tools if not provided.',
87122
nargs='*'
88123
)
89124
parser.add_argument(
90125
'-dsu',
91126
'--disable-self-update',
92127
dest='disable_self_update',
93-
help='disable self update of this script',
94-
action=argparse.BooleanOptionalAction,
128+
help='Disable automatic self-update of this script.',
129+
action='store_true',
95130
default=False
96131
)
97132
parser.add_argument(
98133
'-dfc',
99134
'--disable-folder-clean',
100135
dest='disable_clean',
101-
help='disable tool folder clean',
102-
action=argparse.BooleanOptionalAction,
136+
help='Skip cleaning the tool\'s folder during updates.',
137+
action='store_true',
103138
default=self.get_argparse_default('disable_clean', True)
104139
)
105140
parser.add_argument(
106141
'-dr',
107142
'--disable-repack',
108143
dest='disable_repack',
109-
help='disable tool repack',
110-
action=argparse.BooleanOptionalAction,
144+
help='Prevent repacking of tools after the update process.',
145+
action='store_true',
111146
default=self.get_argparse_default('disable_repack', True)
112147
)
113148
parser.add_argument(
114149
'-dic',
115150
'--disable-install-check',
116151
dest='disable_install_check',
117-
help='disable tool install check',
118-
action=argparse.BooleanOptionalAction,
152+
help='Skip checking if the tools are properly installed.',
153+
action='store_true',
119154
default=self.get_argparse_default('disable_install_check', False)
120155
)
121156
parser.add_argument(
122157
'-dpb',
123158
'--disable-progress-bar',
124159
dest='disable_progress',
125-
help='disable download progress bar',
126-
action=argparse.BooleanOptionalAction,
160+
help='Disable the download progress bar for updates.',
161+
action='store_true',
127162
default=self.get_argparse_default('disable_progress', False)
128163
)
129164
parser.add_argument(
130165
'-sft',
131166
'--save-format-type',
132167
dest='save_format_type',
133-
help='compress save format name',
168+
help='Specify the save format type for compressed updates: "full", "version", or "name".',
134169
choices=['full', 'version', 'name'],
135170
default=self.get_argparse_default('save_format_type', 'full', False)
136171
)
137172
parser.add_argument(
138173
'-f',
139174
'--force',
140175
dest='force_download',
141-
help='force download',
142-
action=argparse.BooleanOptionalAction,
176+
help='Force the download of updates, even if they appear up to date.',
177+
action='store_true',
143178
default=False
144179
)
145180
parser.add_argument(
146181
'-uga',
147182
'--use-github-api',
148183
dest='use_github_api',
149-
help='use github api with this token',
184+
help='Use the GitHub API for updates, specifying the token to authenticate.',
150185
default=self.get_argparse_default('use_github_api', '', False)
151186
)
152187
parser.add_argument(
153188
'-udp',
154189
'--update-default-params',
155190
dest='update_default_params',
156-
help='update default params',
157-
action=argparse.BooleanOptionalAction,
191+
help='Update the default parameters stored in the configuration.',
192+
action='store_true',
193+
default=False
194+
)
195+
parser.add_argument(
196+
'-dmc',
197+
'--disable-mutex-check',
198+
dest='disable_mutex_check',
199+
help='Allow multiple instances of the script to run simultaneously by disabling the mutex check.',
200+
action='store_true',
158201
default=False
159202
)
160203
parser.add_argument(
161204
'-d',
162205
'--debug',
163206
dest='debug',
164-
help='enable debug output',
165-
action=argparse.BooleanOptionalAction,
207+
help='Enable detailed debug output for troubleshooting.',
208+
action='store_true',
166209
default=False
167210
)
168211

@@ -249,7 +292,7 @@ def handle_auto_update(self):
249292
try:
250293
updater.update(self.config_section_self_update)
251294
except Exception as exception:
252-
logging.info(exception)
295+
logging.error(exception)
253296

254297
# add missing new line separator
255298
logging.info("\n")
@@ -269,7 +312,8 @@ def handle_tool_updates(self, updater, update_list):
269312
try:
270313
updater.update(tool)
271314
except Exception as exception:
272-
logging.info(exception)
315+
failed_updates += 1
316+
logging.error(exception)
273317

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

@@ -293,13 +337,19 @@ def main(self):
293337
"""
294338
Main entry point for the UpdateManager.
295339
"""
340+
# setup signals
296341
signal.signal(signal.SIGINT, self.exit_handler)
342+
signal.signal(signal.SIGTERM, self.exit_handler)
343+
344+
# setup script
297345
self.change_current_directory()
298346
self.print_banner()
299347
self.parse_arguments()
300348
self.set_logging_level()
349+
self.check_single_instance()
301350
self.update_default_params()
302351
self.handle_updates()
352+
self.cleanup_mutex()
303353

304354

305355
# Entry point for the script

bin/updater/src/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ colorama>=0.4.4
33
tqdm>=4.62.3
44
py7zr>=0.16.1
55
rarfile>=4.0
6+
psutil>=6.1.0

bin/updater/src/universal_updater/Packer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def unpack_rar(self, file_path, unpack_path, file_pass=None):
6262
"""
6363
# download first "UnRAR for Windows" from https://www.rarlab.com/rar_add.htm
6464
# direct link: https://www.rarlab.com/rar/unrarw32.exe
65+
# new link: https://www.win-rar.com/predownload.html?&Version=32bit&L=0.
6566
with rarfile.RarFile(file_path, 'r') as compressed:
6667
compressed.extractall(unpack_path, pwd=file_pass)
6768

0 commit comments

Comments
 (0)