Last active
July 7, 2022 08:58
-
-
Save pgampe/d202a71934dcc78269b0aa109f50c887 to your computer and use it in GitHub Desktop.
Reset WSL to environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# saner programming env: these switches turn some bugs into errors | |
set -o errexit -o pipefail -o noclobber -o nounset | |
# shellcheck disable=SC2043 | |
for cmd in sudo hwclock sysctl tee grep awk tr powershell.exe; do | |
if ! command -v "${cmd}" &>/dev/null; then | |
echo "${cmd} could not be found" | |
exit 1 | |
fi | |
done | |
echo "This requires root!!!" | |
echo "Resetting time to system clock" | |
sudo hwclock -s | |
echo "Makeing sure sysctl settings are applied" | |
sudo sysctl -f --system --quiet > /dev/null | |
echo "Fixing DNS problems in WLS by adding external DNS in /etc/resolv.conf" | |
# Filter out vEthernet, because it has a lower metric than the actual connection | |
DEVICEALIAS=$(powershell.exe 'Get-NetIPInterface -ConnectionState Connected|Sort-Object -Property InterfaceMetric|Where-Object -Property InterfaceAlias -NotLike "vEthernet*"|Select-Object -Unique InterfaceAlias -First 1 -ExpandProperty InterfaceAlias') | |
DNSRESOLVER=$(powershell.exe "Get-DnsClientServerAddress -InterfaceAlias ${DEVICEALIAS}" | grep IPv4 | awk '{print $4}' | tr -d '{},' ) | |
echo "nameserver $DNSRESOLVER" |sudo tee -a /etc/resolv.conf | |
echo "Resetting sudo" | |
sudo -K | |
echo "Good to go ... have fun" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment