blob: 94a492666890e6a3358c10c97de99d7233541642 [file] [log] [blame]
Anthony Youngc1024d82011-11-09 18:58:07 -08001#!/usr/bin/env bash
2
Dean Troyere62ba4d2012-06-27 22:07:34 -05003# **copy_dev_environment_to_uec.sh**
4
Anthony Youngc1024d82011-11-09 18:58:07 -08005# Echo commands
6set -o xtrace
7
8# Exit on error to stop unexpected errors
9set -o errexit
10
11# Keep track of the current directory
12TOOLS_DIR=$(cd $(dirname "$0") && pwd)
Dean Troyer7f9aa712012-01-31 12:11:56 -060013TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
14
15# Import common functions
16. $TOP_DIR/functions
Anthony Youngc1024d82011-11-09 18:58:07 -080017
18# Change dir to top of devstack
19cd $TOP_DIR
20
Attila Fazekas91b8d132013-01-06 22:40:09 +010021# Source params
22source ./stackrc
23
Anthony Youngc1024d82011-11-09 18:58:07 -080024# Echo usage
Ian Wienandaee18c72014-02-21 15:35:08 +110025function usage {
Anthony Youngc1024d82011-11-09 18:58:07 -080026 echo "Add stack user and keys"
27 echo ""
28 echo "Usage: $0 [full path to raw uec base image]"
29}
30
31# Make sure this is a raw image
32if ! qemu-img info $1 | grep -q "file format: raw"; then
33 usage
34 exit 1
35fi
36
37# Mount the image
38DEST=/opt/stack
39STAGING_DIR=/tmp/`echo $1 | sed "s/\//_/g"`.stage.user
40mkdir -p $STAGING_DIR
41umount $STAGING_DIR || true
42sleep 1
43mount -t ext4 -o loop $1 $STAGING_DIR
44mkdir -p $STAGING_DIR/$DEST
45
46# Create a stack user that is a member of the libvirtd group so that stack
47# is able to interact with libvirt.
48chroot $STAGING_DIR groupadd libvirtd || true
Dean Troyer74759aa2013-01-24 14:19:55 -060049chroot $STAGING_DIR useradd $STACK_USER -s /bin/bash -d $DEST -G libvirtd || true
Anthony Youngc1024d82011-11-09 18:58:07 -080050
Anthony Younge2280932011-11-09 22:29:22 -080051# Add a simple password - pass
Dean Troyer74759aa2013-01-24 14:19:55 -060052echo $STACK_USER:pass | chroot $STAGING_DIR chpasswd
Anthony Youngc1024d82011-11-09 18:58:07 -080053
Anthony Younge2280932011-11-09 22:29:22 -080054# Configure sudo
Dean Troyer74759aa2013-01-24 14:19:55 -060055( umask 226 && echo "$STACK_USER ALL=(ALL) NOPASSWD:ALL" \
Jesse Andrewsd7326d22011-11-20 10:02:26 -080056 > $STAGING_DIR/etc/sudoers.d/50_stack_sh )
Anthony Younge2280932011-11-09 22:29:22 -080057
Anthony Youngc1024d82011-11-09 18:58:07 -080058# Copy over your ssh keys and env if desired
59cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
60cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
61cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
62cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
63cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
64
Jesse Andrewsd7326d22011-11-20 10:02:26 -080065# Copy devstack
66rm -rf $STAGING_DIR/$DEST/devstack
67cp_it . $STAGING_DIR/$DEST/devstack
68
Anthony Youngc1024d82011-11-09 18:58:07 -080069# Give stack ownership over $DEST so it may do the work needed
Dean Troyer74759aa2013-01-24 14:19:55 -060070chroot $STAGING_DIR chown -R $STACK_USER $DEST
Anthony Youngc1024d82011-11-09 18:58:07 -080071
Anthony Younge2280932011-11-09 22:29:22 -080072# Unmount
73umount $STAGING_DIR