|
| 1 | +import sys |
| 2 | + |
| 3 | +from archinstall.lib.command import SysCommand |
| 4 | +from archinstall.lib.exceptions import SysCallError |
| 5 | +from archinstall.lib.output import logger |
| 6 | + |
| 7 | +# paste.rs is a minimal text pastebin with syntax highlighting by extension. |
| 8 | +# 10 MiB is its documented upload limit. |
| 9 | +_PASTE_URL = 'https://paste.rs' |
| 10 | +_PASTE_MAX_SIZE = 10 * 1024 * 1024 |
| 11 | + |
| 12 | + |
| 13 | +def share_install_log() -> int: |
| 14 | + """Upload /var/log/archinstall/install.log to paste.rs and print the URL. |
| 15 | +
|
| 16 | + Intended for users to paste the URL into a GitHub issue when reporting a |
| 17 | + bug. Always asks for explicit confirmation - the log may contain hostname, |
| 18 | + mirror URLs, package list, partition layout and other system details which |
| 19 | + become public on upload. |
| 20 | +
|
| 21 | + All diagnostic output goes to stderr instead of the standard log helpers, |
| 22 | + so the file we are about to upload is not modified by this command. |
| 23 | + """ |
| 24 | + log_path = logger.path |
| 25 | + |
| 26 | + if not log_path.exists(): |
| 27 | + print(f'Log file not found: {log_path}', file=sys.stderr) |
| 28 | + return 1 |
| 29 | + |
| 30 | + size = log_path.stat().st_size |
| 31 | + if size == 0: |
| 32 | + print(f'Log file is empty: {log_path}', file=sys.stderr) |
| 33 | + return 1 |
| 34 | + |
| 35 | + if size > _PASTE_MAX_SIZE: |
| 36 | + print( |
| 37 | + f'Log file is too large to share: {size} bytes ' |
| 38 | + f'(limit: {_PASTE_MAX_SIZE} bytes). ' |
| 39 | + f'Trim it or upload manually.', |
| 40 | + file=sys.stderr, |
| 41 | + ) |
| 42 | + return 1 |
| 43 | + |
| 44 | + print(f'About to upload {log_path} ({size} bytes) to {_PASTE_URL}', file=sys.stderr) |
| 45 | + print( |
| 46 | + 'The log may contain hostname, mirror URLs, package list and ' |
| 47 | + 'partition layout. The uploaded paste is public.', |
| 48 | + file=sys.stderr, |
| 49 | + ) |
| 50 | + |
| 51 | + try: |
| 52 | + answer = input('Continue? [y/N]: ').strip().lower() |
| 53 | + except (EOFError, KeyboardInterrupt): |
| 54 | + print(file=sys.stderr) |
| 55 | + return 1 |
| 56 | + |
| 57 | + if answer not in ('y', 'yes'): |
| 58 | + print('Cancelled.', file=sys.stderr) |
| 59 | + return 1 |
| 60 | + |
| 61 | + try: |
| 62 | + result = SysCommand(f'curl -sS --data-binary @{log_path} {_PASTE_URL}') |
| 63 | + except SysCallError as e: |
| 64 | + print(f'Upload failed: {e}', file=sys.stderr) |
| 65 | + return 1 |
| 66 | + |
| 67 | + url = result.decode().strip() |
| 68 | + |
| 69 | + if not url.startswith('http'): |
| 70 | + print(f'Unexpected response from {_PASTE_URL}: {url[:200]!r}', file=sys.stderr) |
| 71 | + return 1 |
| 72 | + |
| 73 | + print(url) |
| 74 | + return 0 |
0 commit comments