-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDebug.sh
More file actions
158 lines (136 loc) · 4.46 KB
/
getDebug.sh
File metadata and controls
158 lines (136 loc) · 4.46 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
156
157
158
#! /bin/sh
set -euo pipefail
# Set Variables
tsBinary=$(which tailscale)
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
HOSTNAME="$(hostname 2>/dev/null || echo unknown-host)"
BASE_DIR="/tmp/linux_info_${HOSTNAME}_${TIMESTAMP}"
ARCHIVE_NAME="${BASE_DIR}.tar.gz"
# Check if root and whether to use sudo or doas
CAN_ROOT=
SUDO=
if [ "$(id -u)" = 0 ]; then
CAN_ROOT=1
SUDO=""
elif type sudo >/dev/null; then
CAN_ROOT=1
SUDO="sudo"
elif type doas >/dev/null; then
CAN_ROOT=1
SUDO="doas"
fi
if [ "$CAN_ROOT" != "1" ]; then
echo "This installer needs to run commands as root."
echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
echo "Either re-run this script as root, or set up sudo/doas."
exit 1
fi
# Make logging folder
mkdir -p "$BASE_DIR"
run_and_log() {
local outfile="$1"
shift
{
echo "===== Command: $* ====="
echo "===== Timestamp: $(date -Is) ====="
echo
"$@"
} > "${BASE_DIR}/${outfile}" 2>&1 || true
}
copy_file_if_exists() {
local src="$1"
local dst="$2"
{
echo "===== Source: ${src} ====="
echo "===== Timestamp: $(date -Is) ====="
echo
if [[ -e "$src" ]]; then
cat "$src"
else
echo "File not found: $src"
fi
} > "${BASE_DIR}/${dst}" 2>&1
}
# Basic system context
{
echo "Timestamp: $(date -Is)"
echo "Hostname: ${HOSTNAME}"
echo "Kernel: $(uname -a)"
echo "User: $(id)"
} > "${BASE_DIR}/system_info.txt"
# IP information
if command -v ip >/dev/null 2>&1; then
run_and_log "ip_addr.txt" ip addr
run_and_log "ip_link.txt" ip link
run_and_log "ip_route.txt" ip route show
run_and_log "ip_route_table_all.txt" ip route show table all
run_and_log "ip_rule.txt" ip rule show
run_and_log "ip_neigh.txt" ip neigh
else
echo "'ip' command not found" > "${BASE_DIR}/ip_command_missing.txt"
fi
# Legacy fallback commands if available
if command -v ifconfig >/dev/null 2>&1; then
run_and_log "ifconfig.txt" ifconfig -a
fi
if command -v route >/dev/null 2>&1; then
run_and_log "route_n.txt" route -n
fi
if command -v netstat >/dev/null 2>&1; then
run_and_log "netstat_rn.txt" netstat -rn
fi
# Resolver configuration
copy_file_if_exists "/etc/resolv.conf" "resolv.conf.txt"
if [[ -d /etc/resolv.conf.d ]]; then
tar -cf - /etc/resolv.conf.d 2>/dev/null | tar -xf - -C "${BASE_DIR}" 2>/dev/null || true
fi
if [[ -d /etc/systemd/resolved.conf.d ]]; then
tar -cf - /etc/systemd/resolved.conf.d 2>/dev/null | tar -xf - -C "${BASE_DIR}" 2>/dev/null || true
fi
if [[ -f /etc/systemd/resolved.conf ]]; then
copy_file_if_exists "/etc/systemd/resolved.conf" "systemd_resolved.conf.txt"
fi
# DNS status if available
if command -v resolvectl >/dev/null 2>&1; then
run_and_log "resolvectl_status.txt" resolvectl status
run_and_log "resolvectl_dns.txt" resolvectl dns
run_and_log "resolvectl_domain.txt" resolvectl domain
elif command -v systemd-resolve >/dev/null 2>&1; then
run_and_log "systemd_resolve_status.txt" systemd-resolve --status
fi
# NetworkManager info if available
if command -v nmcli >/dev/null 2>&1; then
run_and_log "nmcli_device_show.txt" nmcli device show
run_and_log "nmcli_connection_show.txt" nmcli connection show
fi
# Tailscale info if available
if command -v tailscale >/dev/null 2>&1; then
run_and_log "tailscale_status.txt" tailscale status
run_and_log "tailscale_netcheck.txt" tailscale netcheck
run_and_log "tailscale_debug_ts2021.txt" tailscale debug ts2021 --verbose
run_and_log "tailscale_bugreport.txt" tailscale bugreport
run_and_log "tailscale_debug_prefs.txt" tailscale debug prefs
run_and_log "tailscale_debug_netmap.txt" tailscale debug netmap
run_and_log "tailscale_dns.txt" tailscale dns status
{
echo "===== Command: tailscale ping (all peers) ====="
echo "===== Timestamp: $(date -Is) ====="
echo
tailscale status | awk '/^$/{exit} {print $2}' | while read -r host; do
tailscale ping -c 1 "$host" 2>&1
echo ""
done
} > "${BASE_DIR}/tailscale_ping_peers.txt" 2>&1 || true
else
echo "tailscale command not found" > "${BASE_DIR}/tailscale_missing.txt"
fi
# Create archive
tar -czf "$ARCHIVE_NAME" "$BASE_DIR"
# Verify archive creation before deleting
if [[ -f "$ARCHIVE_NAME" ]]; then
rm -rf "$BASE_DIR"
echo "Cleaned up folder: $BASE_DIR"
else
echo "Archive not created, keeping folder: $BASE_DIR"
fi
echo "Created archive: $ARCHIVE_NAME"