You don't need to do all that. Just run emacsclient with `emacsclient -a ""`.
From the man page:
-a, --alternate-editor=COMMAND
If the Emacs server is not running, run the specified shell command instead. This can also be specified via the ALTERNATE_EDITOR environment variable. If the value of ALTERNATE_EDITOR is the empty string, run
"emacs --daemon" to start Emacs in daemon mode, and try to connect to it.