blob: 231a20f33269faad9003099ebe0db1c8c7de5608 [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# and has sudo ability (in the future this should be limited to only what
53# stack requires)
54echo "stack ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers
55
56# Gracefully cp only if source file/dir exists
57function cp_it {
58 if [ -e $1 ] || [ -d $1 ]; then
59 cp -pRL $1 $2
60 fi
61}
62
63# Copy over your ssh keys and env if desired
64cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
65cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
66cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
67cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
68cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
69
70# Give stack ownership over $DEST so it may do the work needed
71chroot $STAGING_DIR chown -R stack $DEST
72
Anthony Younge2280932011-11-09 22:29:22 -080073# Unmount
74umount $STAGING_DIR