raylu 1 year ago
parent
commit
eaf141ee97
2 changed files with 30 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 29 0
      install_extras.py

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 /bk
 /buildifier
+/dua
 /eza
 /git-whence
 /starship

+ 29 - 0
install_extras.py

@@ -4,6 +4,7 @@ from __future__ import annotations
 import os
 import pathlib
 import platform
+import shutil
 import subprocess
 import tarfile
 
@@ -13,6 +14,7 @@ CURRENT_DIR = pathlib.Path(__file__).parent
 
 def main():
 	delta()
+	dua()
 	eza()
 	git_whence()
 	starship()
@@ -45,6 +47,33 @@ def delta():
 	finally:
 		os.unlink(deb_path)
 
+def dua():
+	if platform.system() == 'Darwin':
+		print('$ brew install dua-cli')
+		subprocess.run(['brew', 'install', 'dua-cli'], check=True)
+		return
+	else:
+		assert platform.system() == 'Linux'
+
+	dua_path = CURRENT_DIR / 'dua'
+	if dua_path.exists():
+		print('dua already downloaded')
+		return
+
+	client = httpx.Client()
+	latest = gh_latest_version(client, 'Byron', 'dua-cli')
+	version = latest['name']
+	dirname = f'dua-{version}-{platform.machine()}-unknown-linux-musl'
+	filename = dirname + '.tar.gz'
+	(asset,) = (asset for asset in latest['assets'] if asset['name'] == filename)
+	tarball_path = CURRENT_DIR / 'dua.tar.gz'
+	download(client, asset['browser_download_url'], tarball_path)
+	with tarfile.open(tarball_path) as tar:
+		with tar.extractfile(dirname + '/dua') as binary, dua_path.open('wb') as f: # pyright: ignore[reportOptionalContextManager]
+			shutil.copyfileobj(binary, f)
+	os.unlink(tarball_path)
+	dua_path.chmod(0o755)
+
 def eza():
 	if platform.system() == 'Darwin':
 		print('$ brew install eza')