blob: 85d418ed8229433eb20d707b6333816710729dd9 [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
43# a simple password - pass
44echo stack:pass | chroot $STAGING_DIR chpasswd
45
46# and has sudo ability (in the future this should be limited to only what
47# stack requires)
48echo "stack ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers
49
50# 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
64# Give stack ownership over $DEST so it may do the work needed
65chroot $STAGING_DIR chown -R stack $DEST
66