Finding an active wireless interface turned out to be surprisingly difficult, so I just left the credentials as parameters to script.
But I know that UCI can see the SSIDs and keys for all the wireless interfaces. "All I want to do" is pick an active one and print its SSID and password on the label.
(Note: I'm fairly convinced that creating a label like this is "secure enough". If the bad guys are reading the password from your router's label, they are also stealing your TV and silverware...)
Can someone give me a script that identifies an active wireless interface? Thanks.
Update: I really want to return the SSID and Password of one of the active interfaces...
The first disabled wireless interface will break the loop and information about subsequent (enabled) interfaces will not be printed. You should replace break with continue.
Thanks again for all those responses. I now have a print-router-label.sh script (OpenWrtScripts repo) that reads the config of a router, and prints the following information. I tape it to the side of my router so I can come back to it easily. (I got tired of scribbling this info on a tiny slip of paper. Now I let the computer do the work for me...)
This is part of my larger "Spare Router" project that resets decommissioned routers to a known good, easy-to-reuse state. See the config-spare-router.sh script.