Advertisement
ItachiSan

PoliMi Protected shell connection script

Jun 5th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.85 KB | None | 0 0
  1. #!/bin/sh
  2. ## polimi-protected sh handler
  3. ## Made by Giovanni Santini (ItachiSan @ github.com)
  4. # --------------------------------------------------------------------
  5. # connects to 'polimi-protected' wifi AP on ArchLinux
  6. # This works for ArchLinux, for else you may need to edit this script
  7. # --------------------------------------------------------------------
  8. # You should have:
  9. # systemctl -> daemon manager (in this case, his power is OVAH 9000)
  10. # ifconfig/iwconfig/wpa_supplicant/dhclient -> quite common net tools
  11. # polimi-protected.conf/ca.pem/wifiCert.p12 -> polimi connection stuff (I suppose you're a PoliMi student)
  12. # --------------------------------------------------------------------
  13. # Edit this script at your wish but give proper credits ;)
  14.  
  15. ## Declaration Time
  16. # Your device iface (you can find it with ifconfig)
  17. DEV=wlp2s0
  18. # wpa_supplicant driver (wext should work fine for everyone)
  19. DRIVER=wext
  20. # root part; if not ran as root, we use sudo
  21. SU=sudo
  22. if [ "$(id -u)" = "0" ]; then
  23.    SU=''
  24. fi
  25. #
  26. SERVICE_STOP='systemctl stop'
  27. #EOF Declarations
  28.  
  29. # The real program
  30. case $1 in
  31. sh)
  32.     # Killing services (about 30 times, so we're sure they're dead)
  33.     for ((i = 1; i <= 30; i++)); do
  34.         $SU $SERVICE_STOP NetworkManager-wait-online.service
  35.         $SU $SERVICE_STOP NetworkManager.service
  36.         $SU $SERVICE_STOP wpa_supplicant.service
  37.         killall wpa_supplicant 2&>/dev/null
  38.     done
  39.    
  40.     #Setting up all the stuff
  41.     echo 'Configuring stuff with net toools...'
  42.     $SU ifconfig $DEV down
  43.     $SU ifconfig $DEV up
  44.     $SU iwconfig $DEV essid polimi-protected
  45.     $SU wpa_supplicant -i $DEV -D $DRIVER -c polimi-protected.conf -d
  46.     echo 'Sleeping for a while...'    
  47.     sleep 15
  48.     $SU dhclient $DEV
  49.     echo 'Done!'
  50.     exit 0    
  51.     ;;
  52. *)
  53.     echo 'Need an input (usually "sh")'
  54.     exit 0
  55.     ;;
  56. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement