| Anthony Young | e7fa909 | 2011-11-07 16:10:59 -0600 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
 | 2 |  | 
| Vincent Untz | 7c3053d | 2012-11-29 09:19:16 +0100 | [diff] [blame] | 3 | # **warm_apts_for_uec.sh** | 
| Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 4 |  | 
| Anthony Young | 208ae2f | 2011-11-07 16:38:03 -0600 | [diff] [blame] | 5 | # Echo commands | 
| Anthony Young | 8655bf0 | 2011-11-07 16:37:00 -0600 | [diff] [blame] | 6 | set -o xtrace | 
 | 7 |  | 
| Anthony Young | 208ae2f | 2011-11-07 16:38:03 -0600 | [diff] [blame] | 8 | # Exit on error to stop unexpected errors | 
| Anthony Young | 8655bf0 | 2011-11-07 16:37:00 -0600 | [diff] [blame] | 9 | set -o errexit | 
 | 10 |  | 
| Anthony Young | e7fa909 | 2011-11-07 16:10:59 -0600 | [diff] [blame] | 11 | # Keep track of the current directory | 
 | 12 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) | 
 | 13 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` | 
 | 14 |  | 
| Anthony Young | 208ae2f | 2011-11-07 16:38:03 -0600 | [diff] [blame] | 15 | # Change dir to top of devstack | 
| Anthony Young | e7fa909 | 2011-11-07 16:10:59 -0600 | [diff] [blame] | 16 | cd $TOP_DIR | 
 | 17 |  | 
 | 18 | # Echo usage | 
 | 19 | usage() { | 
 | 20 |     echo "Cache OpenStack dependencies on a uec image to speed up performance." | 
 | 21 |     echo "" | 
 | 22 |     echo "Usage: $0 [full path to raw uec base image]" | 
 | 23 | } | 
 | 24 |  | 
 | 25 | # Make sure this is a raw image | 
 | 26 | if ! qemu-img info $1 | grep -q "file format: raw"; then | 
 | 27 |     usage | 
 | 28 |     exit 1 | 
 | 29 | fi | 
 | 30 |  | 
| Anthony Young | 8655bf0 | 2011-11-07 16:37:00 -0600 | [diff] [blame] | 31 | # Make sure we are in the correct dir | 
 | 32 | if [ ! -d files/apts ]; then | 
 | 33 |     echo "Please run this script from devstack/tools/" | 
 | 34 |     exit 1 | 
| Hengqing Hu | 3b719e5 | 2012-03-09 16:03:00 +0800 | [diff] [blame] | 35 | fi | 
| Anthony Young | 8655bf0 | 2011-11-07 16:37:00 -0600 | [diff] [blame] | 36 |  | 
| Anthony Young | e7fa909 | 2011-11-07 16:10:59 -0600 | [diff] [blame] | 37 | # Mount the image | 
| Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 38 | STAGING_DIR=/tmp/`echo $1 | sed  "s/\//_/g"`.stage | 
| Anthony Young | e7fa909 | 2011-11-07 16:10:59 -0600 | [diff] [blame] | 39 | mkdir -p $STAGING_DIR | 
| Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 40 | umount $STAGING_DIR || true | 
 | 41 | sleep 1 | 
| Anthony Young | e7fa909 | 2011-11-07 16:10:59 -0600 | [diff] [blame] | 42 | mount -t ext4 -o loop $1 $STAGING_DIR | 
 | 43 |  | 
 | 44 | # Make sure that base requirements are installed | 
 | 45 | cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf | 
 | 46 |  | 
 | 47 | # Perform caching on the base image to speed up subsequent runs | 
 | 48 | chroot $STAGING_DIR apt-get update | 
 | 49 | chroot $STAGING_DIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1` | 
| Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 50 | chroot $STAGING_DIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1` || true | 
| Anthony Young | e228093 | 2011-11-09 22:29:22 -0800 | [diff] [blame] | 51 |  | 
 | 52 | # Unmount | 
| Anthony Young | c1024d8 | 2011-11-09 18:58:07 -0800 | [diff] [blame] | 53 | umount $STAGING_DIR |