Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 3 | # **copy_dev_environment_to_uec.sh** |
| 4 | |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 5 | # Echo commands |
| 6 | set -o xtrace |
| 7 | |
| 8 | # Exit on error to stop unexpected errors |
| 9 | set -o errexit |
| 10 | |
| 11 | # Keep track of the current directory |
| 12 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 13 | TOP_DIR=$(cd $TOOLS_DIR/..; pwd) |
| 14 | |
| 15 | # Import common functions |
| 16 | . $TOP_DIR/functions |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 17 | |
| 18 | # Change dir to top of devstack |
| 19 | cd $TOP_DIR |
| 20 | |
Attila Fazekas | 91b8d13 | 2013-01-06 22:40:09 +0100 | [diff] [blame] | 21 | # Source params |
| 22 | source ./stackrc |
| 23 | |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 24 | # Echo usage |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 25 | function usage { |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 26 | 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 |
| 32 | if ! qemu-img info $1 | grep -q "file format: raw"; then |
| 33 | usage |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | # Mount the image |
| 38 | DEST=/opt/stack |
| 39 | STAGING_DIR=/tmp/`echo $1 | sed "s/\//_/g"`.stage.user |
| 40 | mkdir -p $STAGING_DIR |
| 41 | umount $STAGING_DIR || true |
| 42 | sleep 1 |
| 43 | mount -t ext4 -o loop $1 $STAGING_DIR |
| 44 | mkdir -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. |
| 48 | chroot $STAGING_DIR groupadd libvirtd || true |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 49 | chroot $STAGING_DIR useradd $STACK_USER -s /bin/bash -d $DEST -G libvirtd || true |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 50 | |
Anthony Young | e228093 | 2011-11-09 22:29:22 -0800 | [diff] [blame] | 51 | # Add a simple password - pass |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 52 | echo $STACK_USER:pass | chroot $STAGING_DIR chpasswd |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 53 | |
Anthony Young | e228093 | 2011-11-09 22:29:22 -0800 | [diff] [blame] | 54 | # Configure sudo |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 55 | ( umask 226 && echo "$STACK_USER ALL=(ALL) NOPASSWD:ALL" \ |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 56 | > $STAGING_DIR/etc/sudoers.d/50_stack_sh ) |
Anthony Young | e228093 | 2011-11-09 22:29:22 -0800 | [diff] [blame] | 57 | |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 58 | # Copy over your ssh keys and env if desired |
| 59 | cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh |
| 60 | cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys |
| 61 | cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig |
| 62 | cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc |
| 63 | cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc |
| 64 | |
Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 65 | # Copy devstack |
| 66 | rm -rf $STAGING_DIR/$DEST/devstack |
| 67 | cp_it . $STAGING_DIR/$DEST/devstack |
| 68 | |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 69 | # Give stack ownership over $DEST so it may do the work needed |
Dean Troyer | 74759aa | 2013-01-24 14:19:55 -0600 | [diff] [blame] | 70 | chroot $STAGING_DIR chown -R $STACK_USER $DEST |
Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 71 | |
Anthony Young | e228093 | 2011-11-09 22:29:22 -0800 | [diff] [blame] | 72 | # Unmount |
| 73 | umount $STAGING_DIR |