Add timeout and retry to patch script

Add timeout and retry to the patch script to handle
cases where the command times out (e.g. SSH interupted by network config).