Skip to content

Instantly share code, notes, and snippets.

@ObjectBoxPC
Created March 4, 2026 20:07
Show Gist options
  • Select an option

  • Save ObjectBoxPC/28bc1d71982676c65d06a6d2281fcf81 to your computer and use it in GitHub Desktop.

Select an option

Save ObjectBoxPC/28bc1d71982676c65d06a6d2281fcf81 to your computer and use it in GitHub Desktop.
Automatically update VeraCrypt (for Debian) from Launchpad
#!/usr/bin/env python3
import json
import datetime
import re
import shutil
import subprocess
import tempfile
import urllib.request
USER_AGENT = "VeraCrypt-Update/1.0"
LAUNCHPAD_PROJECT_API = "https://api.launchpad.net/devel/veracrypt"
FILE_DESC_REGEX = re.compile("Uploaded file: veracrypt-console-.*-Debian-13-amd64\\.deb")
VERSION_OUTPUT_REGEX = re.compile("VeraCrypt (.*)")
def request_json(url):
headers = { "User-Agent": USER_AGENT, "Accept": "application/json" }
request = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(request) as json_result:
return json.load(json_result)
def open_download(url):
headers = { "User-Agent": USER_AGENT }
request = urllib.request.Request(url, headers=headers)
return urllib.request.urlopen(request)
def get_release_from_api():
project = request_json(LAUNCHPAD_PROJECT_API)
releases = request_json(project["releases_collection_link"])
releases["entries"].sort(key=lambda e: datetime.datetime.fromisoformat(e["date_created"]), reverse=True)
latest_release = releases["entries"][0]
release_version = latest_release["version"]
release_files = request_json(latest_release["files_collection_link"])
for release_file in release_files["entries"]:
if FILE_DESC_REGEX.match(release_file["description"]):
return (release_version, release_file["file_link"])
return None
def get_version_from_system():
version_output = subprocess.run(["veracrypt", "--version"], capture_output=True, check=True, encoding="utf-8")
version_match = VERSION_OUTPUT_REGEX.match(version_output.stdout)
return version_match.group(1) if version_match else None
api_release = get_release_from_api()
system_version = get_version_from_system()
if api_release:
(api_version, download_url) = api_release
if api_version == system_version and False:
print("VeraCrypt appears to be up to date")
else:
print("Installing version: {}".format(api_version))
with open_download(download_url) as download_file, \
tempfile.NamedTemporaryFile(suffix=".deb", prefix="veracrypt-console.", delete_on_close=False) as temp_file:
shutil.copyfileobj(download_file, temp_file)
temp_file.close()
subprocess.run(["sudo", "apt-get", "install", "-y", temp_file.name], check=True)
else:
print("Could not get version from release feed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment