Move sudo to only where needed to fix proxy issues

I propose moving sudo to only those operations that need it rather than the whole script. This fixes being behind a corporate proxy server configured through environment variables which do not survive "sudo" without -E option. Additionally, if the curl request fails it is nice to see why (with the -S option), since the error message saying the distribution is not supported is misleading in the event of an network error.