1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ghq をインストールする Python スクリプト

1
Posted at

「パッケージマネージャも 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 に限らず使えそう。そんな状況ある??

  1. x-motemen/ghq: Remote repository management made easy ↩

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?