Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: program update from within program itself #1097

Open
shpati opened this issue Oct 30, 2024 · 2 comments
Open

[Feature request]: program update from within program itself #1097

shpati opened this issue Oct 30, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@shpati
Copy link

shpati commented Oct 30, 2024

What do you need?

I would like the program to update itself when given the --update switch. I have set up a batch script (update.bat) that does this for me, but I think it should be a functionality within the program.

My batch script is given below. It downloads the latest release file from GitHub, compares to the existing file, and if the files differ it replaces the existing file with the downloaded one.

@echo off
setlocal EnableDelayedExpansion

:: Configuration
set URL=https://github.com/danielmiessler/fabric/releases/latest/download/fabric-windows-amd64.exe
set EXISTING_FILE=fabric.exe
set TEMP_FILE=fabric.temp
set WGET_PATH=busybox wget

:: Download the file using wget
%WGET_PATH% -q "%URL%" -O "%TEMP_FILE%"

:: Check if download was successful
if %ERRORLEVEL% NEQ 0 (
    echo Error downloading file
    del "%TEMP_FILE%" 2>nul
    exit /b 1
)

:: Compare files if existing file exists
if exist "%EXISTING_FILE%" (
    fc /b "%EXISTING_FILE%" "%TEMP_FILE%" > nul
    if !ERRORLEVEL! EQU 0 (
        echo Files are identical. No update needed.
        del "%TEMP_FILE%"
    ) else (
        echo Files are different. Updating...
        del "%EXISTING_FILE%"
        ren "%TEMP_FILE%" "%EXISTING_FILE%"
        echo Update complete.
    )
) else (
    echo Existing file not found. Creating new file...
    move "%TEMP_FILE%" "%EXISTING_FILE%"
    echo File created.
)

endlocal
@shpati shpati added the enhancement New feature or request label Oct 30, 2024
@jaredmontoya
Copy link
Contributor

jaredmontoya commented Oct 31, 2024

Well actually, it's not a common thing for programs(especially cli ones) to self update, that's what package managers are meant for.

I guess you are using Windows, but even windows has chocolatey the package manager and fabric already has a setup_fabric.bat script that uses chocolatey to install the go language compiler that also happens to be a package manager itself and is able to download, compile and install fabric with go install github.com/danielmiessler/fabric@latest

That is not the same as downloading prebuilt fabric binaries but fabric is not a project that takes a lot of time to compile so it's not a big deal.

If you still want to download fabric binaries only I would suggest you to "install" your fabric-update.bat script as a program by adding it to your PATH and instead of hypothetical fabric --update you will execute fabric-update or fabric-update.bat if windows doesn't let you run scripts without a file extension.

If the --update flag is introduced it will be dead binary weight in case fabric is installed to a read-only location, and if the user does not have write permissions to the installation location the user will have to escalate priviliges(if he can) and trust that his fabric binary that he obtained somewhere is not a modified build that has malware in it that will do something else with those priviliges after the update is completed.
Also, as far as I remember windows doesn't let any program's executable be deleted or edited if it's running, how is fabric going to overwrite itself then?

@shpati
Copy link
Author

shpati commented Nov 2, 2024

yt-dlp is a popular cli program that runs on windows and can self update, which is a very useful feature. So it is fully possible to do.

Your concerns about read only locations and escalation of privileges are not difficult to address. If the update location is read-only the program can just say so and exit. If the original binary file comes from another source than this fabric github repository I think executing that file is just as risky, with or without the update option. A tampered file could ask for priviledge escalation also when the user uses an existing option like updating patterns. The obvious thing to do in this case is to make sure binaries are downloaded from their official sources.

Doing a quick search I found the cross platform code written in go. See here: https://github.com/minio/selfupdate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants