-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREMOTE_ZSH_TEST_SCRIPT.sh
More file actions
executable file
·245 lines (218 loc) · 7.45 KB
/
REMOTE_ZSH_TEST_SCRIPT.sh
File metadata and controls
executable file
·245 lines (218 loc) · 7.45 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
# Non-intrusive Zsh Compatibility Test Script
# Run this on the zsh server: 173.237.68.204
# This script does NOT modify any files - it only tests detection and syntax
set -euo pipefail
echo "======================================================================"
echo " ZSH COMPATIBILITY TEST - NON-INTRUSIVE"
echo "======================================================================"
echo ""
# Test 1: Shell Detection
echo "=== Test 1: Shell Environment Detection ==="
echo "Current shell process:"
ps -p $$ -o comm=
echo ""
echo "Default shell from user database:"
getent passwd "$USER" | cut -d: -f7
echo ""
echo "SHELL environment variable:"
echo "$SHELL"
echo ""
echo "Available shells on system:"
cat /etc/shells
echo ""
# Test 2: Shell Detection Logic (from our script)
echo "=== Test 2: Our Shell Detection Function ==="
detect_user_shell() {
local user_shell
local shell_basename
# Try to get shell from user database first
user_shell=$(getent passwd "$USER" 2>/dev/null | cut -d: -f7)
# Fallback to SHELL environment variable
if [ -z "$user_shell" ] || [ "$user_shell" = "/sbin/nologin" ]; then
user_shell="${SHELL:-/bin/bash}"
fi
# Extract basename and determine type
shell_basename=$(basename "$user_shell")
case "$shell_basename" in
zsh)
echo "zsh"
;;
bash)
echo "bash"
;;
*)
# Default to bash for unknown shells
echo "bash"
;;
esac
}
DETECTED_SHELL=$(detect_user_shell)
echo "Detected shell type: $DETECTED_SHELL"
if [ "$DETECTED_SHELL" = "zsh" ]; then
echo "✓ PASS: Correctly detected zsh"
else
echo "✗ FAIL: Expected zsh, got $DETECTED_SHELL"
fi
echo ""
# Test 3: RC File Selection (with smart detection)
echo "=== Test 3: RC File Selection (Smart Detection) ==="
get_rc_file_for_shell() {
local shell_type="$1"
case "$shell_type" in
zsh)
# Smart detection for zsh: prefer .zshenv if it has PATH configs
if [ -f "$HOME/.zshenv" ] && grep -q "PATH" "$HOME/.zshenv" 2>/dev/null; then
echo "$HOME/.zshenv"
else
echo "$HOME/.zshrc"
fi
;;
bash|*)
echo "$HOME/.bashrc"
;;
esac
}
# Check what exists
if [ -f "$HOME/.zshenv" ]; then
echo "Found .zshenv:"
if grep -q "PATH" "$HOME/.zshenv" 2>/dev/null; then
echo " ✓ Contains PATH configurations"
else
echo " ⊘ No PATH configurations"
fi
fi
RC_FILE=$(get_rc_file_for_shell "$DETECTED_SHELL")
echo "Selected RC file: $RC_FILE"
if [ "$DETECTED_SHELL" = "zsh" ]; then
if [ -f "$HOME/.zshenv" ] && grep -q "PATH" "$HOME/.zshenv" 2>/dev/null; then
[ "$RC_FILE" = "$HOME/.zshenv" ] && echo "✓ PASS: Correctly selected .zshenv (has PATH configs)" || echo "✗ FAIL: Should have selected .zshenv"
else
[ "$RC_FILE" = "$HOME/.zshrc" ] && echo "✓ PASS: Correctly selected .zshrc (no .zshenv PATH)" || echo "✗ FAIL: Should have selected .zshrc"
fi
elif [ "$DETECTED_SHELL" = "bash" ] && [ "$RC_FILE" = "$HOME/.bashrc" ]; then
echo "✓ PASS: Correctly selected .bashrc for bash"
else
echo "✗ FAIL: RC file selection mismatch"
fi
echo ""
# Test 4: Check if RC file exists
echo "=== Test 4: RC File Existence ==="
if [ -f "$RC_FILE" ]; then
echo "✓ RC file exists: $RC_FILE"
echo " Size: $(stat -f%z "$RC_FILE" 2>/dev/null || stat -c%s "$RC_FILE" 2>/dev/null) bytes"
echo " Permissions: $(ls -l "$RC_FILE" | awk '{print $1}')"
else
echo "⚠ RC file does not exist: $RC_FILE"
echo " (Script would create it)"
fi
echo ""
# Test 5: PATH Export Syntax Test
echo "=== Test 5: PATH Export Syntax Compatibility ==="
TEST_PATH_LINE='export PATH="/test/path/active_release:$PATH"'
echo "Test line: $TEST_PATH_LINE"
# Test with current shell
if eval "$TEST_PATH_LINE" 2>/dev/null && echo "$PATH" | grep -q "/test/path/active_release"; then
echo "✓ PASS: Current shell can parse PATH export syntax"
else
echo "✗ FAIL: Current shell cannot parse PATH export syntax"
fi
echo ""
# Test 6: Array Operations (compatible syntax)
echo "=== Test 6: Array Operations Compatibility ==="
test_array=("item1" "item2" "item3")
echo "Test array: ${test_array[@]}"
echo "Array length: ${#test_array[@]}"
if [ "${#test_array[@]}" -eq 3 ]; then
echo "✓ PASS: Array operations work correctly"
else
echo "✗ FAIL: Array operations failed"
fi
echo ""
# Test 7: String Operations
echo "=== Test 7: String Operations Compatibility ==="
test_string="HELLO"
lower_string="${test_string,,}"
if [ "$lower_string" = "hello" ]; then
echo "✓ PASS: String lowercase operation works"
else
echo "⚠ WARNING: String lowercase operation may not work (bash 4+ feature)"
fi
echo ""
# Test 8: Check for existing PATH configurations
echo "=== Test 8: Existing PATH Configurations ==="
if [ -f "$RC_FILE" ]; then
echo "Checking for existing 'active_release' PATH entries in $RC_FILE:"
if grep -q "active_release" "$RC_FILE"; then
echo "Found existing entries:"
grep "active_release" "$RC_FILE" | head -5
else
echo "✓ No existing 'active_release' entries found"
fi
else
echo "⊘ RC file doesn't exist yet"
fi
echo ""
# Test 9: Check for Rust/Cargo installation
echo "=== Test 9: Rust/Cargo Environment ==="
if [ -f "$HOME/.cargo/env" ]; then
echo "✓ Cargo env file exists: $HOME/.cargo/env"
if command -v cargo &> /dev/null; then
echo "✓ Cargo is in PATH: $(which cargo)"
echo " Version: $(cargo --version)"
else
echo "⚠ Cargo env file exists but cargo not in PATH"
fi
else
echo "⊘ Cargo env file doesn't exist (Rust not installed)"
fi
if [ -f "$RC_FILE" ] && grep -q "source.*cargo/env" "$RC_FILE"; then
echo "✓ Cargo env is sourced in $RC_FILE"
else
echo "⊘ Cargo env is not sourced in RC file"
fi
echo ""
# Test 10: Symlink Operations
echo "=== Test 10: Symlink Operations Test ==="
TEST_DIR="/tmp/zsh_test_$$"
mkdir -p "$TEST_DIR/test_bin"
ln -sf "$TEST_DIR/test_bin" "$TEST_DIR/test_link"
if [ -L "$TEST_DIR/test_link" ]; then
TARGET=$(readlink -f "$TEST_DIR/test_link")
echo "✓ PASS: Symlink creation and readlink work correctly"
echo " Link: $TEST_DIR/test_link -> $TARGET"
else
echo "✗ FAIL: Symlink operations failed"
fi
# Cleanup
rm -rf "$TEST_DIR"
echo ""
# Test 11: Command Substitution
echo "=== Test 11: Command Substitution ==="
WHOAMI_RESULT=$(whoami)
if [ "$WHOAMI_RESULT" = "$USER" ]; then
echo "✓ PASS: Command substitution works correctly"
else
echo "✗ FAIL: Command substitution issue"
fi
echo ""
# Summary
echo "======================================================================"
echo " TEST SUMMARY"
echo "======================================================================"
echo ""
echo "Detected Shell: $DETECTED_SHELL"
echo "RC File: $RC_FILE"
echo "RC File Exists: $([ -f "$RC_FILE" ] && echo "Yes" || echo "No")"
echo ""
echo "✓ All core compatibility features tested"
echo "✓ No files were modified during testing"
echo "✓ Safe to proceed with actual implementation"
echo ""
echo "Next Steps:"
echo " 1. Review the output above"
echo " 2. Verify shell detection is correct"
echo " 3. If all tests pass, the scripts will work on this system"
echo " 4. Run system_tuner.sh to configure the system (will modify RC file)"
echo ""
echo "======================================================================"