blob: fcb97333c28a18d4936cce2d5a136cc11cc60699 [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
47grep -q "^#includedir.*/etc/sudoers.d" $STAGING_DIR/etc/sudoers ||
48 echo "#includedir /etc/sudoers.d" | sudo tee -a $STAGING_DIR/etc/sudoers
49cp $TOP_DIR/files/sudo/* $STAGING_DIR/etc/sudoers.d/
50sed -e "s,%USER%,$USER,g" -i $STAGING_DIR/etc/sudoers.d/*
51
Anthony Youngc1024d82011-11-09 18:58:07 -080052# Gracefully cp only if source file/dir exists
53function cp_it {
54 if [ -e $1 ] || [ -d $1 ]; then
55 cp -pRL $1 $2
56 fi
57}
58
59# Copy over your ssh keys and env if desired
60cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
61cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
62cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
63cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
64cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
65
66# Give stack ownership over $DEST so it may do the work needed
67chroot $STAGING_DIR chown -R stack $DEST
68
Anthony Younge2280932011-11-09 22:29:22 -080069# Unmount
70umount $STAGING_DIR