tools/copy_dev_environment_to_uec.sh
c1024d89
 #!/usr/bin/env bash
 
e62ba4d3
 # **copy_dev_environment_to_uec.sh**
 
c1024d89
 # Echo commands
 set -o xtrace
 
 # Exit on error to stop unexpected errors
 set -o errexit
 
 # Keep track of the current directory
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
7f9aa71b
 TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
 
 # Import common functions
 . $TOP_DIR/functions
c1024d89
 
 # Change dir to top of devstack
 cd $TOP_DIR
 
91b8d13e
 # Source params
 source ./stackrc
 
c1024d89
 # Echo usage
 usage() {
     echo "Add stack user and keys"
     echo ""
     echo "Usage: $0 [full path to raw uec base image]"
 }
 
 # Make sure this is a raw image
 if ! qemu-img info $1 | grep -q "file format: raw"; then
     usage
     exit 1
 fi
 
 # Mount the image
 DEST=/opt/stack
 STAGING_DIR=/tmp/`echo $1 | sed  "s/\//_/g"`.stage.user
 mkdir -p $STAGING_DIR
 umount $STAGING_DIR || true
 sleep 1
 mount -t ext4 -o loop $1 $STAGING_DIR
 mkdir -p $STAGING_DIR/$DEST
 
 # Create a stack user that is a member of the libvirtd group so that stack
 # is able to interact with libvirt.
 chroot $STAGING_DIR groupadd libvirtd || true
74759aa1
 chroot $STAGING_DIR useradd $STACK_USER -s /bin/bash -d $DEST -G libvirtd || true
c1024d89
 
e228093e
 # Add a simple password - pass
74759aa1
 echo $STACK_USER:pass | chroot $STAGING_DIR chpasswd
c1024d89
 
e228093e
 # Configure sudo
74759aa1
 ( umask 226 && echo "$STACK_USER ALL=(ALL) NOPASSWD:ALL" \
d7326d2e
     > $STAGING_DIR/etc/sudoers.d/50_stack_sh )
e228093e
 
c1024d89
 # Copy over your ssh keys and env if desired
 cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
 cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
 cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
 cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
 cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
 
d7326d2e
 # Copy devstack
 rm -rf $STAGING_DIR/$DEST/devstack
 cp_it . $STAGING_DIR/$DEST/devstack
 
c1024d89
 # Give stack ownership over $DEST so it may do the work needed
74759aa1
 chroot $STAGING_DIR chown -R $STACK_USER $DEST
c1024d89
 
e228093e
 # Unmount
 umount $STAGING_DIR