Do you have a USB serial port on your P1 board? It sounds like you do if you’re programming the initial firmware binary by serial.
Have you tried setting the Wi-Fi credentials using particle serial wifi with a JSON file? You can do it entirely automated, before you flash your firmware binary.
Create a JSON file with the Wi-Fi credentials:
{"network":"xxx","security":"WPA2_AES","password":"xxx"}
Then you can set them with a command like:
particle serial wifi --port xxx --file wifi.json
It should be possible to run that without user intervention when the P1 is in listening mode.