Skip to content

Commit 420fbb8

Browse files
Adds Matter SDK Doctor
1 parent adcc07a commit 420fbb8

File tree

5 files changed

+481
-0
lines changed

5 files changed

+481
-0
lines changed

scripts/sdk-doctor/_network.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) 2024 Project CHIP Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Function to display information for each network interface
19+
display_interface_info() {
20+
interface=$1
21+
echo "Interface: $interface"
22+
23+
# Check if interface is up
24+
if ip link show "$interface" | grep -q 'state UP'; then
25+
echo " Status: UP"
26+
else
27+
echo " Status: DOWN"
28+
fi
29+
30+
# Get and display the IPv4 address
31+
ipv4_address=$(ip -4 addr show "$interface" | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
32+
[ -z "$ipv4_address" ] && ipv4_address="N/A"
33+
echo " IPv4 Address: $ipv4_address"
34+
35+
# Get and display the IPv6 address
36+
ipv6_address=$(ip -6 addr show "$interface" | grep -oP '(?<=inet6\s)[a-f0-9:]+')
37+
[ -z "$ipv6_address" ] && ipv6_address="N/A"
38+
echo " IPv6 Address: $ipv6_address"
39+
40+
# Get and display the subnet mask
41+
subnet_mask=$(ifconfig "$interface" | grep -oP '(?<=Mask:)[0-9.]+')
42+
[ -z "$subnet_mask" ] && subnet_mask="N/A"
43+
echo " Subnet Mask: $subnet_mask"
44+
45+
# Get and display the MAC address
46+
mac_address=$(ip link show "$interface" | grep -oP '(?<=ether\s)[a-f0-9:]+')
47+
[ -z "$mac_address" ] && mac_address="N/A"
48+
echo " MAC Address: $mac_address"
49+
}
50+
51+
# Get a list of all network interfaces
52+
interfaces=$(ip link show | grep -oP '(?<=^\d: )[e-w]+[0-9a-zA-Z-]+')
53+
54+
# Iterate over each interface and display relevant information
55+
for intf in $interfaces; do
56+
display_interface_info "$intf"
57+
echo ""
58+
done
59+
60+
# Get and display the default gateway
61+
default_gateway=$(ip route | grep default | awk '{print $3}')
62+
[ -z "$default_gateway" ] && default_gateway="N/A"
63+
echo "Default Gateway: $default_gateway"
64+
65+
# Get and display the DNS server information
66+
mapfile -t dns_servers < <(grep nameserver /etc/resolv.conf | awk '{print $2}')
67+
if [ ${#dns_servers[@]} -eq 0 ]; then
68+
echo "DNS Servers: N/A"
69+
else
70+
echo "DNS Servers: ${dns_servers[*]}"
71+
fi
72+
echo
73+
74+
# Check if Internet is available
75+
echo "Checking Internet availability..."
76+
if ping -c 1 8.8.8.8 &>/dev/null; then
77+
echo "Internet is available"
78+
else
79+
echo "Internet is not available"
80+
fi

scripts/sdk-doctor/_os.sh

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) 2024 Project CHIP Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
ROOT_DIR=$(realpath $(dirname "$0")/../..)
19+
cd $ROOT_DIR
20+
21+
# Function to display OS information
22+
get_os_info() {
23+
if [ -f /etc/os-release ]; then
24+
# If available, use /etc/os-release file
25+
. /etc/os-release
26+
echo "Name: $NAME"
27+
echo "Version: $VERSION"
28+
echo "ID: $ID"
29+
echo "ID Like: $ID_LIKE"
30+
elif [ -f /etc/*-release ]; then
31+
# If /etc/os-release is not available, use other available /etc/*-release file
32+
echo "OS Information from /etc/*-release:"
33+
cat /etc/*-release
34+
else
35+
# Print a message if unable to determine OS information
36+
echo "Cannot determine OS information."
37+
fi
38+
}
39+
40+
# Function to display kernel information
41+
get_kernel_info() {
42+
echo "Kernel Information:"
43+
uname -a | fold -w 88 -s
44+
}
45+
46+
# Function to display CPU information
47+
get_cpu_info() {
48+
echo "CPU Information:"
49+
lscpu | grep -E "^Architecture:|^CPU op-mode\(s\):|^CPU\(s\):|^Vendor ID:|^Model name:|^CPU max MHz:|^CPU min MHz:" |
50+
sed 's/^[ \t]*//;s/[ \t]*$//'
51+
}
52+
53+
# Function to display memory information
54+
get_memory_info() {
55+
echo "Memory Information:"
56+
free -h
57+
}
58+
59+
# Call the functions to display the information
60+
get_os_info
61+
echo
62+
63+
get_kernel_info
64+
echo
65+
66+
get_cpu_info
67+
echo
68+
69+
get_memory_info

scripts/sdk-doctor/_repo.sh

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) 2024 Project CHIP Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
ROOT_DIR=$(realpath $(dirname "$0")/../..)
19+
cd $ROOT_DIR
20+
21+
get_repo_and_branch_info() {
22+
# Input validation
23+
if [ -z "$1" ]; then
24+
echo "Please provide a path."
25+
return 1
26+
fi
27+
28+
path="$1"
29+
repo_friendly_name="Matter SDK"
30+
31+
if [ "$path" != "." ]; then
32+
title_case_path=$(echo "$path" | awk '{ for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2)); }1')
33+
repo_friendly_name=$title_case_path
34+
fi
35+
36+
# Check if the directory exists
37+
if [ ! -d "$path" ]; then
38+
echo "Directory '$path' does not exist."
39+
return 1
40+
fi
41+
42+
cd $path
43+
44+
# Get the URL of the remote origin
45+
remote_url=$(git config --get remote.origin.url)
46+
47+
if [ -n "$remote_url" ]; then
48+
# Extract the repository name from the URL
49+
repo_name=$(basename -s .git "$remote_url")
50+
51+
# Calculate the necessary padding to align the end pipe
52+
total_length=95 # Adjust this based on your frame width
53+
text_length=${#repo_friendly_name}+${#repo_name}+4 # 4 for the ": " and two spaces around the repo name
54+
padding_length=$((total_length - text_length))
55+
56+
echo '+-----------------------------------------------------------------------------------------------+'
57+
printf "| %s: %s%*s|\n" "$repo_friendly_name" "$repo_name" $padding_length ""
58+
echo '+-----------------------------------------------------------------------------------------------+'
59+
else
60+
# Print error message if there is no remote URL
61+
echo "Not a Git repository or no remote set"
62+
return 1
63+
fi
64+
65+
# Get the current branch and its tracking branch
66+
git_status=$(git status)
67+
tracking_branch_info=$(echo "$git_status" | grep "Your branch is up to date with")
68+
69+
# Extract the fork owner and branch from the tracking branch info
70+
if [[ $tracking_branch_info =~ Your\ branch\ is\ up\ to\ date\ with\ \'([^\']+)\' ]]; then
71+
fork_owner_and_branch="${BASH_REMATCH[1]}"
72+
else
73+
fork_owner_and_branch="Not set or not a tracking branch"
74+
fi
75+
76+
# Get the commit SHA of the current HEAD
77+
commit_sha=$(git rev-parse HEAD)
78+
echo "Commit SHA: $commit_sha"
79+
80+
# Get the commit message of the current HEAD
81+
commit_message=$(git log -1 --pretty=format:"%B")
82+
trimmed_commit_message=$(trim_commit_message "$commit_message")
83+
echo "Commit Message: $trimmed_commit_message"
84+
85+
# Get the commit author of the current HEAD
86+
commit_author=$(git log -1 --pretty=format:"%an")
87+
echo "Commit Author: $commit_author"
88+
89+
# Get the commit date and time of the current HEAD including timezone
90+
commit_datetime=$(git log -1 --pretty=format:"%cd" --date=format:"%Y-%m-%d %H:%M:%S %z")
91+
echo "Commit Date: $commit_datetime"
92+
93+
# Attempt to find branches that contain this commit
94+
branches=$(git branch --contains $commit_sha | sed 's/^/ /')
95+
96+
if [ -n "$branches" ]; then
97+
echo "Contained in branches:"
98+
echo "$branches"
99+
else
100+
echo "This commit is not on any known branch."
101+
fi
102+
103+
echo " Tracking: $fork_owner_and_branch"
104+
105+
echo
106+
107+
# Navigate back to the original directory
108+
cd $ROOT_DIR
109+
}
110+
111+
trim_commit_message() {
112+
local commit_message="$1"
113+
114+
# Check if the commit message contains a newline character
115+
if [[ "$commit_message" == *$'\n'* ]]; then
116+
# Extract the first line of the commit message
117+
local first_line=${commit_message%%$'\n'*}
118+
else
119+
# If there's no newline, use the entire commit message
120+
local first_line="$commit_message"
121+
fi
122+
123+
# Trim leading and trailing whitespace from the first line and echo it
124+
echo "$first_line" | sed 's/^[ \t]*//;s/[ \t]*$//'
125+
}
126+
127+
# Print SDK root git status
128+
get_repo_and_branch_info "."
129+
130+
# Handle arguments
131+
case "$1" in
132+
--git-sub)
133+
# Initialize an array to hold the directories
134+
declare -a repo_dirs
135+
136+
cd $ROOT_DIR
137+
138+
# Find directories containing a .github folder and store them in the array, excluding the current directory
139+
while IFS= read -r dir; do
140+
# Check if the directory is not the current directory
141+
if [[ "$dir" != "." ]]; then
142+
repo_dirs+=("$dir")
143+
fi
144+
done < <(find . -type d -name .github | awk -F'/[^/]*$' '{print $1}')
145+
146+
# Iterate through the directories and call the function for each
147+
for dir in "${repo_dirs[@]}"; do
148+
get_repo_and_branch_info "$dir"
149+
done
150+
;;
151+
*) ;;
152+
esac

scripts/sdk-doctor/_version.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) 2024 Project CHIP Authors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
ROOT_DIR=$(realpath $(dirname "$0")/../..)
19+
cd $ROOT_DIR
20+
21+
SPEC_VERSION=$(head -n 1 $ROOT_DIR/SPECIFICATION_VERSION)
22+
SPEC_SHA=$(head -n 1 $ROOT_DIR/data_model/spec_sha)
23+
SCRAPPER_VERSION=$(head -n 1 $ROOT_DIR/data_model/scraper_version)
24+
25+
echo 'SPEC VERSION:' $SPEC_VERSION
26+
echo 'SPEC SHA:' $SPEC_SHA
27+
echo 'SCRAPER VERSION:' $SCRAPPER_VERSION

0 commit comments

Comments
 (0)