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