Skip to content

Instantly share code, notes, and snippets.

@juanvgarcia
Created November 13, 2013 03:54
Show Gist options
  • Select an option

  • Save juanvgarcia/7443442 to your computer and use it in GitHub Desktop.

Select an option

Save juanvgarcia/7443442 to your computer and use it in GitHub Desktop.

Revisions

  1. juanvgarcia created this gist Nov 13, 2013.
    31 changes: 31 additions & 0 deletions change_interfaces.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/sh
    if [ "$1" != "work" ] && [ "$1" != "home" ];
    then
    echo "Wrong arguments Usage: $0 home|work"
    exit $E_BADARGS
    fi

    interface_file='/etc/network/interfaces'

    work_config_start=`grep -n "#work config start" $interface_file | awk -F':' '{print $1}'`
    work_config_end=`grep -n "#work config end" $interface_file | awk -F':' '{print $1}'`
    home_config_start=`grep -n "#home config start" $interface_file | awk -F':' '{print $1}'`
    home_config_end=`grep -n "#home config end" $interface_file | awk -F':' '{print $1}'`

    if [ "$1" = "work" ];
    then
    start_to_comment=`expr $home_config_start + 1`
    end_to_comment=`expr $home_config_end - 1`
    start_to_uncomment=`expr $work_config_start + 1`
    end_to_uncomment=`expr $work_config_end - 1`
    else
    start_to_comment=`expr $work_config_start + 1`
    end_to_comment=`expr $work_config_end - 1`
    start_to_uncomment=`expr $home_config_start + 1`
    end_to_uncomment=`expr $home_config_end - 1`
    fi

    sed -i.bak "$start_to_comment,$end_to_comment s/^/#/g" $interface_file
    sed -i.bak "$start_to_uncomment,$end_to_uncomment s/^#//g" $interface_file

    service networking restart