-
-
Save alexbonhomme/6923495 to your computer and use it in GitHub Desktop.
#!/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 |
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).
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.
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 ;)
Done. Mais SVN non testé de mon coté.
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.