in reply to Detecting the current terminal

Just an idea:

who -a gives PID of the login process in addition. From the PID of your script, you could traverse the parent-pid hierarchy (through ps -f --pid xxx or some handy module), until you find one listed in the who -a.