Skip to content

Instantly share code, notes, and snippets.

@alexbonhomme

alexbonhomme/99-proxy

Last active Dec 25, 2015
Embed
What would you like to do?
Ce script permet d'activer/désactiver le proxy de Lille 1 dans l'env (.bashrc) et sur les applications suivantes : Git, Maven, Network Manager, Eclipse. !! Attention !! Vous devez avoir configuré le proxy sur vos applications au préalable. Ce script n'est qu'un simple 'toggle'. Vous devez aussi éditer les variables de configurations si vous n'ut…
#!/bin/sh
USER=alex # <--- Put your username here
SSID=LILLE1
INTERFACE=$1
STATUS=$2
case $INTERFACE in
wlan0)
case $STATUS in
up)
if [[ ! -z $(/bin/su $USER -c "iwlist wlan0 scanning | grep $SSID") ]]
then
echo "Proxy enable."
/bin/su $USER -c "/home/$USER/Scripts/proxy-lille1 on"
fi
;;
down)
if [[ "'none'" != $(/bin/su $USER -c "gsettings get org.gnome.system.proxy mode") ]]
then
/bin/su $USER -c "/home/$USER/Scripts/proxy-lille1 off"
echo "Proxy disabled."
fi
;;
esac
;;
esac
#!/bin/sh
#----------------------------
#
# Author : Alexandre Bonhomme
# Last update : 5/11/2013
#
#----------------------------
### Configuration ###
# Network Manager (by default in Gnome)
#
nm_active=true
# Env
#
env_config="$HOME/.bashrc"
# Git
#
git_config="$HOME/.gitconfig"
# SVN
#
svn_config="$HOME/.subversion/servers"
# Maven
#
mvn_config="$HOME/.m2/settings.xml"
# Eclipse
# Version number of your installation
#
eclipse_version="4.3.0" # /!\ <--- TO CONFIGURE /!\
# Android SDK
#
android_config="$HOME/.android/androidtool.cfg"
######################
#
eclipse_config="$HOME/.eclipse/org.eclipse.platform_$eclipse_version*/configuration/.settings/org.eclipse.core.net.prefs"
if [[ $1 = "on" ]]; then
# Network Manager
if $nm_active ; then
dbus-launch --exit-with-session gsettings set org.gnome.system.proxy mode auto
fi
# Env
sed -i -e 's/^#\(export\ .*_proxy\)/\1/' $env_config
# Git
sed -i -e 's/^#\(\[https*\]\)/\1/; s/^#\(\t*proxy\)/\1/' $git_config
# SVN
sed -i -e 's/^#\(http-proxy-host\)/\1/; s/^#\(http-proxy-port\)/\1/' $svn_config
# Maven
# Need this structure :
# <proxy>
# <active...</active>
# ...
# </proxy>
sed -i '/<proxy>/{n; s/false/true/}' $mvn_config
# Eclipse
sed -i '/proxiesEnabled/{s/false/true/}' $eclipse_config
# SDK Android
sed -i -e 's/^#\(http.proxy*\)/\1/' $android_config
elif [[ $1 = "off" ]]; then
# Network Manager
if $nm_active ; then
dbus-launch --exit-with-session gsettings set org.gnome.system.proxy mode none
fi
# Env
sed -i -e 's/\(^export\ .*_proxy\)/#\1/' $env_config
unset http_proxy
# Git
sed -i -e 's/\(^\[https*\]\)/#\1/; s/\(^\t*proxy\)/#\1/' $git_config
# SVN
sed -i -e 's/\(^http-proxy-host\)/#\1/; s/\(^http-proxy-port\)/#\1/' $svn_config
# Maven
sed -i '/<proxy>/{n; s/true/false/}' $mvn_config
# Eclipse
sed -i '/proxiesEnabled/{s/true/false/}' $eclipse_config
# SDK Android
sed -i -e 's/\(^http.proxy*\)/#\1/' $android_config
else
echo "Usage : $0 [on|off]"
fi
@cmnt

This comment has been minimized.

Copy link

@cmnt cmnt commented Oct 11, 2013

Super !
Tu pourrais aussi prendre en compte les "paramètres réseaux" Ubuntu ?
Merci

@alexbonhomme

This comment has been minimized.

Copy link
Owner Author

@alexbonhomme alexbonhomme commented Oct 11, 2013

J'ai ajouté la gestion du proxy en mode "automatique" sous Gnome. Il faut auparavant avoir renseigné le champs "URL de configuration" dans la partie "Serveur mandataire" du gestionnaire de réseaux .

Note

A tester sous Unity, c'est fort possible que la manip ne fonctionne pas.

@alexbonhomme

This comment has been minimized.

Copy link
Owner Author

@alexbonhomme alexbonhomme commented Oct 11, 2013

Ajout de la gestion du switch pour Eclipse

Eclipse

Vous devez renseigner le numéro de version de votre installation Eclipse (par default j'ai mis la version 4.3.0, Kepler).

@alexbonhomme

This comment has been minimized.

Copy link
Owner Author

@alexbonhomme alexbonhomme commented Oct 15, 2013

J'ai ajouté une script de lancement (99-proxy) automatique pour les utilisateur de Network Manager à placer dans /etc/NetworkManager/dispatcher.d/. Cela devrait fonctionner sous Ubuntu, Fedora, and co. cf. votre distrib' pour savoir ou placer le script.

@cmnt

This comment has been minimized.

Copy link

@cmnt cmnt commented Oct 16, 2013

Yep,
Super boulot ! Tu pourrais ajouter Android & Svn stp :

Svn

svn_config="$HOME/.subversion/servers"

on

sed -i -e 's/^#(http-proxy-host)/\1/; s/^#(http-proxy-port)/\1/' $svn_config

off

sed -i -e 's/(^http-proxy-host)/#\1/; s/(^http-proxy-port)/#\1/' $svn_config

Android

android_config="$HOME/.android/androidtool.cfg"

on

sed -i -e 's/^#(http.proxy*)/\1/' $android_config

off

sed -i -e 's/(^http.proxy*)/#\1/' $android_config

Merci ;)

@alexbonhomme

This comment has been minimized.

Copy link
Owner Author

@alexbonhomme alexbonhomme commented Nov 5, 2013

Done. Mais SVN non testé de mon coté.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.