PREREQUISITES

Install wpa_supplicant and wireless-tools(standard in most distros).

# apt-get install wireless-tools wpa_supplicant

Identify your wifi controller. This can usually be found by typing
$ iwconfig

Locate all the config files for your desired networks. Mine are placed in /etc/network/wifi/.conf. More info on creating configs in the end of the file.

INSTALLATION

Create the SSID selection script.
I've put mine in /etc/network/wifi/select

#!/bin/sh
ifconfig [INTERFACE] up 1> /dev/null && { iwlist [INTERFACE] scan | grep -o "\".*\"" | tr -d \'\" | sort | uniq; grep -o "map\ .*" /etc/network/interfaces | awk '{print $2}'; } | sort | uniq -d | head -1

Make it executable.
# chmod +x /etc/network/wifi/select

Change in /etc/network/interfaces the [INTERFACE] specification.
		
mapping [INTERFACE]
	script /etc/network/wifi/select
	map [SSID]1
	map [SSID]2
	..
	map eduroam

iface [SSID]1 inet dhcp
wpa_conf /etc/network/wifi/[SSID]1.conf

iface [SSID]2 inet dhcp
wpa_conf /etc/network/wifi/[SSID]2.conf

..

iface eduroam inet dhcp
wpa_conf /etc/network/wifi/eduroam.conf

You're finished! Restart the network service with:
# service networking restartworking restart
And you can connect to a available network by running this command.
# ifup [INTERFACE]
If you want to force an [SSID] you can run:
# ifup [INTERFACE]=[SSID]

CONFIG CREATION

Standard wpa2 network configs can be created by running:

# wpa_passphrase [SSID] [PASSWORD] > /etc/network/wifi/[SSID].conf

For eduroam you can use this example:
		
network={
	ssid="eduroam"
	key_mgmt=WPA-EAP
	eap=TTLS
	phase2="auth=MSCHAPV2"
	ca_cert="/etc/ssl/certs/AddTrust_External_Root.pem"
	identity="login@university.nl"
	scan_ssid=1
	password="YOURPASSWORD"
}
If you don't want your password in a config you can also use a hash generated by this command. (Don't forget to remove it from ~/.bash_history afterwards)
$ echo -n [PASSWORD] | iconv -t UTF16LE | openssl md4
You should replace the plaintext string with: "hash:[HASHOUTPUT]"
note: don't use quotes.