This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Write connection details to TTY on boot #53
Merged
mayankchhabra
merged 19 commits into
getumbrel:master
from
lukechilds:connection-details
Jul 27, 2020
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b4f26db
Add connection-details script
lukechilds 4ff305c
Reduce error correction for smaller QR code
lukechilds be64734
Use multiline string instead of multiple print()s
lukechilds 2c4fed6
Remvoe timout log
lukechilds 529c2a7
Run connection-details in rc.local
lukechilds b8d9ab4
Remove extra space
lukechilds cb3cf60
Add Pipfile and Pipfile.lock to prevent dependency backdoor
lukechilds f6f3fbe
Add IP address
lukechilds a52c7c6
Attempt to get qrcode dep installed
lukechilds 4a70857
Retry GitHub actions build
lukechilds c1bd4c2
Revert "Retry GitHub actions build"
lukechilds 23f47ab
Merge remote-tracking branch 'upstream/master' into connection-details
lukechilds 675d2e3
Quote variables
lukechilds d079e16
More accurate binary check
lukechilds a3cd43a
Install qrcode via apt
lukechilds 08ab57b
Copy in binary with install
lukechilds 0c904fd
conection-details => umbrel-details
lukechilds 268d14b
Make sure we actually have an IP
lukechilds 28a6164
Import consistency
lukechilds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python3-qrcode |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash -e | ||
|
||
echo "Installing umbrel-details" | ||
install -m 755 files/umbrel-details "${ROOTFS_DIR}"/usr/local/bin/umbrel-details |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import os | ||
import time | ||
import subprocess | ||
import io | ||
import qrcode | ||
|
||
umbrel_ascii = ''' | ||
,;###GGGGGGGGGGl#Sp | ||
,##GGGlW""^' '`""%GGGG#S, | ||
,#GGG" "lGG#o | ||
#GGl^ '$GG# | ||
,#GGb \GGG, | ||
lGG" "GGG | ||
#GGGlGGGl##p,,p##lGGl##p,,p###ll##GGGG | ||
!GGGlW"""*GGGGGGG#""""WlGGGGG#W""*WGGGGS | ||
"" "^ '" "" | ||
|
||
|
||
@GGS lG# | ||
!GGG !GGG | ||
!GGG !GGG | ||
!GGG !GGG | ||
!GGG !GGG | ||
!GGG !GGG | ||
'GGG $GGl | ||
"GGG#psqp##GG# | ||
"%GGGGGG#" | ||
'''.strip('\n') | ||
|
||
def create_qr(data): | ||
output_buffer = io.TextIOWrapper(io.BytesIO(), sys.stdout.encoding) | ||
|
||
qr = qrcode.QRCode(border=0, error_correction=qrcode.constants.ERROR_CORRECT_Q) | ||
qr.add_data(data) | ||
qr.print_ascii(out=output_buffer) | ||
|
||
output_buffer.seek(0) | ||
qr_ascii = output_buffer.read().strip() | ||
|
||
return qr_ascii | ||
|
||
def combine_ascii(left_ascii, right_ascii, spacing=0): | ||
left_lines = left_ascii.split('\n') | ||
right_lines = right_ascii.split('\n') | ||
|
||
no_left_lines = len(left_lines) | ||
no_right_lines = len(right_lines) | ||
|
||
left_width = max(list(map(lambda line: len(line), left_lines))) | ||
max_height = max(no_left_lines, no_right_lines) | ||
|
||
lines = [] | ||
for i in range(max_height): | ||
left_line = left_lines[i] if i < no_left_lines else "" | ||
right_line = right_lines[i] if i < no_right_lines else "" | ||
|
||
padding = " " * ((left_width - len(left_line)) + spacing) | ||
|
||
lines.append(left_line + padding + right_line) | ||
|
||
return "\n".join(lines) | ||
|
||
def read_file_when_available(file_path, timeout): | ||
start = time.time() | ||
while not os.path.exists(file_path): | ||
if (time.time() - start) > timeout: | ||
return False | ||
time.sleep(1) | ||
|
||
with open(file_path, "r") as file: | ||
file_contents = file.read() | ||
|
||
return file_contents | ||
|
||
def run(command): | ||
result = subprocess.run(command, stdout=subprocess.PIPE) | ||
return result.stdout.decode('utf-8').rstrip("\n") | ||
|
||
def main(): | ||
timeout = 30 | ||
tor_hostname_file = "/home/umbrel/tor/data/web/hostname" | ||
tor_hostname = read_file_when_available(tor_hostname_file, timeout) | ||
|
||
ip = run(['hostname', '-I']).split(" ")[0] | ||
|
||
if not tor_hostname or not ip: | ||
print("Couldn't get connection details") | ||
return | ||
|
||
tor_hostname_qr_ascii = create_qr(tor_hostname.strip()) | ||
ascii_banner = combine_ascii(umbrel_ascii, tor_hostname_qr_ascii, spacing=10) | ||
|
||
connection_details = f""" | ||
|
||
|
||
{ascii_banner} | ||
|
||
Your Umbrel is up and running at: | ||
|
||
http://umbrel.local | ||
http://{ip} | ||
http://{tor_hostname} | ||
""" | ||
print(connection_details) | ||
|
||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add a
clear
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should clear the TTY here since there could be useful log output on the screen that we don't want to overwrite.