Repository navigation
Expand file tree
/
Copy pathqrcode.sh
More file actions
executable file
·155 lines (134 loc) · 8.49 KB
/
Copy pathqrcode.sh
File metadata and controls
executable file
·155 lines (134 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# ODS — ASCII QR Code Generator
# Generates simple QR codes for terminal display without external dependencies
# ═══════════════════════════════════════════════════════════════
# QR CODE DISPLAY
# ═══════════════════════════════════════════════════════════════
# Best-effort LAN IP detection for remote access URLs.
#
# The address is read from the `src` field by name, not by column. `ip route
# get` only emits `via <gw>` when the route has a gateway; on an on-link
# default route (WSL2, point-to-point and VPN links, some cloud VMs) the two
# fields are absent and the column that held the address holds `uid` instead.
_ods_lan_ip() {
local lan_ip=""
if command -v ip >/dev/null 2>&1; then
lan_ip=$(ip -4 route get 1.1.1.1 2>/dev/null \
| awk '{for (i = 1; i <= NF; i++) if ($i == "src") { print $(i + 1); exit }}')
fi
if [[ -z "$lan_ip" ]] && command -v ifconfig >/dev/null 2>&1; then
lan_ip=$(ifconfig 2>/dev/null | awk '/inet / && $2 != "127.0.0.1" {print $2; exit}')
fi
printf '%s' "$lan_ip"
}
# Print a QR code for the dashboard URL
# Falls back to plain text if qrencode not available
local display_url="${1:-}"
if [[ -z "$display_url" ]]; then
local lan_ip remote_port="${DASHBOARD_REMOTE_PORT:-3011}"
[[ "$remote_port" =~ ^[0-9]+$ ]] || remote_port=3011
lan_ip=$(_ods_lan_ip)
display_url="http://${lan_ip:-localhost}:${remote_port}"
fi
echo ""
# Try qrencode if available
if command -v qrencode >/dev/null 2>&1; then
echo -e " ${BOLD}Scan to open Dashboard:${NC}"
echo ""
qrencode -t ANSIUTF8 -m 2 "$display_url" | sed 's/^/ /'
echo ""
echo -e " ${CYAN}$display_url${NC}"
else
# Fallback: Simple ASCII box with URL
print_url_box "$display_url"
fi
}
# Print a stylish URL box (fallback when qrencode unavailable)
print_url_box() {
local url=$1
local url_len=${#url}
local box_width=$((url_len + 6))
# Build horizontal line
local hline=""
for ((i=0; i<box_width; i++)); do hline+="═"; done
echo -e " ${CYAN}╔${hline}╗${NC}"
echo -e " ${CYAN}║${NC} ${BOLD}${url}${NC} ${CYAN}║${NC}"
echo -e " ${CYAN}╚${hline}╝${NC}"
}
# ═══════════════════════════════════════════════════════════════
# SUCCESS CARD
# ═══════════════════════════════════════════════════════════════
# Print the final success card with all access info
print_success_card() {
local tier=$1
local model=$2
local dashboard_url=${3:-"http://localhost:3001"}
local api_url=${4:-"http://localhost:8000/v1"}
# Get LAN IP for remote access URLs
local lan_ip
lan_ip=$(_ods_lan_ip)
local remote_port="${DASHBOARD_REMOTE_PORT:-3011}"
[[ "$remote_port" =~ ^[0-9]+$ ]] || remote_port=3011
local remote_dash="http://${lan_ip:-localhost}:${remote_port}"
local remote_api="http://${lan_ip:-localhost}:8000/v1"
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${BOLD}🌙 ODS is Ready!${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}╠═══════════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${BOLD}Tier:${NC} $tier ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${BOLD}Model:${NC} $model ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}╠═══════════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${CYAN}Local Access:${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} Dashboard: $dashboard_url ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} API: $api_url ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
if [[ -n "$lan_ip" ]]; then
echo -e "${GREEN}║${NC} ${CYAN}Remote Access (LAN):${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} Dashboard: $remote_dash ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} API: $remote_api ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
fi
echo -e "${GREEN}╠═══════════════════════════════════════════════════════════════╣${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${BOLD}Quick Commands:${NC} ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} View logs: docker compose logs -f ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} Stop server: docker compose down ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} Restart: docker compose restart ${GREEN}║${NC}"
echo -e "${GREEN}║${NC} ${GREEN}║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
# Print QR code for mobile access
if [[ -n "$lan_ip" ]]; then
print_dashboard_qr "$remote_dash"
fi
echo ""
echo -e "${BOLD}Welcome to your ODS. 🌙${NC}"
echo ""
}
# ═══════════════════════════════════════════════════════════════
# INSTALL SUMMARY
# ═══════════════════════════════════════════════════════════════
# Print installation summary with timing
print_install_summary() {
local tier=$1
local model=$2
local start_time=$3
local end_time=$4
local duration=$((end_time - start_time))
local duration_str
duration_str=$(format_duration $duration)
echo ""
echo -e "${GREEN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${BOLD}Installation Complete${NC}"
echo -e "${GREEN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e " ${BOLD}Tier:${NC} $tier"
echo -e " ${BOLD}Model:${NC} $model"
echo -e " ${BOLD}Install Time:${NC} $duration_str"
echo ""
}