Make tools/users-setup explain its actions first
authorKlaus Aehlig <aehlig@google.com>
Wed, 11 Sep 2013 09:00:15 +0000 (11:00 +0200)
committerKlaus Aehlig <aehlig@google.com>
Wed, 11 Sep 2013 16:11:54 +0000 (18:11 +0200)
Before doing any changes, make tools/users-setup explain its
actions first, and ask the user for confirmation. If the first
argument is --yes-do-it, this step will be skipped.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>

Makefile.am

index 2fd79b9..0f8941f 100644 (file)
@@ -1384,6 +1384,19 @@ tools/kvm-ifup: tools/kvm-ifup.in $(REPLACE_VARS_SED)
 tools/users-setup: Makefile $(userspecs)
        set -e; \
        { echo '#!/bin/sh'; \
 tools/users-setup: Makefile $(userspecs)
        set -e; \
        { echo '#!/bin/sh'; \
+         echo 'if [ "x$$1" != "x--yes-do-it" ];'; \
+         echo 'then echo "This will do the following changes"'; \
+         $(AWK) -- '{print "echo + Will add group ",$$1; count++}\
+                    END {if (count == 0) {print "echo + No groups to add"}}' doc/users/groups; \
+         $(AWK) -- '{if (NF > 1) {print "echo + Will add user",$$1,"with primary group",$$2} \
+                                 else {print "echo + Will add user",$$1}; count++}\
+                    END {if (count == 0) {print "echo + No users to add"}}' doc/users/users; \
+         $(AWK) -- '{print "echo + Will add user",$$1,"to group",$$2}' doc/users/groupmemberships; \
+         echo 'echo'; \
+         echo 'echo "OK? (y/n)"'; \
+         echo 'read confirm'; \
+         echo 'if [ "x$$confirm" != "xy" ]; then exit 0; fi'; \
+         echo 'fi'; \
          $(AWK) -- '{print "addgroup --system",$$1}' doc/users/groups; \
          $(AWK) -- '{if (NF > 1) {print "adduser --system --ingroup",$$2,$$1} else {print "adduser --system",$$1}}' doc/users/users; \
          $(AWK) -- '{print "adduser",$$1,$$2}' doc/users/groupmemberships; \
          $(AWK) -- '{print "addgroup --system",$$1}' doc/users/groups; \
          $(AWK) -- '{if (NF > 1) {print "adduser --system --ingroup",$$2,$$1} else {print "adduser --system",$$1}}' doc/users/users; \
          $(AWK) -- '{print "adduser",$$1,$$2}' doc/users/groupmemberships; \