lib/ec2/ec2.js
function getUserdata0_(username, upNamespace, envVars_, origUsername) {
  var envVars = cleanEnvVars(upNamespace, envVars_);

  var script  = [
                "#!/bin/bash -ex",
         format("if ! [ -d /home/%s ]; then", username),
         format("  usermod -l %s %s", username, origUsername),
         format("  groupmod -n %s %s", username, origUsername),
         format("  usermod  -d /home/%s -m %s", username, username),
                "fi",

         format("if [ -f /etc/sudoers.d/90-cloudimg-%s ]; then", origUsername),
         format("  mv /etc/sudoers.d/90-cloudimg-%s /etc/sudoers.d/90-cloud-init-users", origUsername),
                "fi",
         format("perl -pi -e 's/%s/%s/g;' /etc/sudoers.d/90-cloud-init-users", origUsername, username),

                "if ! grep `hostname` /etc/hosts; then",
                "  echo \"127.0.0.1 `hostname`\" | sudo tee -a /etc/hosts",
                "fi",
                ""
  ];
  _.each(envVars, function(value, key) {
    script.push("echo "+key+"="+value+" | sudo tee -a /etc/environment");
  });
  script.push(  "");

  console.error(script);
  return script;
}
function getUserdata0_(username, upNamespace, envVars_, origUsername) {
  var envVars = cleanEnvVars(upNamespace, envVars_);

  var script  = [
                "#!/bin/bash -ex",
         format("if ! [ -d /home/%s ]; then", username),
         format("  usermod -l %s %s", username, origUsername),
         format("  groupmod -n %s %s", username, origUsername),
         format("  usermod  -d /home/%s -m %s", username, username),
                "fi",

         format("if [ -f /etc/sudoers.d/90-cloudimg-%s ]; then", origUsername),
         format("  mv /etc/sudoers.d/90-cloudimg-%s /etc/sudoers.d/90-cloud-init-users", origUsername),
                "fi",
         format("perl -pi -e 's/%s/%s/g;' /etc/sudoers.d/90-cloud-init-users", origUsername, username),

                "if ! grep `hostname` /etc/hosts; then",
                "  echo \"127.0.0.1 `hostname`\" | sudo tee -a /etc/hosts",
                "fi",
                ""
  ];
  _.each(envVars, function(value, key) {
    script.push("echo "+key+"="+value+" | sudo tee -a /etc/environment");
  });
  script.push(  "");

  console.error(script);
  return script;
}
function getUserdata0_ ( username , upNamespace , envVars_ , origUsername ) { var envVars = cleanEnvVars ( upNamespace , envVars_ ) ; var script = [ "#!/bin/bash -ex" , format ( "if ! [ -d /home/%s ]; then" , username ) , format ( "  usermod -l %s %s" , username , origUsername ) , format ( "  groupmod -n %s %s" , username , origUsername ) , format ( "  usermod  -d /home/%s -m %s" , username , username ) , "fi" , format ( "if [ -f /etc/sudoers.d/90-cloudimg-%s ]; then" , origUsername ) , format ( "  mv /etc/sudoers.d/90-cloudimg-%s /etc/sudoers.d/90-cloud-init-users" , origUsername ) , "fi" , format ( "perl -pi -e 's/%s/%s/g;' /etc/sudoers.d/90-cloud-init-users" , origUsername , username ) , "if ! grep `hostname` /etc/hosts; then" , "  echo \"127.0.0.1 `hostname`\" | sudo tee -a /etc/hosts" , "fi" , "" ] ; _ . each ( envVars , function ( value , key ) { script . push ( "echo " + key + "=" + value + " | sudo tee -a /etc/environment" ) ; } ) ; script . push ( "" ) ; console . error ( script ) ; return script ; }
The userdata for when starting an instance from a base-image.

Basically, it renames the default 'ubuntu' user to 'scotty'; manages
/etc/hosts, and sets a couple of system-wide env vars.
The userdata for when starting an instance from a base - image .