Lucas A. Meyer
Lucas A. Meyer

Reputation: 478

Automatically installing the latest Quarto version

I use a Quarto script to render my blog in Python. Quarto frequently updates, and I want to automatically install the latest version so I can have a script that automatically updates Quarto before rendering my blog.

How can I do this?

Upvotes: 3

Views: 1342

Answers (2)

Lucas A. Meyer
Lucas A. Meyer

Reputation: 478

For my own blog, I use the Python script below (requires installing the GitHub CLI):

    print("Upgrading Quarto")

    # delete all files in this directory that have the .msi extension
    for fname in os.listdir('.'):
        if fname.endswith('.msi'):
            os.remove(fname)

    # download the latest version of Quarto
    os.system("gh --repo quarto-dev/quarto-cli release download --pattern *.msi")

    time. Sleep(1)

    # get the full path of the file that was downloaded
    for fname in os.listdir('.'):
        if fname.endswith('.msi'):
            msi_file = os.path.abspath(fname)

    # install the latest version of Quarto
    os.system(f"msiexec /i {msi_file} /qn")

    # update the PATH, adding c:\Program Files\Quarto\bin if it doesn't already exist
    path = os.environ.get('PATH')
    if 'c:\\Program Files\\Quarto\\bin' not in path:
        os.environ['PATH'] = path + ';c:\\Program Files\\Quarto\\bin'

    # delete the .msi file
    os.remove(msi_file)

    # Show the quarto version
    os.system("quarto --version")

    # Print completion message
    print("Quarto upgrade completed")

If I don't have Python but have access to the shell, I use the script below:

wget https://quarto.org/docs/download/_download.json 
ver=$(grep -o '"version": "[^"]*' _download.json | grep -o '[^"]*$')
wget https://github.com/quarto-dev/quarto-cli/releases/download/v${ver}/quarto-${ver}-linux-amd64.deb
sudo dpkg -i quarto-${ver}-linux-amd64.deb
rm quarto-${ver}-linux-amd64.deb
rm _download.json

It takes advantage of the _download.json file in Quarto's website having the latest version.

Upvotes: 1

cderv
cderv

Reputation: 6552

This is another example leveraging latest github release and gh CLI

gh --repo quarto-dev/quarto-cli release download --pattern '*.deb'
sudo dpkg -i $(ls quarto-*.deb)
rm $(ls quarto-*.deb)

This could be adapted to any repo with Github release.

Using _download.json is the safest though, especially when stable release of Quarto will be out.

Upvotes: 3

Related Questions