| Dean Troyer | 23f69d8 | 2013-10-04 12:35:24 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
|  | 2 |  | 
|  | 3 | # **create-stack-user.sh** | 
|  | 4 |  | 
|  | 5 | # Create a user account suitable for running DevStack | 
|  | 6 | # - create a group named $STACK_USER if it does not exist | 
|  | 7 | # - create a user named $STACK_USER if it does not exist | 
| Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 8 | # | 
| Dean Troyer | 23f69d8 | 2013-10-04 12:35:24 -0500 | [diff] [blame] | 9 | #   - home is $DEST | 
| Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 10 | # | 
| Dean Troyer | 23f69d8 | 2013-10-04 12:35:24 -0500 | [diff] [blame] | 11 | # - configure sudo for $STACK_USER | 
|  | 12 |  | 
|  | 13 | # ``stack.sh`` was never intended to run as root.  It had a hack to do what is | 
|  | 14 | # now in this script and re-launch itself, but that hack was less than perfect | 
|  | 15 | # and it was time for this nonsense to stop.  Run this script as root to create | 
|  | 16 | # the user and configure sudo. | 
|  | 17 |  | 
|  | 18 |  | 
|  | 19 | # Keep track of the devstack directory | 
|  | 20 | TOP_DIR=$(cd $(dirname "$0")/.. && pwd) | 
|  | 21 |  | 
|  | 22 | # Import common functions | 
|  | 23 | source $TOP_DIR/functions | 
|  | 24 |  | 
|  | 25 | # Determine what system we are running on.  This provides ``os_VENDOR``, | 
|  | 26 | # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` | 
|  | 27 | # and ``DISTRO`` | 
|  | 28 | GetDistro | 
|  | 29 |  | 
|  | 30 | # Needed to get ``ENABLED_SERVICES`` | 
|  | 31 | source $TOP_DIR/stackrc | 
|  | 32 |  | 
|  | 33 | # Give the non-root user the ability to run as **root** via ``sudo`` | 
|  | 34 | is_package_installed sudo || install_package sudo | 
|  | 35 |  | 
|  | 36 | if ! getent group $STACK_USER >/dev/null; then | 
|  | 37 | echo "Creating a group called $STACK_USER" | 
|  | 38 | groupadd $STACK_USER | 
|  | 39 | fi | 
|  | 40 |  | 
|  | 41 | if ! getent passwd $STACK_USER >/dev/null; then | 
|  | 42 | echo "Creating a user called $STACK_USER" | 
|  | 43 | useradd -g $STACK_USER -s /bin/bash -d $DEST -m $STACK_USER | 
|  | 44 | fi | 
|  | 45 |  | 
|  | 46 | echo "Giving stack user passwordless sudo privileges" | 
|  | 47 | # UEC images ``/etc/sudoers`` does not have a ``#includedir``, add one | 
|  | 48 | grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || | 
|  | 49 | echo "#includedir /etc/sudoers.d" >> /etc/sudoers | 
|  | 50 | ( umask 226 && echo "$STACK_USER ALL=(ALL) NOPASSWD:ALL" \ | 
|  | 51 | > /etc/sudoers.d/50_stack_sh ) |