Created
December 22, 2022 12:34
-
-
Save jcassette/ef75aebce99fa5803e7151e23d17748f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import io | |
| import pathlib | |
| import subprocess | |
| import urllib.parse | |
| import urllib.request | |
| import zipfile | |
| BASEURL = 'https://github.com/storj/storj/releases/latest/download/' | |
| def run(*args, **kwargs): | |
| print(*args) | |
| return subprocess.run(args, check=True, **kwargs) | |
| def fetch(base, arg, **kwargs): | |
| url = urllib.parse.urljoin(base, arg) | |
| print(url) | |
| return urllib.request.urlopen(url, **kwargs) | |
| def main(): | |
| home = pathlib.Path.home() | |
| bindir = home / '.local' / 'bin' | |
| if not bindir.exists(): | |
| bindir.mkdir(parents=True) | |
| if not (bindir / 'identity').exists(): | |
| with fetch(BASEURL, 'identity_linux_amd64.zip') as rf: | |
| data = io.BytesIO(rf.read()) | |
| with zipfile.ZipFile(data) as zf: | |
| zf.extract('identity', path=bindir) | |
| (bindir / 'identity').chmod(0o555) | |
| if not (bindir / 'storagenode').exists(): | |
| with fetch(BASEURL, 'storagenode_linux_amd64.zip') as rf: | |
| data = io.BytesIO(rf.read()) | |
| with zipfile.ZipFile(data) as zf: | |
| zf.extract('storagenode', path=bindir) | |
| (bindir / 'storagenode').chmod(0o555) | |
| sysdir = home / '.config' / 'systemd' / 'user' | |
| if not sysdir.exists(): | |
| sysdir.mkdir(parents=True) | |
| service = sysdir / 'storagenode.service' | |
| if not service.exists(): | |
| service.write_text('''\ | |
| [Unit] | |
| Description=Storj node | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| ExecStart=%h/.local/bin/storagenode run | |
| Restart=always | |
| [Install] | |
| WantedBy=default.target | |
| ''') | |
| datadir = home / '.local.' / 'share' / 'storj' | |
| if not (datadir / 'identity' / 'storagenode').exists(): | |
| print('This can take a very long time') | |
| run(bindir / 'identity', 'create', 'storagenode') | |
| print('Visit https://www.storj.io/host-a-node') | |
| token = input('Enter auth token: ') | |
| run(bindir / 'identity', 'authorize', 'storagenode', token) | |
| if not (datadir / 'storagenode').exists(): | |
| run(bindir / 'storagenode', 'setup') | |
| run(bindir / 'storagenode', 'config') | |
| print('All good. Please execute the following commands:') | |
| print(' sudo loginctl enable-linger $USER') | |
| print(' systemctl --user enable storagenode') | |
| print(' systemctl --user start storagenode') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment