www.freniche.com

Linux, Computers and other stuff

¡ESTE SITIO WEB YA NO ESTA ACTUALIZADO!

Los últimos posts están en http:/blog.freniche.com/

Por favor, actualiza tus enlaces y perdona las molestias.

 »www.freniche.com »Proyectos »Scripts »Set-interface.sh

Instrucciones de instalación

Recuerda que antes de utilizar cualquier script que te bajes de Internet debes hacer varias cosas:

1. Leertelo bien para comprobar que no hace cosas raras ni es dañino (en mi caso te puedes fiar de mi palabra :-) )

2. Activar los permisos de ejecución mediante un chmod a+x script.sh

3. Cambiar a root, si el script así lo necesita (en este caso, si vas a copiar /etc por ejemplo SI lo necesitas)

4. Ejecutarlo mediante ./backup-system.sh

5. Enviarme un correo si encuentras problemas o quieres enviarme dinero que te sobre.

Set-Interface

Este script lo utilizo para disponer de diferentes configuraciones de red en mi portátil y seleccionarlas de forma sencilla (al menos para mi).

 

El código:

#!/bin/bash

# set-interface.sh: sets a link to a desired /etc/network/interfaces* file

# Just copy the original /etc/network/interfaces to interfaces<whatever>

# and run this script (as root) to change your current networking config.

# You can have several interfaces.* files and switch easily

# (c-left) Diego Freniche 2004-2005 [ www.freniche.com for more ]

 

# change for non-Debians

ETCNETWORKDIR=/etc/network

# a command to be launched after net reconfiguring is done

POSTCOMMAND="/etc/init.d/firestarter restart"

 

check_root() {

USUARIO=`whoami`

if [ $USUARIO = 'root' ]

then

return 0

else

return 1

fi

}

 

if check_root ;then

RESULTADO=`ls /etc/network/interfaces?* | sed -e '/~$/d' | zenity --width=350 --height=450 --list --column=Config --text="Escoja una config."`

if [ "$RESULTADO" == "" ]; then

exit 0

fi

cat $RESULTADO | zenity --text-info

zenity --question --text "Aceptar"

# echo $?

 

if [ $? -eq 0 ]; then

# link /etc/network/interfaces to the actual file

ln -sf $RESULTADO $ETCNETWORKDIR/interfaces

# now, we change the file name "/etc/network/interfaces.*" to "/etc/resolv.conf.*"

# using sed's substitution (s/src/dst/)

SRC_LINK=`echo $RESULTADO | sed -e 's/\/etc\/network\/interfaces./\/etc\/resolv.conf./'`

echo $SRC_LINK

ln -sf $SRC_LINK /etc/resolv.conf

/etc/init.d/networking restart

ifconfig | zenity --text-info

$POSTCOMMAND

else

zenity --info --text "No se han efectuado cambios"

fi

else

zenity --error --text "Debe ser root para ejecutar este programa"

fi

Capturas de pantalla

Descárgatelo

set-interface.sh

Última actualización: 17 / Feb / 2006