1
1
#! /bin/bash
2
2
3
- set -ue
4
-
5
3
DEFAULT_UID=' 1000'
6
4
5
+ function prompt_proxy {
6
+ read -p " Are you behind a proxy that you want to configure now? (y/N) " -n 1 -r
7
+ echo
8
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
9
+ echo -e " \nPlease provide your HTTP_PROXY URL (e.g. http://proxy.example.com:8080):"
10
+ read -r HTTP_PROXY
11
+ echo -e " \nPlease provide your HTTPS_PROXY URL (often the same as HTTP_PROXY):"
12
+ read -r HTTPS_PROXY
13
+ echo -e " \nPlease provide your NO_PROXY list (default: localhost,127.0.0.1,::1):"
14
+ read -r NO_PROXY
15
+ [ -z " $NO_PROXY " ] && NO_PROXY=" localhost,127.0.0.1,::1"
16
+
17
+ echo -e " \nWriting proxy configuration to /etc/proxy.conf..."
18
+ echo " HTTP_PROXY=$HTTP_PROXY " | sudo tee /etc/proxy.conf > /dev/null
19
+ echo " HTTPS_PROXY=$HTTPS_PROXY " | sudo tee -a /etc/proxy.conf > /dev/null
20
+ echo " NO_PROXY=$NO_PROXY " | sudo tee -a /etc/proxy.conf > /dev/null
21
+
22
+ echo -e " \nConfiguring system-wide proxy using proxyman..."
23
+ SUDO_USER=clab SUDO_UID=1000 SUDO_GID=1000 sudo proxyman set > /dev/null 2>&1
24
+ echo -e " \nProxy has been set. You can run 'sudo proxyman unset' to remove it."
25
+ eval " $( sudo /usr/local/bin/proxyman export) "
26
+ echo -e " \n\033[32mWelcome to Containerlab's WSL distribution\033[0m"
27
+ else
28
+ echo -e " \nSkipping proxy configuration.\n"
29
+ fi
30
+ }
31
+
7
32
function setup-bash-prompt {
8
33
# Check if the prompt is already set up
9
34
if grep -q " function promptcmd" /home/clab/.bashrc; then
@@ -62,7 +87,7 @@ function install_fonts {
62
87
# Convert the path to Windows format
63
88
FONTS_PATH=$( wslpath -w " $TMP_DIR /FiraCodeNF" )
64
89
65
- # Install fonts using PowerShell directly with ExecutionPolicy set to Bypass
90
+ # Install fonts using PowerShell
66
91
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
67
92
$fontFiles = Get-ChildItem -Path "' " $FONTS_PATH " ' " -Filter "*.ttf"
68
93
foreach ($fontFile in $fontFiles) {
@@ -98,7 +123,6 @@ function import_ssh_keys {
98
123
mkdir -p /home/clab/.ssh
99
124
100
125
case $KEY_CHECK in
101
-
102
126
rsa* )
103
127
KEY=$( powershell.exe -NoProfile -Command ' Get-Content $env:userprofile\.ssh\id_rsa.pub' )
104
128
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
@@ -112,103 +136,97 @@ function import_ssh_keys {
112
136
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
113
137
;;
114
138
False* )
115
- powershell.exe -NoProfile -Command " ssh-keygen -t rsa -b 4096 -f \$ env:userprofile\.ssh\id_rsa -N '\"\" '" > /dev/null 2>&1
139
+ powershell.exe -NoProfile -Command " ssh-keygen -t rsa -b 4096 -f \$ env:userprofile\.ssh\id_rsa -N ''" > /dev/null 2>&1
116
140
KEY=$( powershell.exe -NoProfile -Command ' Get-Content $env:userprofile\.ssh\id_rsa.pub' )
117
141
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
118
142
;;
119
143
* )
120
- echo " \033[34m\nSSH: Couldn't match key type, invoking Powershell may have failed. Create an issue at https://github.com/srl-labs/wsl-containerlab \033[0m"
144
+ echo " \033[34m\nSSH: Couldn't detect key type, please create a key manually or check PowerShell invocation. \033[0m"
121
145
esac
122
146
123
- echo -e " \033[32mSSH keys successfully copied. You can SSH into Container WSL passwordless with: 'ssh clab@localhost -p 2222'. (Ensure Containerlab WSL is open)\033[0m"
147
+ echo -e " \033[32mSSH keys successfully copied. You can SSH into Container WSL passwordless with: 'ssh clab@localhost -p 2222' (Ensure Containerlab WSL is open)\033[0m"
124
148
}
125
149
126
- # We know the user clab exists from Dockerfile with UID 1000
127
- if getent passwd " $DEFAULT_UID " > /dev/null ; then
150
+ # Start OOBE logic
151
+ echo -e " \033[32mWelcome to Containerlab's WSL distribution\033[0m"
152
+ echo " cd ~" >> /home/clab/.bashrc
153
+ echo " echo clab | sudo -S mkdir -p /run/docker/netns" >> /home/clab/.bashrc
128
154
129
- echo -e " \033[32mWelcome to Containerlab's WSL distribution\033[0m"
155
+ # Check connectivity before anything else
156
+ if ! curl -fsSL --connect-timeout 5 https://www.google.com -o /dev/null; then
157
+ echo -e " \nIt seems we couldn't connect to the internet directly. You might be behind a proxy."
158
+ prompt_proxy
159
+ fi
130
160
131
- echo " cd ~" >> /home/clab/.bashrc
132
-
133
- echo " echo clab | sudo -S mkdir -p /run/docker/netns" >> /home/clab/.bashrc
161
+ PS3="
134
162
135
- PS3="
136
163
Please select which shell you'd like to use: "
164
+ shell_opts=(" zsh" " bash with two-line prompt" " bash (default WSL prompt)" )
165
+ select shell in " ${shell_opts[@]} "
166
+ do
167
+ case $shell in
168
+ " zsh" )
169
+ echo -e " \033[34m\nzsh selected\033[0m"
170
+ echo -e " \033[33mNote: zsh with custom theme requires Nerd Font for proper symbol display.\033[0m"
171
+
172
+ PS3="
137
173
138
- shell_opts=(" zsh" " bash with two-line prompt" " bash (default WSL prompt)" )
139
- select shell in " ${shell_opts[@]} "
140
- do
141
- case $shell in
142
- " zsh" )
143
- echo -e " \033[34m\nzsh selected\033[0m"
144
- echo -e " \033[33mNote: zsh with custom theme requires Nerd Font for proper symbol display\033[0m"
145
-
146
- PS3="
147
174
Select zsh configuration: "
148
- zsh_opts=(" Full featured (many plugins)" " Lean version (minimal plugins)" )
149
- select zsh_config in " ${zsh_opts[@]} "
150
- do
151
- case $zsh_config in
152
- " Full featured (many plugins)" )
153
- echo -e " \033[34m\nConfiguring full featured zsh\033[0m"
154
- read -p " Would you like to install FiraCode Nerd Font? (y/N) " -n 1 -r
155
- echo
156
- if [[ $REPLY =~ ^[Yy]$ ]]; then
157
- install_fonts
158
- fi
159
- # Use default .zshrc and .p10k.zsh
160
- sudo -u clab cp /home/clab/.zshrc{,.bak}
161
- sudo -u clab cp /home/clab/.p10k.zsh{,.bak}
162
- break 2
163
- ;;
164
- " Lean version (minimal plugins)" )
165
- echo -e " \033[34m\nConfiguring lean zsh\033[0m"
166
- read -p " Would you like to install FiraCode Nerd Font? (y/N) " -n 1 -r
167
- echo
168
- if [[ $REPLY =~ ^[Yy]$ ]]; then
169
- install_fonts
170
- fi
171
- # Use lean versions
172
- sudo -u clab cp /home/clab/.zshrc{,.bak}
173
- sudo -u clab cp /home/clab/.p10k.zsh{,.bak}
174
- sudo -u clab cp /home/clab/.zshrc-lean /home/clab/.zshrc
175
- sudo -u clab cp /home/clab/.p10k-lean.zsh /home/clab/.p10k.zsh
176
- break 2
177
- ;;
178
- * ) echo -e " \033[31m\n'$REPLY ' is not a valid choice\033[0m" ;;
179
- esac
180
- done
181
- sudo chsh -s " $( which zsh) " clab
182
- break
183
- ;;
184
- " bash with two-line prompt" )
185
- echo -e " \033[34m\nbash with two-line prompt selected. Configuring two-line prompt\033[0m"
186
- read -p " Would you like to install FiraCode Nerd Font? (y/N) " -n 1 -r
187
- echo
188
- if [[ $REPLY =~ ^[Yy]$ ]]; then
189
- install_fonts
190
- fi
191
- # Backup .bashrc
192
- sudo -u clab cp /home/clab/.bashrc /home/clab/.bashrc.bak
193
- sudo chsh -s " $( which bash) " clab
194
- setup-bash-prompt
195
- break
196
- ;;
197
- " bash (default WSL prompt)" )
198
- echo -e " \033[34m\nbash selected\033[0m"
199
- sudo chsh -s " $( which bash) " clab
200
- break
201
- ;;
202
- * ) echo -e " \033[31m\n'$REPLY ' is not a valid choice\033[0m" ;;
203
- esac
204
- done
205
-
206
- import_ssh_keys
207
-
208
- exit 0
209
- fi
175
+ zsh_opts=(" Full featured (many plugins)" " Lean version (minimal plugins)" )
176
+ select zsh_config in " ${zsh_opts[@]} "
177
+ do
178
+ case $zsh_config in
179
+ " Full featured (many plugins)" )
180
+ echo -e " \033[34m\nConfiguring full featured zsh\033[0m"
181
+ read -p " Would you like to install FiraCode Nerd Font? (y/N) " -n 1 -r
182
+ echo
183
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
184
+ install_fonts
185
+ fi
186
+ sudo -u clab cp /home/clab/.zshrc{,.bak}
187
+ sudo -u clab cp /home/clab/.p10k.zsh{,.bak}
188
+ break 2
189
+ ;;
190
+ " Lean version (minimal plugins)" )
191
+ echo -e " \033[34m\nConfiguring lean zsh\033[0m"
192
+ read -p " Would you like to install FiraCode Nerd Font? (y/N) " -n 1 -r
193
+ echo
194
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
195
+ install_fonts
196
+ fi
197
+ sudo -u clab cp /home/clab/.zshrc{,.bak}
198
+ sudo -u clab cp /home/clab/.p10k.zsh{,.bak}
199
+ sudo -u clab cp /home/clab/.zshrc-lean /home/clab/.zshrc
200
+ sudo -u clab cp /home/clab/.p10k-lean.zsh /home/clab/.p10k.zsh
201
+ break 2
202
+ ;;
203
+ * ) echo -e " \033[31m\n'$REPLY ' is not a valid choice\033[0m" ;;
204
+ esac
205
+ done
206
+ sudo chsh -s " $( which zsh) " clab
207
+ break
208
+ ;;
209
+ " bash with two-line prompt" )
210
+ echo -e " \033[34m\nbash with two-line prompt selected.\033[0m"
211
+ read -p " Would you like to install FiraCode Nerd Font? (y/N) " -n 1 -r
212
+ echo
213
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
214
+ install_fonts
215
+ fi
216
+ # Backup .bashrc
217
+ sudo -u clab cp /home/clab/.bashrc /home/clab/.bashrc.bak
218
+ sudo chsh -s " $( which bash) " clab
219
+ setup-bash-prompt
220
+ break
221
+ ;;
222
+ " bash (default WSL prompt)" )
223
+ echo -e " \033[34m\nbash selected\033[0m"
224
+ sudo chsh -s " $( which bash) " clab
225
+ break
226
+ ;;
227
+ * ) echo -e " \033[31m\n'$REPLY ' is not a valid choice\033[0m" ;;
228
+ esac
229
+ done
210
230
211
- # This part will (should) never be reached since clab user exists,
212
- # but keeping it as a fallback
213
- echo ' No user account detected, Something may be wrong with your installation. Create an issue at <githubIssueLink>'
214
- exit 1
231
+ import_ssh_keys
232
+ exit 0
0 commit comments