blob: c949b329dfb335361a645a7a53833fa56d74ab50 [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)
11TOP_DIR=`cd $TOOLS_DIR/..; pwd`
12
13# Change dir to top of devstack
14cd $TOP_DIR
15
16# Echo usage
17usage() {
18 echo "Add stack user and keys"
19 echo ""
20 echo "Usage: $0 [full path to raw uec base image]"
21}
22
23# Make sure this is a raw image
24if ! qemu-img info $1 | grep -q "file format: raw"; then
25 usage
26 exit 1
27fi
28
29# Mount the image
30DEST=/opt/stack
31STAGING_DIR=/tmp/`echo $1 | sed "s/\//_/g"`.stage.user
32mkdir -p $STAGING_DIR
33umount $STAGING_DIR || true
34sleep 1
35mount -t ext4 -o loop $1 $STAGING_DIR
36mkdir -p $STAGING_DIR/$DEST
37
38# Create a stack user that is a member of the libvirtd group so that stack
39# is able to interact with libvirt.
40chroot $STAGING_DIR groupadd libvirtd || true
41chroot $STAGING_DIR useradd stack -s /bin/bash -d $DEST -G libvirtd || true
42
Anthony Younge2280932011-11-09 22:29:22 -080043# Add a simple password - pass
Anthony Youngc1024d82011-11-09 18:58:07 -080044echo stack:pass | chroot $STAGING_DIR chpasswd
45
Anthony Younge2280932011-11-09 22:29:22 -080046# Configure sudo
Jesse Andrewsd7326d22011-11-20 10:02:26 -080047( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \
48 > $STAGING_DIR/etc/sudoers.d/50_stack_sh )
Anthony Younge2280932011-11-09 22:29:22 -080049
Anthony Youngc1024d82011-11-09 18:58:07 -080050# Gracefully cp only if source file/dir exists
51function cp_it {
52 if [ -e $1 ] || [ -d $1 ]; then
53 cp -pRL $1 $2
54 fi
55}
56
57# Copy over your ssh keys and env if desired
58cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
59cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
60cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
61cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
62cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
63
Jesse Andrewsd7326d22011-11-20 10:02:26 -080064# Copy devstack
65rm -rf $STAGING_DIR/$DEST/devstack
66cp_it . $STAGING_DIR/$DEST/devstack
67
Anthony Youngc1024d82011-11-09 18:58:07 -080068# Give stack ownership over $DEST so it may do the work needed
69chroot $STAGING_DIR chown -R stack $DEST
70
Anthony Younge2280932011-11-09 22:29:22 -080071# Unmount
72umount $STAGING_DIR