Browse code

Merge pull request #31 from vishvananda/master

No ROOT!!!

Jesse Andrews authored on 2011/10/01 07:44:44
Showing 1 changed files
... ...
@@ -26,10 +26,6 @@ if ! grep -q natty /etc/lsb-release; then
26 26
     fi
27 27
 fi
28 28
 
29
-#The following makes fresh mininmal installs (i.e. LXCs) happy
30
-apt-get update
31
-apt-get install -y sudo
32
-
33 29
 # stack.sh keeps the list of **apt** and **pip** dependencies in external
34 30
 # files, along with config templates and other useful files.  You can find these
35 31
 # in the ``files`` directory (next to this script).  We will reference this
... ...
@@ -40,12 +36,26 @@ if [ ! -d $FILES ]; then
40 40
     exit 1
41 41
 fi
42 42
 
43
-# you need to run this as a regular user with sudo priviledges
43
+# If stack.sh is run as root, it automatically creates a stack user with
44
+# sudo privileges and runs as that user.
44 45
 if [[ $EUID -eq 0 ]]; then
45
-   echo "This script cannot be run as root." 1>&2
46
-   echo "You should run this script as the user you wish openstack to run as" 1>&2
47
-   echo "The user will need to be a sudoer (without password)" 1>&2
48
-   exit 1
46
+   echo "You are running this script as root."
47
+   apt-get update
48
+   apt-get install -y sudo
49
+   if ! getent passwd | grep -q stack; then
50
+       echo "Creating a user called stack"
51
+       useradd -g sudo -s /bin/bash -m stack
52
+    fi
53
+    echo "Making sure stack has passwordless sudo"
54
+    sed -i "/^%sudo/ { / ALL/ { s/ ALL/ NOPASSWD:ALL/ }}" /etc/sudoers
55
+    echo "Copying files to stack user"
56
+    cp -r -f `pwd` /home/stack/
57
+    THIS_DIR=$(basename $(dirname $(readlink -f $0)))
58
+    chown -R stack:sudo /home/stack/$THIS_DIR
59
+    echo "Running the script as stack in 3 seconds..."
60
+    sleep 3
61
+    exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
62
+    exit 0
49 63
 fi
50 64
 
51 65