blob: d5687dc14d3fe144553496e12cbe12772bd54630 [file] [log] [blame]
Anthony Youngc1024d82011-11-09 18:58:07 -08001#!/usr/bin/env bash
2
3# Echo commands
4set -o xtrace
5
6# Exit on error to stop unexpected errors
7set -o errexit
8
9# Keep track of the current directory
10TOOLS_DIR=$(cd $(dirname "$0") && pwd)
Dean Troyer7f9aa712012-01-31 12:11:56 -060011TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
12
13# Import common functions
14. $TOP_DIR/functions
Anthony Youngc1024d82011-11-09 18:58:07 -080015
16# Change dir to top of devstack
17cd $TOP_DIR
18
19# Echo usage
20usage() {
21 echo "Add stack user and keys"
22 echo ""
23 echo "Usage: $0 [full path to raw uec base image]"
24}
25
26# Make sure this is a raw image
27if ! qemu-img info $1 | grep -q "file format: raw"; then
28 usage
29 exit 1
30fi
31
32# Mount the image
33DEST=/opt/stack
34STAGING_DIR=/tmp/`echo $1 | sed "s/\//_/g"`.stage.user
35mkdir -p $STAGING_DIR
36umount $STAGING_DIR || true
37sleep 1
38mount -t ext4 -o loop $1 $STAGING_DIR
39mkdir -p $STAGING_DIR/$DEST
40
41# Create a stack user that is a member of the libvirtd group so that stack
42# is able to interact with libvirt.
43chroot $STAGING_DIR groupadd libvirtd || true
44chroot $STAGING_DIR useradd stack -s /bin/bash -d $DEST -G libvirtd || true
45
Anthony Younge2280932011-11-09 22:29:22 -080046# Add a simple password - pass
Anthony Youngc1024d82011-11-09 18:58:07 -080047echo stack:pass | chroot $STAGING_DIR chpasswd
48
Anthony Younge2280932011-11-09 22:29:22 -080049# Configure sudo
Jesse Andrewsd7326d22011-11-20 10:02:26 -080050( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \
51 > $STAGING_DIR/etc/sudoers.d/50_stack_sh )
Anthony Younge2280932011-11-09 22:29:22 -080052
Anthony Youngc1024d82011-11-09 18:58:07 -080053# Copy over your ssh keys and env if desired
54cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
55cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
56cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
57cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
58cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
59
Jesse Andrewsd7326d22011-11-20 10:02:26 -080060# Copy devstack
61rm -rf $STAGING_DIR/$DEST/devstack
62cp_it . $STAGING_DIR/$DEST/devstack
63
Anthony Youngc1024d82011-11-09 18:58:07 -080064# Give stack ownership over $DEST so it may do the work needed
65chroot $STAGING_DIR chown -R stack $DEST
66
Anthony Younge2280932011-11-09 22:29:22 -080067# Unmount
68umount $STAGING_DIR