「パッケージマネージャも curl も unzip もないけど Python だけはある Linux 環境」に ghq1 をインストールしたくなった。そんなことある??
install_ghq.py
from io import BytesIO
from os import chmod
import platform
from urllib.request import urlopen
from zipfile import ZipFile
arch = {"x86_64": "amd64", "aarch64": "arm64"}[platform.machine()]
url = f"https://github.com/x-motemen/ghq/releases/latest/download/ghq_linux_{arch}.zip"
dest = "/usr/local/bin/ghq"
with urlopen(url) as res, ZipFile(BytesIO(res.read())) as zf:
filename = next(n for n in zf.namelist() if n.endswith("/ghq"))
with open(dest, "wb") as f:
f.write(zf.read(filename))
chmod(dest, 0o755)
$ sudo python3 install_ghq.py
$ ghq --version
ghq version 1.11.2 (rev:b9273dd)
「シングルバイナリが zip で提供されているが unzip が無い」という状況で、もし Python があるなら ghq に限らず使えそう。そんな状況ある??