Skip to content

Commit 25cc341

Browse files
authored
Proxyman (#11)
* Update README.md * proxyman and proxy detection
1 parent 687c74c commit 25cc341

File tree

5 files changed

+656
-93
lines changed

5 files changed

+656
-93
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RUN apt install -y --no-install-recommends \
2323
openssh-server \
2424
zsh && rm -rf /var/lib/apt/lists/*
2525

26+
# Copy WSL related config and scripts
2627
COPY --chmod=644 --chown=root:root ./wsl-distribution.conf /etc/wsl-distribution.conf
2728
COPY --chmod=644 --chown=root:root ./wsl.conf /etc/wsl.conf
2829
COPY --chmod=755 ./oobe.sh /etc/oobe.sh
@@ -31,6 +32,9 @@ COPY ./terminal-profile.json /usr/lib/wsl/terminal-profile.json
3132

3233
COPY ./profile /etc/profile
3334

35+
# Add proxyman tool
36+
COPY --chmod=755 ./proxyman.sh /usr/local/bin/proxyman
37+
3438
RUN bash -c "echo 'port 2222' >> /etc/ssh/sshd_config"
3539

3640
# Create clab user and add to sudo group

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ We recommend using Windows Terminal for the best experience:
2626
- Double click the `.wsl` file to install.
2727
- Open 'Containerlab' from the start menu, or execute `wsl -d Containerlab`
2828
- Complete the interactive shell selection.
29+
- If you are behind a proxy, the OOBE script will let you configure it using [proxyman](https://github.com/FloSch62/proxyman).
2930
- If you have Docker Desktop installed. See [Docker Desktop](#docker-desktop).
3031
- Done! you can start labbing. (see [DevPod](#devpod) for a great way to lab).
3132

build.sh

100644100755
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
#!/bin/bash
2+
3+
# Remove the previous container if it exists
14
docker rm wsl_export
25

6+
# Build the Docker image
37
docker build . --tag ghcr.io/kaelemc/clab-wsl-debian
48

5-
mkdir /mnt/c/temp/
6-
mv /mnt/c/temp/clab.wsl /mnt/c/temp/clab.wsl.old
9+
# Check and handle /temp and /Temp paths
10+
if [ -d "/mnt/c/temp" ]; then
11+
TEMP_PATH="/mnt/c/temp"
12+
elif [ -d "/mnt/c/Temp" ]; then
13+
TEMP_PATH="/mnt/c/Temp"
14+
else
15+
echo "Error: Neither /mnt/c/temp nor /mnt/c/Temp exists."
16+
exit 1
17+
fi
18+
19+
# Rename old file if it exists
20+
if [ -f "$TEMP_PATH/clab.wsl" ]; then
21+
mv "$TEMP_PATH/clab.wsl" "$TEMP_PATH/clab.wsl.old"
22+
fi
723

24+
# Run the Docker container
825
docker run -t --name wsl_export ghcr.io/kaelemc/clab-wsl-debian ls /
926

27+
# Export the Docker container
1028
echo "Copying..."
11-
docker export wsl_export > /mnt/c/temp/clab.wsl
29+
docker export wsl_export > "$TEMP_PATH/clab.wsl"
1230

31+
# Clean up the Docker container
1332
echo "Cleaning up..."
14-
docker rm wsl_export
33+
docker rm wsl_export

oobe.sh

Lines changed: 107 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
#!/bin/bash
22

3-
set -ue
4-
53
DEFAULT_UID='1000'
64

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+
732
function setup-bash-prompt {
833
# Check if the prompt is already set up
934
if grep -q "function promptcmd" /home/clab/.bashrc; then
@@ -62,7 +87,7 @@ function install_fonts {
6287
# Convert the path to Windows format
6388
FONTS_PATH=$(wslpath -w "$TMP_DIR/FiraCodeNF")
6489

65-
# Install fonts using PowerShell directly with ExecutionPolicy set to Bypass
90+
# Install fonts using PowerShell
6691
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
6792
$fontFiles = Get-ChildItem -Path "'"$FONTS_PATH"'" -Filter "*.ttf"
6893
foreach ($fontFile in $fontFiles) {
@@ -98,7 +123,6 @@ function import_ssh_keys {
98123
mkdir -p /home/clab/.ssh
99124

100125
case $KEY_CHECK in
101-
102126
rsa*)
103127
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_rsa.pub')
104128
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
@@ -112,103 +136,97 @@ function import_ssh_keys {
112136
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
113137
;;
114138
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
116140
KEY=$(powershell.exe -NoProfile -Command 'Get-Content $env:userprofile\.ssh\id_rsa.pub')
117141
echo $KEY | sudo tee -a /home/clab/.ssh/authorized_keys > /dev/null
118142
;;
119143
*)
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"
121145
esac
122146

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"
124148
}
125149

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
128154

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
130160

131-
echo "cd ~" >> /home/clab/.bashrc
132-
133-
echo "echo clab | sudo -S mkdir -p /run/docker/netns" >> /home/clab/.bashrc
161+
PS3="
134162
135-
PS3="
136163
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="
137173
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="
147174
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
210230

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

Comments
 (0)