diff --git a/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java b/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java index 9f537006be..7674ce26fa 100644 --- a/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java +++ b/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java @@ -129,8 +129,8 @@ public class RunScriptOnNodeUsingSshTest { expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect(sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + - "mkdir -p /home/users/testuser\n" + - "useradd -s /bin/bash -d /home/users/testuser testuser\n" + + "mkdir -p /home/users\n" + + "useradd -s /bin/bash -m -d /home/users/testuser testuser\n" + "chown -R testuser /home/users/testuser\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("done", null, 0)); sshClient.disconnect(); diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/SaveHttpResponseTo.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/SaveHttpResponseTo.java index e06dc21658..615e5ab06d 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/SaveHttpResponseTo.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/domain/SaveHttpResponseTo.java @@ -32,7 +32,7 @@ import com.google.common.collect.Multimap; * @author Adrian Cole */ public class SaveHttpResponseTo extends InterpretableStatement { - static final String CURL = "curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20"; + public static final String CURL = "curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20"; /** * diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java index 5fd68fbaa2..6621263abd 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java @@ -161,7 +161,8 @@ public class UserAdd implements Statement { throw new UnsupportedOperationException("windows not yet implemented"); String homeDir = defaultHome + "{fs}" + login; ImmutableList.Builder statements = ImmutableList. builder(); - statements.add(Statements.exec("{md} " + homeDir)); + // useradd cannot create the default homedir + statements.add(Statements.exec("{md} " + defaultHome)); ImmutableMap.Builder userAddOptions = ImmutableMap. builder(); userAddOptions.put("-s", shell); @@ -176,6 +177,7 @@ public class UserAdd implements Statement { userAddOptions.put("-G", Joiner.on(',').join(groups)); } + userAddOptions.put("-m", ""); userAddOptions.put("-d", homeDir); if (password != null) { try { diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java index fc9140376b..ac570a1eb9 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java @@ -33,41 +33,41 @@ public class UserAddTest { public void testUNIX() { assertEquals(UserAdd.builder().login("me").build().render(OsFamily.UNIX), - "mkdir -p /home/users/me\nuseradd -s /bin/bash -d /home/users/me me\nchown -R me /home/users/me\n"); + "mkdir -p /home/users\nuseradd -s /bin/bash -m -d /home/users/me me\nchown -R me /home/users/me\n"); } public void testWithBaseUNIX() { assertEquals(UserAdd.builder().login("me").defaultHome("/export/home").build().render(OsFamily.UNIX), - "mkdir -p /export/home/me\nuseradd -s /bin/bash -d /export/home/me me\nchown -R me /export/home/me\n"); + "mkdir -p /export/home\nuseradd -s /bin/bash -m -d /export/home/me me\nchown -R me /export/home/me\n"); } public void testWithGroupUNIX() { assertEquals(UserAdd.builder().login("me").group("wheel").build().render(OsFamily.UNIX), - "mkdir -p /home/users/me\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -d /home/users/me me\nchown -R me /home/users/me\n"); + "mkdir -p /home/users\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -m -d /home/users/me me\nchown -R me /home/users/me\n"); } public void testWithGroupsUNIX() { assertEquals(UserAdd.builder().login("me").groups(ImmutableList.of("wheel", "candy")).build().render( OsFamily.UNIX), - "mkdir -p /home/users/me\ngroupadd -f wheel\ngroupadd -f candy\nuseradd -s /bin/bash -g wheel -G candy -d /home/users/me me\nchown -R me /home/users/me\n"); + "mkdir -p /home/users\ngroupadd -f wheel\ngroupadd -f candy\nuseradd -s /bin/bash -g wheel -G candy -m -d /home/users/me me\nchown -R me /home/users/me\n"); } public void testWithPasswordUNIX() { String userAdd = UserAdd.builder().login("me").password("foo").group("wheel").build().render(OsFamily.UNIX); - assert userAdd.startsWith("mkdir -p /home/users/me\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -d /home/users/me -p '$6$") : userAdd; + assert userAdd.startsWith("mkdir -p /home/users\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -m -d /home/users/me -p '$6$") : userAdd; assert userAdd.endsWith("' me\nchown -R me /home/users/me\n") : userAdd; } public void testWithSshAuthorizedKeyUNIX() { assertEquals( UserAdd.builder().login("me").authorizeRSAPublicKey("rsapublickey").build().render(OsFamily.UNIX), - "mkdir -p /home/users/me\nuseradd -s /bin/bash -d /home/users/me me\nmkdir -p /home/users/me/.ssh\ncat >> /home/users/me/.ssh/authorized_keys <<'END_OF_FILE'\nrsapublickey\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/authorized_keys\nchown -R me /home/users/me\n"); + "mkdir -p /home/users\nuseradd -s /bin/bash -m -d /home/users/me me\nmkdir -p /home/users/me/.ssh\ncat >> /home/users/me/.ssh/authorized_keys <<'END_OF_FILE'\nrsapublickey\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/authorized_keys\nchown -R me /home/users/me\n"); } public void testWithSshInstalledKeyUNIX() { assertEquals( UserAdd.builder().login("me").installRSAPrivateKey("rsaprivate").build().render(OsFamily.UNIX), - "mkdir -p /home/users/me\nuseradd -s /bin/bash -d /home/users/me me\nmkdir -p /home/users/me/.ssh\nrm /home/users/me/.ssh/id_rsa\ncat >> /home/users/me/.ssh/id_rsa <<'END_OF_FILE'\nrsaprivate\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/id_rsa\nchown -R me /home/users/me\n"); + "mkdir -p /home/users\nuseradd -s /bin/bash -m -d /home/users/me me\nmkdir -p /home/users/me/.ssh\nrm /home/users/me/.ssh/id_rsa\ncat >> /home/users/me/.ssh/id_rsa <<'END_OF_FILE'\nrsaprivate\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/id_rsa\nchown -R me /home/users/me\n"); } @Test(expectedExceptions = UnsupportedOperationException.class) diff --git a/scriptbuilder/src/test/resources/test_adminaccess_params.sh b/scriptbuilder/src/test/resources/test_adminaccess_params.sh index 5c66dc833f..3908f6299a 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_params.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_params.sh @@ -4,9 +4,9 @@ root ALL = (ALL) ALL %wheel ALL = (ALL) NOPASSWD:ALL END_OF_FILE chmod 0440 /etc/sudoers -mkdir -p /home/users/foo +mkdir -p /home/users groupadd -f wheel -useradd -s /bin/bash -g wheel -d /home/users/foo -p 'crypt(bar)' foo +useradd -s /bin/bash -g wheel -m -d /home/users/foo -p 'crypt(bar)' foo mkdir -p /home/users/foo/.ssh cat >> /home/users/foo/.ssh/authorized_keys <<'END_OF_FILE' fooPublicKey diff --git a/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh b/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh index 9909b98bf9..d91f18e1ef 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh @@ -1,5 +1,5 @@ -mkdir -p /home/users/defaultAdminUsername -useradd -s /bin/bash -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername +mkdir -p /home/users +useradd -s /bin/bash -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername mkdir -p /home/users/defaultAdminUsername/.ssh cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE' publicKey diff --git a/scriptbuilder/src/test/resources/test_adminaccess_standard.sh b/scriptbuilder/src/test/resources/test_adminaccess_standard.sh index 0c10ee9582..3da6b1c70c 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_standard.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_standard.sh @@ -4,9 +4,9 @@ root ALL = (ALL) ALL %wheel ALL = (ALL) NOPASSWD:ALL END_OF_FILE chmod 0440 /etc/sudoers -mkdir -p /home/users/defaultAdminUsername +mkdir -p /home/users groupadd -f wheel -useradd -s /bin/bash -g wheel -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername +useradd -s /bin/bash -g wheel -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername mkdir -p /home/users/defaultAdminUsername/.ssh cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE' publicKey