Browse code

tweaks to warm script, add script to configure stack user

Anthony Young authored on 2011/11/10 11:58:07
Showing 2 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,66 @@
0
+#!/usr/bin/env bash
1
+
2
+# Echo commands
3
+set -o xtrace
4
+
5
+# Exit on error to stop unexpected errors
6
+set -o errexit
7
+
8
+# Keep track of the current directory
9
+TOOLS_DIR=$(cd $(dirname "$0") && pwd)
10
+TOP_DIR=`cd $TOOLS_DIR/..; pwd`
11
+
12
+# Change dir to top of devstack
13
+cd $TOP_DIR
14
+
15
+# Echo usage
16
+usage() {
17
+    echo "Add stack user and keys"
18
+    echo ""
19
+    echo "Usage: $0 [full path to raw uec base image]"
20
+}
21
+
22
+# Make sure this is a raw image
23
+if ! qemu-img info $1 | grep -q "file format: raw"; then
24
+    usage
25
+    exit 1
26
+fi
27
+
28
+# Mount the image
29
+DEST=/opt/stack
30
+STAGING_DIR=/tmp/`echo $1 | sed  "s/\//_/g"`.stage.user
31
+mkdir -p $STAGING_DIR
32
+umount $STAGING_DIR || true
33
+sleep 1
34
+mount -t ext4 -o loop $1 $STAGING_DIR
35
+mkdir -p $STAGING_DIR/$DEST
36
+
37
+# Create a stack user that is a member of the libvirtd group so that stack
38
+# is able to interact with libvirt.
39
+chroot $STAGING_DIR groupadd libvirtd || true
40
+chroot $STAGING_DIR useradd stack -s /bin/bash -d $DEST -G libvirtd || true
41
+
42
+# a simple password - pass
43
+echo stack:pass | chroot $STAGING_DIR chpasswd
44
+
45
+# and has sudo ability (in the future this should be limited to only what
46
+# stack requires)
47
+echo "stack ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers
48
+
49
+# Gracefully cp only if source file/dir exists
50
+function cp_it {
51
+    if [ -e $1 ] || [ -d $1 ]; then
52
+        cp -pRL $1 $2
53
+    fi
54
+}
55
+
56
+# Copy over your ssh keys and env if desired
57
+cp_it ~/.ssh $STAGING_DIR/$DEST/.ssh
58
+cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/$DEST/.ssh/authorized_keys
59
+cp_it ~/.gitconfig $STAGING_DIR/$DEST/.gitconfig
60
+cp_it ~/.vimrc $STAGING_DIR/$DEST/.vimrc
61
+cp_it ~/.bashrc $STAGING_DIR/$DEST/.bashrc
62
+
63
+# Give stack ownership over $DEST so it may do the work needed
64
+chroot $STAGING_DIR chown -R stack $DEST
65
+
... ...
@@ -33,8 +33,10 @@ if [ ! -d files/apts ]; then
33 33
 fi 
34 34
 
35 35
 # Mount the image
36
-STAGING_DIR=`mktemp -d uec.XXXXXXXXXX`
36
+STAGING_DIR=/tmp/`echo $1 | sed  "s/\//_/g"`.stage
37 37
 mkdir -p $STAGING_DIR
38
+umount $STAGING_DIR || true
39
+sleep 1
38 40
 mount -t ext4 -o loop $1 $STAGING_DIR
39 41
 
40 42
 # Make sure that base requirements are installed
... ...
@@ -43,6 +45,7 @@ cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf
43 43
 # Perform caching on the base image to speed up subsequent runs
44 44
 chroot $STAGING_DIR apt-get update
45 45
 chroot $STAGING_DIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1`
46
-chroot $STAGING_DIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1`
47
-chroot $STAGING_DIR pip install `cat files/pips/*`
48
-umount $STAGING_DIR && rm -rf $STAGING_DIR
46
+chroot $STAGING_DIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1` || true
47
+mkdir -p $STAGING_DIR/var/cache/pip
48
+PIP_DOWNLOAD_CACHE=/var/cache/pip chroot $STAGING_DIR pip install `cat files/pips/*` || true
49
+umount $STAGING_DIR