Skip to content

Commit d9acaef

Browse files
committed
chore: add more debug info
1 parent 1584015 commit d9acaef

File tree

1 file changed

+137
-19
lines changed

1 file changed

+137
-19
lines changed

scripts/setup-dev-env.sh

Lines changed: 137 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ BLUE='\033[0;34m'
3939
NC='\033[0m' # No Color
4040

4141
# Configuration
42-
AUTO_MODE=false
42+
AUTO_MODE=${AUTO_MODE:-false} # Preserve environment variable if set
4343
SKIP_GO=false
4444
SKIP_DOCKER=false
4545
SKIP_PYTHON=false
@@ -49,9 +49,17 @@ SKIP_TOOLS=false
4949
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
5050
ARCH=$(uname -m)
5151

52+
# Map architecture names for different use cases
5253
case "${ARCH}" in
53-
x86_64) ARCH="amd64" ;;
54-
aarch64|arm64) ARCH="arm64" ;;
54+
x86_64)
55+
GO_ARCH="amd64" # Go uses amd64
56+
PROTOC_ARCH="x86_64" # Protocol Buffers uses x86_64
57+
;;
58+
aarch64|arm64)
59+
GO_ARCH="arm64"
60+
PROTOC_ARCH="aarch_64" # Protocol Buffers uses aarch_64
61+
ARCH="arm64" # Normalize to arm64
62+
;;
5563
*) echo -e "${RED}❌ Unsupported architecture: ${ARCH}${NC}" && exit 1 ;;
5664
esac
5765

@@ -72,6 +80,50 @@ log_error() {
7280
echo -e "${RED}$*${NC}"
7381
}
7482

83+
log_debug() {
84+
if [[ "${DEBUG:-false}" == "true" ]]; then
85+
echo -e "${BLUE}🔍 DEBUG: $*${NC}"
86+
fi
87+
}
88+
89+
# Function to verify and log download URLs
90+
verify_download_url() {
91+
local url="$1"
92+
local description="$2"
93+
94+
log_debug "Attempting to verify: $description"
95+
log_debug "URL: $url"
96+
97+
# Test URL accessibility (without downloading the full file)
98+
local http_code
99+
http_code=$(curl -f -s -I -L -w "%{http_code}" -o /dev/null "$url" 2>/dev/null)
100+
local curl_exit_code=$?
101+
102+
if [[ $curl_exit_code -ne 0 || "$http_code" != "200" ]]; then
103+
log_error "Failed to access URL for $description"
104+
log_error "URL: $url"
105+
log_error "HTTP status code: ${http_code:-unknown}"
106+
log_error "curl exit code: $curl_exit_code"
107+
108+
# Provide helpful suggestions based on the error
109+
if [[ "$http_code" == "404" ]]; then
110+
log_error "File not found (404). The version or architecture might not be available."
111+
log_error "Suggestion: Check if the version exists in the GitHub releases page"
112+
elif [[ "$http_code" == "403" ]]; then
113+
log_error "Access forbidden (403). This might be a rate limit or authentication issue."
114+
elif [[ $curl_exit_code -eq 6 ]]; then
115+
log_error "Could not resolve host. Check your internet connection."
116+
elif [[ $curl_exit_code -eq 7 ]]; then
117+
log_error "Failed to connect to host. Check your internet connection and firewall."
118+
fi
119+
120+
return 1
121+
fi
122+
123+
log_debug "URL verified successfully for $description (HTTP $http_code)"
124+
return 0
125+
}
126+
75127
command_exists() {
76128
command -v "$1" >/dev/null 2>&1
77129
}
@@ -105,6 +157,10 @@ OPTIONS:
105157
--skip-tools Skip development tools installation
106158
--help Show this help message
107159
160+
ENVIRONMENT VARIABLES:
161+
AUTO_MODE=true Same as --auto flag (non-interactive mode)
162+
DEBUG=true Enable debug output (shows URLs, architecture mappings, etc.)
163+
108164
EXAMPLES:
109165
# Interactive mode
110166
$0
@@ -115,6 +171,12 @@ EXAMPLES:
115171
# Install only tools (Go already installed)
116172
$0 --skip-go --skip-docker
117173
174+
# Enable debug output to troubleshoot download issues
175+
DEBUG=true $0
176+
177+
# Automated setup with debug output
178+
AUTO_MODE=true DEBUG=true $0
179+
118180
EOF
119181
}
120182

@@ -156,10 +218,14 @@ done
156218
# Banner
157219
echo ""
158220
echo "╔════════════════════════════════════════════════════════╗"
159-
echo "║ NVSentinel Development Environment Setup ║"
221+
echo "║ NVSentinel Development Environment Setup "
160222
echo "╚════════════════════════════════════════════════════════╝"
161223
echo ""
162-
log_info "Platform: ${OS}-${ARCH}"
224+
log_info "Platform: ${OS}-${GO_ARCH}"
225+
log_debug "Architecture mappings:"
226+
log_debug " Raw ARCH: ${ARCH}"
227+
log_debug " GO_ARCH (for Go tools, yq, kubectl): ${GO_ARCH}"
228+
log_debug " PROTOC_ARCH (for Protocol Buffers): ${PROTOC_ARCH}"
163229
echo ""
164230

165231
# Check if .versions.yaml exists
@@ -181,8 +247,18 @@ if ! command_exists yq; then
181247
exit 1
182248
fi
183249
elif [[ "${OS}" == "linux" ]]; then
184-
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_"${ARCH}"
185-
sudo chmod +x /usr/local/bin/yq
250+
YQ_URL="https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${GO_ARCH}"
251+
log_debug "Architecture mapping: ${ARCH} -> GO_ARCH=${GO_ARCH}"
252+
253+
if verify_download_url "$YQ_URL" "yq for Linux ${GO_ARCH}"; then
254+
log_debug "Downloading yq from: $YQ_URL"
255+
sudo wget -qO /usr/local/bin/yq "$YQ_URL"
256+
sudo chmod +x /usr/local/bin/yq
257+
log_debug "yq installed successfully to /usr/local/bin/yq"
258+
else
259+
log_error "Failed to install yq. Please install manually or check your architecture."
260+
exit 1
261+
fi
186262
fi
187263

188264
log_success "yq installed"
@@ -364,9 +440,22 @@ if [[ "${SKIP_TOOLS}" == "false" ]]; then
364440
if [[ "${OS}" == "darwin" ]]; then
365441
brew install kubectl
366442
elif [[ "${OS}" == "linux" ]]; then
443+
log_debug "Fetching latest kubectl version..."
367444
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
368-
sudo curl -L "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl" -o /usr/local/bin/kubectl
369-
sudo chmod +x /usr/local/bin/kubectl
445+
KUBECTL_URL="https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${GO_ARCH}/kubectl"
446+
447+
log_debug "kubectl version: ${KUBECTL_VERSION}"
448+
log_debug "Architecture mapping: ${ARCH} -> GO_ARCH=${GO_ARCH}"
449+
450+
if verify_download_url "$KUBECTL_URL" "kubectl ${KUBECTL_VERSION} for Linux ${GO_ARCH}"; then
451+
log_debug "Downloading kubectl from: $KUBECTL_URL"
452+
sudo curl -L "$KUBECTL_URL" -o /usr/local/bin/kubectl
453+
sudo chmod +x /usr/local/bin/kubectl
454+
log_debug "kubectl installed successfully to /usr/local/bin/kubectl"
455+
else
456+
log_error "Failed to install kubectl. Please install manually or check your architecture."
457+
exit 1
458+
fi
370459
fi
371460
log_success "kubectl installed"
372461
fi
@@ -383,12 +472,24 @@ if [[ "${SKIP_TOOLS}" == "false" ]]; then
383472
if [[ "${OS}" == "darwin" ]]; then
384473
PROTOC_ZIP="protoc-${PROTOBUF_VERSION_NUM}-osx-universal_binary.zip"
385474
elif [[ "${OS}" == "linux" ]]; then
386-
PROTOC_ZIP="protoc-${PROTOBUF_VERSION_NUM}-linux-${ARCH}.zip"
475+
PROTOC_ZIP="protoc-${PROTOBUF_VERSION_NUM}-linux-${PROTOC_ARCH}.zip"
387476
fi
388477

389-
TMP_DIR=$(mktemp -d)
390-
cd "${TMP_DIR}"
391-
wget -q "https://github.com/protocolbuffers/protobuf/releases/download/${PROTOBUF_VERSION}/${PROTOC_ZIP}"
478+
PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/${PROTOBUF_VERSION}/${PROTOC_ZIP}"
479+
480+
log_debug "protobuf version: ${PROTOBUF_VERSION} (${PROTOBUF_VERSION_NUM})"
481+
log_debug "Architecture mapping: ${ARCH} -> PROTOC_ARCH=${PROTOC_ARCH}"
482+
log_debug "Expected file: ${PROTOC_ZIP}"
483+
484+
if verify_download_url "$PROTOC_URL" "protoc ${PROTOBUF_VERSION} for ${OS} ${PROTOC_ARCH}"; then
485+
TMP_DIR=$(mktemp -d)
486+
cd "${TMP_DIR}"
487+
log_debug "Downloading protoc from: $PROTOC_URL"
488+
wget -q "$PROTOC_URL"
489+
else
490+
log_error "Failed to download protoc. Please check the version and architecture."
491+
exit 1
492+
fi
392493
unzip -q "${PROTOC_ZIP}"
393494
sudo cp bin/protoc /usr/local/bin/
394495
sudo mkdir -p /usr/local/include
@@ -406,16 +507,33 @@ if [[ "${SKIP_TOOLS}" == "false" ]]; then
406507
else
407508
log_info "Installing shellcheck ${SHELLCHECK_VERSION}..."
408509
if prompt_continue; then
409-
SHELLCHECK_VERSION_NUM=${SHELLCHECK_VERSION#v}
410-
411510
if [[ "${OS}" == "darwin" ]]; then
412511
brew install shellcheck
413512
elif [[ "${OS}" == "linux" ]]; then
414513
TMP_DIR=$(mktemp -d)
415514
cd "${TMP_DIR}"
416-
wget -q "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION_NUM}.linux.${ARCH}.tar.xz"
417-
tar -xJ -f "shellcheck-${SHELLCHECK_VERSION_NUM}.linux.${ARCH}.tar.xz"
418-
sudo cp "shellcheck-${SHELLCHECK_VERSION_NUM}/shellcheck" /usr/local/bin/
515+
# Shellcheck uses x86_64 for amd64 and aarch64 for arm64
516+
SHELLCHECK_ARCH=${PROTOC_ARCH}
517+
if [[ "${ARCH}" == "arm64" ]]; then
518+
SHELLCHECK_ARCH="aarch64"
519+
fi
520+
521+
SHELLCHECK_FILE="shellcheck-${SHELLCHECK_VERSION}.linux.${SHELLCHECK_ARCH}.tar.xz"
522+
SHELLCHECK_URL="https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/${SHELLCHECK_FILE}"
523+
524+
log_debug "shellcheck version: ${SHELLCHECK_VERSION}"
525+
log_debug "Architecture mapping: ${ARCH} -> PROTOC_ARCH=${PROTOC_ARCH} -> SHELLCHECK_ARCH=${SHELLCHECK_ARCH}"
526+
log_debug "Expected file: ${SHELLCHECK_FILE}"
527+
528+
if verify_download_url "$SHELLCHECK_URL" "shellcheck ${SHELLCHECK_VERSION} for Linux ${SHELLCHECK_ARCH}"; then
529+
log_debug "Downloading shellcheck from: $SHELLCHECK_URL"
530+
wget -q "$SHELLCHECK_URL"
531+
else
532+
log_error "Failed to download shellcheck. Please check the version and architecture."
533+
exit 1
534+
fi
535+
tar -xJ -f "shellcheck-${SHELLCHECK_VERSION}.linux.${SHELLCHECK_ARCH}.tar.xz"
536+
sudo cp "shellcheck-${SHELLCHECK_VERSION}/shellcheck" /usr/local/bin/
419537
sudo chmod +x /usr/local/bin/shellcheck
420538
cd - >/dev/null
421539
rm -rf "${TMP_DIR}"
@@ -514,7 +632,7 @@ if [[ "${SKIP_PYTHON}" == "false" ]] && command_exists python3; then
514632
log_info "Python gRPC Tools"
515633
echo "════════════════════════════════════════════════════════"
516634

517-
log_info "Installing Python gRPC tools (grpcio, grpcio-tools)..."
635+
log_info "Installing Python gRPC tools: grpcio, grpcio-tools..."
518636

519637
if prompt_continue; then
520638
if [[ "${OS}" == "darwin" ]]; then

0 commit comments

Comments
 (0)