Skip to content

Instantly share code, notes, and snippets.

@y0n1
Last active September 9, 2021 21:07
Show Gist options
  • Save y0n1/1914c22e63eb67f72ba07dbe0ddde9f1 to your computer and use it in GitHub Desktop.
Save y0n1/1914c22e63eb67f72ba07dbe0ddde9f1 to your computer and use it in GitHub Desktop.
A NetworkManager script for toggling repositories state after connecting or disconnecting from a VPN
#!/bin/bash
# Instructions:
# Place this file inside /etc/NetworkManager/dispatcher.d/
# sudo chown root:root 00_toggle-repo.sh
# sudo chmod +x 00_toggle-repo.sh
repos="rhel8-csb"
case "${NM_DISPATCHER_ACTION}" in
"vpn-up")
[[ "$(dnf repolist $repo)" =~ disabled ]] && \
dnf config-manager --set-enabled $repo
;;
"vpn-down")
[[ "$(dnf repolist $repo)" =~ enabled ]] && \
dnf config-manager --set-disabled $repo
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment