Skip to content

Instantly share code, notes, and snippets.

@monokrome
Created January 24, 2018 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokrome/4caf27a2d3a47b3dcfae26d6ca8d8491 to your computer and use it in GitHub Desktop.
Save monokrome/4caf27a2d3a47b3dcfae26d6ca8d8491 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Rename this to `$vpn_state` to be more semantically useful. `$script_type` is
# a really weird name.
vpn_state=$script_type
case $vpn_state in
up)
nameservers=()
search=()
# Loop through every variable name w/ that matches foreign_option_*
for option in ${!foreign_option_*}; do
# Get value of our option as an array
values=(${!option})
[[ ${values[0]} != 'dhcp-option' ]] && continue
[[ ${values[1]} == 'DNS' ]] && nameservers+=(${values[2]})
[[ ${values[2]} = DOMAIN* ]] && search+=(${values[2]})
for nameserver in $nameservers; do
printf 'nameserver %s\n' $nameserver | resolvconf -a $dev
done
for domain in $search; do
printf 'search %s\n' $domain | resolvconf -a $dev
done
done
;;
down)
resolvconf -d $dev
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment