-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprepare-hosts
25 lines (25 loc) · 917 Bytes
/
prepare-hosts
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
#!/bin/sh
export WINIP=$(cat /etc/resolv.conf | grep 'nameserver' | cut -f 2 -d ' ')
export WSLIP=$(ip addr show eth0 | grep 'inet ' | cut -f 6 -d ' ' | cut -f 1 -d '/')
echo $WINIP
echo $WSLIP
rm /tmp/hosts
if grep "wsl2" /mnt/c/Windows/System32/drivers/etc/hosts
then
cp /mnt/c/Windows/System32/drivers/etc/hosts /tmp/hosts
sed -i "s/.*wsl2/$WSLIP wsl2/" /tmp/hosts
cat /tmp/hosts > /mnt/c/Windows/System32/drivers/etc/hosts
else
echo "$WSLIP wsl2\n" >> /mnt/c/Windows/System32/drivers/etc/hosts
fi
rm /tmp/hosts
if grep "winhost" /mnt/c/Windows/System32/drivers/etc/hosts
then
cp /mnt/c/Windows/System32/drivers/etc/hosts /tmp/hosts
sed -i "s/.*winhost/$WINIP winhost/" /tmp/hosts
cat /tmp/hosts > /mnt/c/Windows/System32/drivers/etc/hosts
else
echo "$WINIP winhost\n" >> /mnt/c/Windows/System32/drivers/etc/hosts
fi
cat /mnt/c/Windows/System32/drivers/etc/hosts
echo "DONE!\n"