Commits

Eric Dowd committed f3e0e54

Merging 32-bit and 64-bit scripts. Adding minimal build

Comments (0)

Files changed (12)

 ./setup_build_gentoo.sh us-east-1
 ```
 
+## build_gentoo.sh
+
+Builds 64 bit Gentoo image. Will use a c1.medium for bootstrap instance.
+
+Will use a t1.micro as test instance.
+
+Because sudo will be called, this script cannot be run in the backgroud.
+
+Recommend running screen before running.
+
+Takes 5 options:
+
+1. architecture
+2. region 
+3. security group
+4. key pair
+5. keyfile
+
+if you do not set these:
+
+* architecture is not optional. The script will give an error. Valid values are: `i386`, `x86_64`
+* region defaults to `us-east-1`
+* security group default to `gentoo-bootstrap_64-bit` and will be created if needed
+* key pair defaults to `gentoo-bootstrap_64-bit_$region` e.g. `gentoo-bootstrap_64-bit_us-east-1`
+* key file defaults to `gentoo-bootstrap_64-bit_$region.pem` e.g. `gentoo-bootstrap_64-bit_us-east-1.pem`
+* key pair will be created if needed.
+
+Default AMI name is Gentoo\_64-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`, but can be changed if the environment variable `AMI_NAME` is set.
+
+Sample command for building 64 bit gentoo on us-east-1
+
+```bash
+./build_gentoo.sh x86_64 us-east-1 gentoo-bootstrap gentoo-bootstrap_us-east-1 gentoo-bootstrap_us-east-1.pem
+```
+
+Sample command for building 32 bit gentoo on us-east-1
+
+```bash
+./build_gentoo.sh i386 us-east-1 gentoo-bootstrap gentoo-bootstrap_us-east-1 gentoo-bootstrap_us-east-1.pem
+```
+
 ## build_gentoo_64.sh
 
 Builds 64 bit Gentoo image. Will use a c1.medium for bootstrap instance.
 if you do not set these:
 
 * region defaults to `us-east-1`
-* security group default to `gentoo-bootstrap_64-bit` and will be created if needed
-* key pair defaults to `gentoo-bootstrap_64-bit_$region` e.g. `gentoo-bootstrap_64-bit_us-east-1`
-* key file defaults to `gentoo-bootstrap_64-bit_$region.pem` e.g. `gentoo-bootstrap_64-bit_us-east-1.pem`
+* security group default to `gentoo-bootstrap` and will be created if needed
+* key pair defaults to `gentoo-bootstrap_$region` e.g. `gentoo-bootstrap_us-east-1`
+* key file defaults to `gentoo-bootstrap_$region.pem` e.g. `gentoo-bootstrap_us-east-1.pem`
 * key pair will be created if needed.
 
 Default AMI name is Gentoo\_64-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`, but can be changed if the environment variable `AMI_NAME` is set.
 if you do not set these:
 
 * region defaults to `us-east-1`
-* security group default to `gentoo-bootstrap_32-bit` and will be created if needed
-* key pair defaults to `gentoo-bootstrap_32-bit_$region` e.g. `gentoo-bootstrap_32-bit_us-east-1`
-* key file defaults to `gentoo-bootstrap_32-bit_$region.pem` e.g. `gentoo-bootstrap_32-bit_us-east-1.pem`
+* security group default to `gentoo-bootstrap` and will be created if needed
+* key pair defaults to `gentoo-bootstrap_$region` e.g. `gentoo-bootstrap_us-east-1`
+* key file defaults to `gentoo-bootstrap_$region.pem` e.g. `gentoo-bootstrap_us-east-1.pem`
 * key pair will be created if needed.
 
 Default AMI name is Gentoo\_32-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`, but can be changed if the environment variable `AMI_NAME` is set.
 ./build_gentoo_32.sh us-east-1 gentoo-bootstrap gentoo-bootstrap_us-east-1 gentoo-bootstrap_us-east-1.pem
 ```
 
-## x86_64/
+## build_minimal_gentoo_64.sh
 
-The contents of this directory will be copied to `/tmp` on the instance building the 64-bit gentoo image.
+Builds a minimal 64 bit Gentoo image. Will use a c1.medium for bootstrap instance.
 
-## i386
+Will use a t1.micro as test instance.
 
-The contents of this directory will be copied to `/tmp` on the instance building the 32-bit gentoo image.
+Because sudo will be called, this script cannot be run in the backgroud.
 
-## x86_64/remote_gentoo.sh & i386/remote_gentoo.sh
+Recommend running screen before running.
 
-The script to be copied to and executed on bootstrap instance.
+Takes 4 options:
 
+1. region 
+2. security group
+3. key pair
+4. keyfile
+
+if you do not set these:
+
+* region defaults to `us-east-1`
+* security group default to `gentoo-bootstrap` and will be created if needed
+* key pair defaults to `gentoo-bootstrap_$region` e.g. `gentoo-bootstrap_us-east-1`
+* key file defaults to `gentoo-bootstrap_$region.pem` e.g. `gentoo-bootstrap_us-east-1.pem`
+* key pair will be created if needed.
+
+Default AMI name is minimal-Gentoo\_64-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`, but can be changed if the environment variable `AMI_NAME` is set.
+
+Sample command for building 64 bit gentoo on us-east-1
+
+```bash
+./build_minimal_gentoo_64.sh us-east-1 gentoo-bootstrap gentoo-bootstrap_us-east-1 gentoo-bootstrap_us-east-1.pem
+```
+
+See the AMI_TYPE section below for more information on this AMI.
+
+## build_minimal_gentoo_32.sh
+
+Builds minimal 32 bit Gentoo image. Will use a c1.medium for bootstrap instance.
+
+Will use a t1.micro as test instance.
+
+Because sudo will be called, this script cannot be run in the backgroud.
+
+Recommend running screen before running.
+
+Takes 4 options:
+
+1. region 
+2. security group
+3. key pair
+4. keyfile
+
+if you do not set these:
+
+* region defaults to `us-east-1`
+* security group default to `gentoo-bootstrap` and will be created if needed
+* key pair defaults to `gentoo-bootstrap_$region` e.g. `gentoo-bootstrap_us-east-1`
+* key file defaults to `gentoo-bootstrap_$region.pem` e.g. `gentoo-bootstrap_us-east-1.pem`
+* key pair will be created if needed.
+
+Default AMI name is minimal-Gentoo\_32-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`, but can be changed if the environment variable `AMI_NAME` is set.
+
+Sample command for building 32 bit gentoo on us-east-1
+
+```bash
+./build_minimal_gentoo_32.sh us-east-1 gentoo-bootstrap gentoo-bootstrap_us-east-1 gentoo-bootstrap_us-east-1.pem
+```
+
+See the AMI_TYPE section below for more information on this AMI.
+
+## remote_gentoo.sh
+
+The script to copied to and executed on bootstrap instance.
+
+## x86_64/
+
+The contents of this directory will be copied to `/tmp` on the instance building the 64-bit gentoo image.
+
+## i386/
+
+The contents of this directory will be copied to `/tmp` on the instance building the 32-bit gentoo image.
 
 ## x86_64/.config & i386/.config
 
 ./copy_ebs_across_region.sh us-east-1 i386 us-west-2
 ```
 
+# AMI_TYPE
+
+Using the `AMI_TYPE` environment variable, variants of the AMI can be built. Currently there is only one value that does anything:
+
+* minimal
+
+## minimal
+
+Will setup a minimal AMI.
+
+The only items in `/var/lib/portage/world` are `app-admin/sudo` and `sys-kernel/gentoo-sources`
+
 # Setup across all regions
 
 Need to setup only once.
+#!/bin/bash
+
+#-------------------------------------------------------------------------------
+# build_gentoo.sh
+#-------------------------------------------------------------------------------
+# Copyright 2012 Dowd and Associates
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#-------------------------------------------------------------------------------
+
+architecture=$1
+
+# The region to install into
+#region="us-east-1"
+region=$2
+
+# The security group to use. 22/tcp needs to be open
+# Leave empty to have a group created
+#group="default"
+group=$3
+
+# The ec2 key pair to use
+# Leave empty to have a key created
+#key="example"
+key=$4
+
+# The fully qualified path to private key of the ec2 key pair
+# Leave empty to have a key created
+#keyfile="$HOME/.ssh/example.pem"
+keyfile=$5
+
+instance_type="c1.medium"
+remove_keypair="false"
+
+#-----
+
+if [ -z $architecture ]; then
+    echo "architecture not set"
+    exit
+elif [ $architecture != "i386" -a $architecture != "x86_64" ]; then
+    echo "Unknown architecture: $architecture"
+    echo "Valid architecture values: i386, x86_64"
+    exit
+fi
+
+if [ $architecture = "x86_64" ]; then
+    if [ -z $AMI_TYPE ]; then
+        building="Gentoo 64 EBS"
+    else
+        building="Gentoo 64 EBS ($AMI_TYPE)"
+    fi
+    default_name="Gentoo_64-bit-EBS"
+else
+    if [ -z $AMI_TYPE ]; then
+        building="Gentoo 32 EBS"
+    else
+        building="Gentoo 32 EBS ($AMI_TYPE)"
+    fi
+    default_name="Gentoo_32-bit-EBS"
+fi
+
+start_time=`date +%Y-%m-%dT%H:%M:%S`
+
+if [[ $region == "" ]]; then
+    region="us-east-1"
+fi
+
+if [[ $group == "" ]]; then
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: set up group"
+    group="gentoo-bootstrap"
+
+    group_exists=`ec2-describe-group \
+            --region $region \
+            --filter group-name=$group \
+            | wc -c`
+
+    if [ $group_exists -eq 0 ]; then
+        ec2-create-group --region $region $group --description "Gentoo Bootstrap"
+    fi
+
+    ec2-authorize --region $region $group -P tcp -p 22 -s 0.0.0.0/0
+
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: group set up"
+fi
+
+if [[ $key == "" || $keyfile == "" ]]; then
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: set up key"
+    key="gentoo-bootstrap_$region-`date +%Y%m%d%H%M%S`"
+    keyfile="${key}.pem"
+   
+    if [ ! -f $keyfile ]; then
+        ec2-add-keypair --region $region $key | sed 1d > $keyfile
+        remove_keypair="true"
+    fi
+
+    chmod 600 $keyfile
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: key set up"
+fi
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: architecture = $architecture"
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: region = $region"
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: group = $group"
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: key = $key"
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: keyfile = $keyfile"
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: AMI_NAME = $AMI_NAME"
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: AMI_TYPE = $AMI_TYPE"
+
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding latest kernel-id"
+
+latest_kernel=`ec2-describe-images \
+--region $region \
+--filter image-type=kernel \
+--filter manifest-location=*pv-grub* \
+--owner amazon \
+--filter architecture=${architecture} \
+| grep -v "hd00" \
+| awk '{ print $3 "\t"  $2 }' \
+| sed "s:.*/pv-grub-hd0[^0-9]*::" \
+| sort \
+| tail -n 1 \
+| awk '{ print $2 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: kernel-id = $latest_kernel"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding bootstrap image"
+
+boot_image=`ec2-describe-images \
+--region $region \
+--owner amazon \
+--filter architecture=${architecture} \
+--filter image-type=machine \
+--filter root-device-type=ebs \
+--filter virtualization-type=paravirtual \
+--filter kernel-id=${latest_kernel} \
+--filter manifest-location=amazon/amzn-ami-pv-* \
+| grep "^IMAGE" \
+| grep -v "amazon/amzn-ami-pv-*.*.rc-*" \
+| tail -n 1 \
+| awk '{ print $2 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap image = $boot_image"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: starting bootstrap instance"
+
+instance=`ec2-run-instances \
+--region $region \
+$boot_image \
+--group $group \
+--key $key \
+--instance-type $instance_type \
+--block-device-mapping "/dev/sdf=:10" \
+| grep "^INSTANCE" \
+| awk '{ print $2 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap instance = $instance"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
+running_check=0
+while [ $running_check -eq 0 ]; do
+    sleep 10
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if instance is running (10 second check)"
+    let running_check="`ec2-describe-instances \
+            --region $region \
+            $instance \
+            --filter instance-state-name=running \
+            | wc -c`"
+done
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
+
+server=`ec2-describe-instances \
+--region $region \
+$instance \
+--filter instance-state-name=running \
+| grep "^INSTANCE" \
+| awk '{ print $4 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: Wait 120 seconds, just in case, for server to finish coming up"
+
+sleep 120
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: copying files to remote server"
+
+scp -o StrictHostKeyChecking=no -i $keyfile -r ${architecture}/* ${architecture}/.[a-zA-Z0-9]* ec2-user@$server:/tmp
+scp -o StrictHostKeyChecking=no -i $keyfile -r remote_gentoo.sh ec2-user@$server:/tmp
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: setting remote_gentoo.sh as executable on remote server"
+
+ssh -o StrictHostKeyChecking=no -i $keyfile ec2-user@$server "chmod 755 /tmp/remote_gentoo.sh"
+ssh -o StrictHostKeyChecking=no -i $keyfile -t ec2-user@$server "sudo /tmp/remote_gentoo.sh ${architecture} $AMI_TYPE"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if install is done"
+
+stopped_check=0
+while [ $stopped_check -eq 0 ]; do
+    sleep 60
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if install is done (1 minute check)"
+    let stopped_check="`ec2-describe-instances \
+            --region $region \
+            $instance \
+            --filter instance-state-name=stopped \
+            | wc -c`"
+done
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: install is done"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: get volume on which gentoo was installed"
+
+volume=`ec2-describe-volumes \
+--region $region \
+--filter attachment.instance-id=$instance \
+--filter attachment.device=/dev/sdf \
+| grep "^VOLUME" \
+| awk '{ print $2 } '`
+
+if [ -z $AMI_TYPE ]; then
+    name=${AMI_NAME:-${default_name}-`date +%Y-%m-%d-%H-%M-%S`}
+else
+    name=${AMI_NAME:-${AMI_TYPE}-${default_name}-`date +%Y-%m-%d-%H-%M-%S`}
+fi
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: creating snapshot"
+
+snapshot=`ec2-create-snapshot \
+--region $region \
+$volume \
+--description $name \
+| awk '{ print $2 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done"
+
+completed_check=0
+while [ $completed_check -eq 0 ]; do
+    sleep 60
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done (1 minute check)"
+    let completed_check="`ec2-describe-snapshots \
+        --region $region \
+        $snapshot \
+        --filter status=completed \
+        | wc -c`"
+done
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: snapshot is done"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: register image"
+
+if [ $architecture = "i386" ]; then
+gentoo_image=`ec2-register \
+--region $region \
+--name $name \
+--description "${building}" \
+--architecture $architecture \
+--kernel $latest_kernel \
+--root-device-name /dev/sda1 \
+--block-device-mapping "/dev/sda1=$snapshot" \
+--block-device-mapping "/dev/sda2=ephemeral0" \
+--block-device-mapping "/dev/sda3=ephemeral1" \
+| awk '{ print $2 }'`
+else
+gentoo_image=`ec2-register \
+--region $region \
+--name $name \
+--description "${building}" \
+--architecture $architecture \
+--kernel $latest_kernel \
+--root-device-name /dev/sda1 \
+--block-device-mapping "/dev/sda1=$snapshot" \
+--block-device-mapping "/dev/sdb=ephemeral0" \
+--block-device-mapping "/dev/sdc=ephemeral1" \
+--block-device-mapping "/dev/sdd=ephemeral2" \
+--block-device-mapping "/dev/sde=ephemeral3" \
+| awk '{ print $2 }'`
+fi
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: image-id = $gentoo_image"
+
+gentoo_instance=`ec2-run-instances \
+--region $region \
+$gentoo_image \
+--group $group \
+--key $key \
+--instance-type t1.micro \
+| grep "^INSTANCE" \
+| awk '{ print $2 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance = $gentoo_instance"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
+running_check=0
+while [ $running_check -eq 0 ]; do
+    sleep 10
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if instance is running (10 second check)"
+    let running_check="`ec2-describe-instances \
+            --region $region \
+            $gentoo_instance \
+            --filter instance-state-name=running \
+            | wc -c`"
+done
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
+
+server=`ec2-describe-instances \
+--region $region \
+$gentoo_instance \
+--filter instance-state-name=running \
+| grep "^INSTANCE" \
+| awk '{ print $4 }'`
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: Wait 120 seconds, just in case, for server to finish coming up"
+
+sleep 120
+
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking connection"
+up_check=`ssh -o StrictHostKeyChecking=no -i $keyfile -t ec2-user@$server "uname -a" | wc -c`
+
+if [ $up_check -ne 0 ]; then
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: connection successful"
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: terminating instances"
+    ec2-terminate-instances --region $region $instance $gentoo_instance
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instances terminated"
+    if [ $remove_keypair = "true" ]; then
+        ec2-delete-keypair --region $region $key
+        rm $keyfile
+    fi
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo image-id = $gentoo_image"
+    echo "To make the image public run the following command:"
+    echo "ec2-modify-image-attribute --region $region $gentoo_image --launch-permission --add all"
+else
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: connection failed"
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: stopping instance"
+    ec2-stop-instances --region $region $gentoo_instance
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance stopped"
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: issue with script, could not verify image. Check instances:"
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap instance: $instance"
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance: $gentoo_instance"
+    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo image-id = $gentoo_image"
+fi
+

build_gentoo_32.sh

 #keyfile="$HOME/.ssh/example.pem"
 keyfile=$4
 
-#-----
-
-building="Gentoo 32 EBS"
-start_time=`date +%Y-%m-%dT%H:%M:%S`
-
-if [[ $region == "" ]]; then
-    region="us-east-1"
-fi
-
-if [[ $group == "" ]]; then
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: set up group"
-    group="gentoo-bootstrap_32-bit"
-
-    group_exists=`ec2-describe-group \
-            --region $region \
-            --filter group-name=$group \
-            | wc -c`
-
-    if [ $group_exists -eq 0 ]; then
-        ec2-create-group --region $region $group --description "Gentoo Bootstrap 32-bit"
-    fi
-
-    ec2-authorize --region $region $group -P tcp -p 22 -s 0.0.0.0/0
-
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: group set up"
-fi
-
-if [[ $key == "" || $keyfile == "" ]]; then
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: set up key"
-    key="gentoo-bootstrap_32-bit_$region"
-    keyfile="gentoo-bootstrap_32-bit_$region.pem"
-   
-    if [ ! -f $keyfile ]; then
-        ec2-add-keypair --region $region $key | sed 1d > $keyfile
-    fi
-
-    chmod 600 $keyfile
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: key set up"
-fi
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: region = $region"
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: group = $group"
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: key = $key"
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: keyfile = $keyfile"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding latest kernel-id"
-
-latest_kernel=`ec2-describe-images \
---region $region \
---filter image-type=kernel \
---filter manifest-location=*pv-grub* \
---owner amazon \
---filter architecture=i386 \
-| grep -v "hd00" \
-| awk '{ print $3 "\t"  $2 }' \
-| sed "s:.*/pv-grub-hd0[^0-9]*::" \
-| sort \
-| tail -n 1 \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: kernel-id = $latest_kernel"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding bootstrap image"
-
-boot_image=`ec2-describe-images \
---region $region \
---owner amazon \
---filter architecture=i386 \
---filter image-type=machine \
---filter root-device-type=ebs \
---filter virtualization-type=paravirtual \
---filter kernel-id=$latest_kernel \
---filter manifest-location=amazon/amzn-ami-* \
-| grep "^IMAGE" \
-| tail -n 1 \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap image = $boot_image"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: starting bootstrap instance"
-
-instance=`ec2-run-instances \
---region $region \
-$boot_image \
---group $group \
---key $key \
---instance-type c1.medium \
---block-device-mapping "/dev/sdf=:10" \
-| grep "^INSTANCE" \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap instance = $instance"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
-running_check=0
-while [ $running_check -eq 0 ]; do
-    sleep 10
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if instance is running (10 second check)"
-    let running_check=`ec2-describe-instances \
-            --region $region \
-            $instance \
-            --filter instance-state-name=running \
-            | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
-
-server=`ec2-describe-instances \
---region $region \
-$instance \
---filter instance-state-name=running \
-| grep "^INSTANCE" \
-| awk '{ print $4 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: Wait 120 seconds, just in case, for server to finish coming up"
-
-sleep 120
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: copying files to remote server"
-
-scp -o StrictHostKeyChecking=no -i $keyfile i386/* i386/.* ec2-user@$server:/tmp
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: setting remote_gentoo.sh as executable on remote server"
-
-ssh -o StrictHostKeyChecking=no -i $keyfile ec2-user@$server "chmod 755 /tmp/remote_gentoo.sh"
-ssh -o StrictHostKeyChecking=no -i $keyfile -t ec2-user@$server "sudo /tmp/remote_gentoo.sh"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if install is done"
-
-stopped_check=0
-while [ $stopped_check -eq 0 ]; do
-    sleep 60
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if install is done (1 minute check)"
-    let stopped_check=`ec2-describe-instances \
-            --region $region \
-            $instance \
-            --filter instance-state-name=stopped \
-            | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: install is done"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: get volume gentoo was installed on"
-volume=`ec2-describe-volumes \
---region $region \
---filter attachment.instance-id=$instance \
---filter attachment.device=/dev/sdf \
-| grep "^VOLUME" \
-| awk '{ print $2 } '`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: volume = $volume"
-
-name=${AMI_NAME:-Gentoo_32-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`}
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: creating snapshot"
-
-snapshot=`ec2-create-snapshot \
---region $region \
-$volume \
---description $name \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done"
-
-completed_check=0
-while [ $completed_check -eq 0 ]; do
-    sleep 60
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done (1 minute check)"
-    let completed_check=`ec2-describe-snapshots \
-        --region $region \
-        $snapshot \
-        --filter status=completed \
-        | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: snapshot is done"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: register image"
-
-gentoo_image=`ec2-register \
---region $region \
---name $name \
---description "Gentoo 32-bit EBS" \
---architecture i386 \
---kernel $latest_kernel \
---root-device-name /dev/sda1 \
---block-device-mapping "/dev/sda1=$snapshot" \
---block-device-mapping "/dev/sda2=ephemeral0" \
---block-device-mapping "/dev/sda3=ephemeral1" \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: image-id = $gentoo_image"
-
-gentoo_instance=`ec2-run-instances \
---region $region \
-$gentoo_image \
---group $group \
---key $key \
---instance-type t1.micro \
-| grep "^INSTANCE" \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance = $gentoo_instance"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
-running_check=0
-while [ $running_check -eq 0 ]; do
-    sleep 10
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if instance is running (10 second check)"
-    let running_check=`ec2-describe-instances \
-            --region $region \
-            $gentoo_instance \
-            --filter instance-state-name=running \
-            | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
-
-server=`ec2-describe-instances \
---region $region \
-$gentoo_instance \
---filter instance-state-name=running \
-| grep "^INSTANCE" \
-| awk '{ print $4 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: Wait 120 seconds, just in case, for server to finish coming up"
-
-sleep 120
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking connection"
-up_check=`ssh -o StrictHostKeyChecking=no -i $keyfile -t ec2-user@$server "uname -a" | wc -c`
-
-if [ $up_check -ne 0 ]; then
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: connection successful"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: terminating instances"
-    ec2-terminate-instances --region $region $instance $gentoo_instance
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instances terminated"
-else
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: connection failed"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: stopping instance"
-    ec2-stop-instances --region $region $gentoo_instance
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance stopped"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap instance: $instance"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance: $gentoo_instance"
-fi
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo image-id = $gentoo_image"
-echo "-----"
-echo "ec2-modify-image-attribute --region $region $gentoo_image --launch-permission --add all"
-echo "<tr><td>$region</td><td>$gentoo_image</td><td>i386</td><td>ebs</td><td>$latest_kernel</td><td>$name</td></tr>"
+unset AMI_TYPE
+./build_gentoo.sh i386 $region $group $key $keyfile
 

build_gentoo_64.sh

 #keyfile="$HOME/.ssh/example.pem"
 keyfile=$4
 
-#-----
-
-building="Gentoo 64 EBS"
-start_time=`date +%Y-%m-%dT%H:%M:%S`
-
-if [[ $region == "" ]]; then
-    region="us-east-1"
-fi
-
-if [[ $group == "" ]]; then
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: set up group"
-    group="gentoo-bootstrap_64-bit"
-
-    group_exists=`ec2-describe-group \
-            --region $region \
-            --filter group-name=$group \
-            | wc -c`
-
-    if [ $group_exists -eq 0 ]; then
-        ec2-create-group --region $region $group --description "Gentoo Bootstrap 64-bit"
-    fi
-
-    ec2-authorize --region $region $group -P tcp -p 22 -s 0.0.0.0/0
-
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: group set up"
-fi
-
-if [[ $key == "" || $keyfile == "" ]]; then
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: set up key"
-    key="gentoo-bootstrap_64-bit_$region"
-    keyfile="gentoo-bootstrap_64-bit_$region.pem"
-   
-    if [ ! -f $keyfile ]; then
-        ec2-add-keypair --region $region $key | sed 1d > $keyfile
-    fi
-
-    chmod 600 $keyfile
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: key set up"
-fi
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: region = $region"
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: group = $group"
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: key = $key"
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: keyfile = $keyfile"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding latest kernel-id"
-
-latest_kernel=`ec2-describe-images \
---region $region \
---filter image-type=kernel \
---filter manifest-location=*pv-grub* \
---owner amazon \
---filter architecture=x86_64 \
-| grep -v "hd00" \
-| awk '{ print $3 "\t"  $2 }' \
-| sed "s:.*/pv-grub-hd0[^0-9]*::" \
-| sort \
-| tail -n 1 \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: kernel-id = $latest_kernel"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding bootstrap image"
-
-boot_image=`ec2-describe-images \
---region $region \
---owner amazon \
---filter architecture=x86_64 \
---filter image-type=machine \
---filter root-device-type=ebs \
---filter virtualization-type=paravirtual \
---filter kernel-id=$latest_kernel \
---filter manifest-location=amazon/amzn-ami-* \
-| grep "^IMAGE" \
-| tail -n 1 \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap image = $boot_image"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: starting bootstrap instance"
-
-instance=`ec2-run-instances \
---region $region \
-$boot_image \
---group $group \
---key $key \
---instance-type c1.medium \
---block-device-mapping "/dev/sdf=:10" \
-| grep "^INSTANCE" \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap instance = $instance"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
-running_check=0
-while [ $running_check -eq 0 ]; do
-    sleep 10
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if instance is running (10 second check)"
-    let running_check=`ec2-describe-instances \
-            --region $region \
-            $instance \
-            --filter instance-state-name=running \
-            | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
-
-server=`ec2-describe-instances \
---region $region \
-$instance \
---filter instance-state-name=running \
-| grep "^INSTANCE" \
-| awk '{ print $4 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: Wait 120 seconds, just in case, for server to finish coming up"
-
-sleep 120
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: copying files to remote server"
-
-scp -o StrictHostKeyChecking=no -i $keyfile x86_64/* x86_64/.* ec2-user@$server:/tmp
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: setting remote_gentoo.sh as executable on remote server"
-
-ssh -o StrictHostKeyChecking=no -i $keyfile ec2-user@$server "chmod 755 /tmp/remote_gentoo.sh"
-ssh -o StrictHostKeyChecking=no -i $keyfile -t ec2-user@$server "sudo /tmp/remote_gentoo.sh"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if install is done"
-
-stopped_check=0
-while [ $stopped_check -eq 0 ]; do
-    sleep 60
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if install is done (1 minute check)"
-    let stopped_check=`ec2-describe-instances \
-            --region $region \
-            $instance \
-            --filter instance-state-name=stopped \
-            | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: install is done"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: get volume gentoo was installed on"
-
-volume=`ec2-describe-volumes \
---region $region \
---filter attachment.instance-id=$instance \
---filter attachment.device=/dev/sdf \
-| grep "^VOLUME" \
-| awk '{ print $2 } '`
-
-name=${AMI_NAME:-Gentoo_64-bit-EBS-`date +%Y-%m-%d-%H-%M-%S`}
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: creating snapshot"
-
-snapshot=`ec2-create-snapshot \
---region $region \
-$volume \
---description $name \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done"
-
-completed_check=0
-while [ $completed_check -eq 0 ]; do
-    sleep 60
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done (1 minute check)"
-    let completed_check=`ec2-describe-snapshots \
-        --region $region \
-        $snapshot \
-        --filter status=completed \
-        | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: snapshot is done"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: register image"
-
-gentoo_image=`ec2-register \
---region $region \
---name $name \
---description "Gentoo 64-bit EBS" \
---architecture x86_64 \
---kernel $latest_kernel \
---root-device-name /dev/sda1 \
---block-device-mapping "/dev/sda1=$snapshot" \
---block-device-mapping "/dev/sdb=ephemeral0" \
---block-device-mapping "/dev/sdc=ephemeral1" \
---block-device-mapping "/dev/sdd=ephemeral2" \
---block-device-mapping "/dev/sde=ephemeral3" \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: image-id = $gentoo_image"
-
-gentoo_instance=`ec2-run-instances \
---region $region \
-$gentoo_image \
---group $group \
---key $key \
---instance-type t1.micro \
-| grep "^INSTANCE" \
-| awk '{ print $2 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance = $gentoo_instance"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
-running_check=0
-while [ $running_check -eq 0 ]; do
-    sleep 10
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if instance is running (10 second check)"
-    let running_check=`ec2-describe-instances \
-            --region $region \
-            $gentoo_instance \
-            --filter instance-state-name=running \
-            | wc -c`
-done
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
-
-server=`ec2-describe-instances \
---region $region \
-$gentoo_instance \
---filter instance-state-name=running \
-| grep "^INSTANCE" \
-| awk '{ print $4 }'`
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: Wait 120 seconds, just in case, for server to finish coming up"
-
-sleep 120
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking connection"
-up_check=`ssh -o StrictHostKeyChecking=no -i $keyfile -t ec2-user@$server "uname -a" | wc -c`
-
-if [ $up_check -ne 0 ]; then
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: connection successful"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: terminating instances"
-    ec2-terminate-instances --region $region $instance $gentoo_instance
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instances terminated"
-else
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: connection failed"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: stopping instance"
-    ec2-stop-instances --region $region $gentoo_instance
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance stopped"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: bootstrap instance: $instance"
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance: $gentoo_instance"
-fi
-
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo image-id = $gentoo_image"
-echo "-----"
-echo "ec2-modify-image-attribute --region $region $gentoo_image --launch-permission --add all"
-echo "<tr><td>$region</td><td>$gentoo_image</td><td>x86_64</td><td>ebs</td><td>$latest_kernel</td><td>$name</td></tr>"
+unset AMI_TYPE
+./build_gentoo.sh x86_64 $region $group $key $keyfile
 

build_minimal_gentoo_32.sh

+#!/bin/bash
+
+#-------------------------------------------------------------------------------
+# build_minimal_gentoo_32.sh
+#-------------------------------------------------------------------------------
+# Copyright 2012 Dowd and Associates
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#-------------------------------------------------------------------------------
+
+# The region to install into
+#region="us-east-1"
+region=$1
+
+# The security group to use. 22/tcp needs to be open
+# Leave empty to have a group created
+#group="default"
+group=$2
+
+# The ec2 key pair to use
+# Leave empty to have a key created
+#key="example"
+key=$3
+
+# The fully qualified path to private key of the ec2 key pair
+# Leave empty to have a key created
+#keyfile="$HOME/.ssh/example.pem"
+keyfile=$4
+
+AMI_TYPE="minimal"
+
+./build_gentoo.sh i386 $region $group $key $keyfile

build_minimal_gentoo_64.sh

+#!/bin/bash
+
+#-------------------------------------------------------------------------------
+# build_minimal_gentoo_64.sh
+#-------------------------------------------------------------------------------
+# Copyright 2012 Dowd and Associates
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#-------------------------------------------------------------------------------
+
+# The region to install into
+#region="us-east-1"
+region=$1
+
+# The security group to use. 22/tcp needs to be open
+# Leave empty to have a group created
+#group="default"
+group=$2
+
+# The ec2 key pair to use
+# Leave empty to have a key created
+#key="example"
+key=$3
+
+# The fully qualified path to private key of the ec2 key pair
+# Leave empty to have a key created
+#keyfile="$HOME/.ssh/example.pem"
+keyfile=$4
+
+AMI_TYPE="minimal"
+
+./build_gentoo.sh x86_64 $region $group $key $keyfile

copy_ebs_across_region.sh

 to_region=$3
 
 if [[ $architecture == "x86_64" ]]; then
-    building="Gentoo 64 EBS"
-	ami_description="Gentoo 64-bit EBS"
+    if [ -z $AMI_TYPE ]; then
+        building="Gentoo 64 EBS"
+    	ami_description="Gentoo 64-bit EBS"
+    else
+        building="Gentoo 64 EBS ($AMI_TYPE)"
+    	ami_description="$AMI_TYPE Gentoo 64-bit EBS"
+    fi
 elif [[ $architecture == "i386" ]]; then
-	building="Gentoo 32 EBS"
-	ami_description="Gentoo 32-bit EBS"
+    if [ -z $AMI_TYPE ]; then
+        building="Gentoo 32 EBS"
+    	ami_description="Gentoo 32-bit EBS"
+    else
+        building="Gentoo 32 EBS ($AMI_TYPE)"
+    	ami_description="$AMI_TYPE Gentoo 32-bit EBS"
+    fi
 else
 	echo "Unknown architecture: $architecture"
 	echo "valid values for architecture: x86_64, i386"
 
 start_time=`date +%Y-%m-%dT%H:%M:%S`
 
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: AMI_TYPE = $AMI_TYPE"
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: from_region = $from_region"
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: architecture = $architecture"
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: to_region = $to_region"
 
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding latest image"
 
+if [ -z $AMI_TYPE ]; then
+    manifest_location="*/Gentoo_*"
+else
+    manifest_location="*/{$AMI_TYPE}-Gentoo_*"
+fi
+
 latest_image=`ec2-describe-images \
 --region $from_region \
 --owner self \
 --filter image-type=machine \
 --filter is-public=true \
---filter manifest-location=*/Gentoo_* \
+--filter manifest-location=${manifest_location} \
 --filter architecture=$architecture \
 --filter root-device-type=ebs \
 | grep "^IMAGE" \

i386/remote_gentoo.sh

-
-#-------------------------------------------------------------------------------
-# i386/remote_gentoo.sh
-#-------------------------------------------------------------------------------
-# Copyright 2012 Dowd and Associates
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#-------------------------------------------------------------------------------
-
-echo "mkfs -t ext4 /dev/xvdf"
-mkfs -t ext4 /dev/xvdf
-echo "mkdir -p /mnt/gentoo"
-mkdir -p /mnt/gentoo
-
-mount /dev/xvdf /mnt/gentoo
-
-cd /tmp
-echo "Download stage3"
-curl -O http://gentoo.mirrors.pair.com/releases/x86/autobuilds/`curl --silent http://gentoo.mirrors.pair.com/releases/x86/autobuilds/latest-stage3-i686.txt | grep stage3-i686`
-echo "Download portage"
-curl -O http://gentoo.mirrors.pair.com/snapshots/portage-latest.tar.bz2
-echo "Unpack stage3"
-tar -xjpf /tmp/stage3-*.tar.bz2 -C /mnt/gentoo
-echo "Unpack portage"
-tar -xjf /tmp/portage*.tar.bz2 -C /mnt/gentoo/usr
-
-echo "Setup files"
-
-mkdir -p /mnt/gentoo/boot/grub
-echo "/boot/grub/menu.lst"
-cat <<'EOF'>/mnt/gentoo/boot/grub/menu.lst
-default 0
-timeout 3
-title EC2
-root (hd0)
-kernel /boot/bzImage root=/dev/xvda1 rootfstype=ext4
-EOF
-
-echo "/etc/fstab"
-cat <<'EOF'>/mnt/gentoo/etc/fstab
-/dev/xvda1 / ext4 defaults 1 1
-/dev/xvda3 none swap sw 0 0
-none /dev/pts devpts gid=5,mode=620 0 0
-none /dev/shm tmpfs defaults 0 0
-none /proc proc defaults 0 0
-none /sys sysfs defaults 0 0
-EOF
-
-mkdir -p /mnt/gentoo/etc/local.d
-echo "/etc/local.d/killall_nash-hotplug.start"
-cat <<'EOF'>/mnt/gentoo/etc/local.d/killall_nash-hotplug.start
-# /etc/local.d/killall_nash-hotplug.start
-
-killall nash-hotplug
-EOF
-chmod 755 /mnt/gentoo/etc/local.d/killall_nash-hotplug.start
-
-echo "/etc/local.d/public-keys.start"
-cat <<'EOF'>/mnt/gentoo/etc/local.d/public-keys.start
-# /etc/local.d/public-keys.start
-
-[ ! -e /home/ec2-user ] && cp -r /etc/skel /home/ec2-user && chown -R ec2-user /home/ec2-user && chgrp -R ec2-user /home/ec2-user
-if [ ! -d /home/ec2-user/.ssh ] ; then
-mkdir -p /home/ec2-user/.ssh
-chmod 700 /home/ec2-user/.ssh
-chown ec2-user /home/ec2-user/.ssh
-chgrp ec2-user /home/ec2-user/.ssh
-fi
-curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/my-key
-if [ $? -eq 0 ] ; then
-cat /tmp/my-key >> /home/ec2-user/.ssh/authorized_keys
-chmod 600 /home/ec2-user/.ssh/authorized_keys
-chown ec2-user /home/ec2-user/.ssh/authorized_keys
-chgrp ec2-user /home/ec2-user/.ssh/authorized_keys
-rm /tmp/my-key
-fi
-EOF
-chmod 755 /mnt/gentoo/etc/local.d/public-keys.start
-
-echo "/etc/local.d/public-keys.stop"
-cat <<'EOF'>/mnt/gentoo/etc/local.d/public-keys.stop
-# /etc/local.d/public-keys.stop
-
-rm -f /home/ec2-user/.ssh/authorized_keys
-EOF
-chmod 755 /mnt/gentoo/etc/local.d/public-keys.stop
-
-mkdir -p /mnt/gentoo/etc/portage
-
-echo "/etc/portage/make.conf"
-cat <<'EOF'>/mnt/gentoo/etc/portage/make.conf
-# These settings were set by the catalyst build script that automatically
-# built this stage.
-# Please consult /usr/share/portage/config/make.conf.example for a more
-# detailed example.
-CFLAGS="-O2 -march=i686 -mno-tls-direct-seg-refs -pipe"
-CXXFLAGS="${CFLAGS}"
-# WARNING: Changing your CHOST is not something that should be done lightly.
-# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
-CHOST="i686-pc-linux-gnu"
-MAKEOPTS="-j3"
-EMERGE_DEFAULT_OPTS= "--jobs=2 --load-average=3.0"
-EOF
-
-echo "/etc/resolv.conf"
-cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
-
-mkdir -p /mnt/gentoo/etc/sudoers.d
-echo "/etc/sudoers.d/ec2-user"
-cat <<'EOF'>/mnt/gentoo/etc/sudoers.d/ec2-user
-ec2-user  ALL=(ALL) NOPASSWD:ALL
-EOF
-chmod 440 /mnt/gentoo/etc/sudoers.d/ec2-user
-
-echo "/etc/sudoers.d/_sudo"
-cat <<'EOF'>/mnt/gentoo/etc/sudoers.d/_sudo
-%sudo     ALL=(ALL) ALL
-EOF
-chmod 440 /mnt/gentoo/etc/sudoers.d/_sudo
-
-echo "/usr/src/linux/.config"
-mkdir -p /mnt/gentoo/tmp
-cp /tmp/.config /mnt/gentoo/tmp/.config
-
-mkdir -p /mnt/gentoo/var/lib/portage
-echo "/var/lib/portage/world"
-cat <<'EOF'>/mnt/gentoo/var/lib/portage/world
-app-admin/logrotate
-app-admin/sudo
-app-admin/syslog-ng
-app-arch/unzip
-app-editors/nano
-app-editors/vim
-app-misc/screen
-app-portage/eix
-app-portage/gentoolkit
-dev-vcs/git
-net-misc/curl
-net-misc/dhcpcd
-net-misc/ntp
-sys-fs/lvm2
-sys-fs/mdadm
-sys-kernel/gentoo-sources
-sys-process/atop
-sys-process/fcron
-sys-process/htop
-EOF
-
-echo "/tmp/build.sh"
-
-cat <<'EOF'>/mnt/gentoo/tmp/build.sh
-#!/bin/bash
-
-env-update
-source /etc/profile
-
-emerge --sync
-
-cp /usr/share/zoneinfo/GMT /etc/localtime
-
-eselect profile set default/linux/x86/13.0
-emerge --oneshot sys-apps/portage
-emerge --unmerge sys-apps/module-init-tools
-emerge --update --deep --with-bdeps=y --newuse @world
-
-cd /usr/src/linux
-mv /tmp/.config ./.config
-yes "" | make oldconfig
-make -j3 && make -j3 modules_install
-cp -L arch/x86/boot/bzImage /boot/bzImage
-
-groupadd sudo
-useradd -r -m -s /bin/bash ec2-user
-
-ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
-
-rc-update add net.eth0 default
-rc-update add sshd default
-rc-update add syslog-ng default
-rc-update add fcron default
-rc-update add ntpd default
-rc-update add lvm boot
-rc-update add mdraid boot
-
-mv /etc/portage/make.conf /etc/portage/make.conf.bkup
-sed "s/MAKEOPTS=\"-j.*\"/MAKEOPTS=\"-j2\"/g" /etc/portage/make.conf.bkup > /etc/portage/make.conf
-rm /etc/portage/make.conf.bkup
-
-EOF
-
-chmod 755 /mnt/gentoo/tmp/build.sh
-
-mount -t proc none /mnt/gentoo/proc
-mount --rbind /dev /mnt/gentoo/dev
-mount --rbind /dev/pts /mnt/gentoo/dev/pts
-
-chroot /mnt/gentoo /tmp/build.sh
-
-rm -fR /mnt/gentoo/tmp/*
-rm -fR /mnt/gentoo/var/tmp/*
-rm -fR /mnt/gentoo/usr/portage/distfiles/*
-
-shutdown -h now

list_gentoo_images.sh

 | head -n 1
 }
 
+function current_minimal_image
+{
+ec2-describe-images \
+--region $1 \
+--owner $OWNER \
+--filter image-type=machine \
+--filter is-public=true \
+--filter manifest-location=*/minimal-Gentoo_* \
+--filter architecture=$3 \
+--filter root-device-type=$2 \
+| grep "^IMAGE" \
+| awk '{ print $3 $0 }' \
+| sort -r \
+| awk '{ print "<tr><td>$REGION</td><td><a href=\"https://console.aws.amazon.com/ec2/home?region=$REGION#launchAmi="$2"\">"$2"</a></td><td>"$7"</td><td>"$10"</td><td>"$9"</td><td>"$3"</td></tr>" }' \
+| sed -e "s/<td>[^<]*\/Gentoo/<td>Gentoo/g" \
+| sed -e "s/\$REGION/$1/g" \
+| head -n 1
+}
+
 function old_images
 {
 ec2-describe-images \
 | tail -n +2
 }
 
+function old_minimal_images
+{
+ec2-describe-images \
+--region $1 \
+--owner $OWNER \
+--filter image-type=machine \
+--filter is-public=true \
+--filter manifest-location=*/minimal-Gentoo_* \
+--filter architecture=$3 \
+--filter root-device-type=$2 \
+| grep "^IMAGE" \
+| awk '{ print $3 $0 }' \
+| sort -r \
+| awk '{ print "<tr><td>$REGION</td><td><a href=\"https://console.aws.amazon.com/ec2/home?region=$REGION#launchAmi="$2"\">"$2"</a></td><td>"$7"</td><td>"$10"</td><td>"$9"</td><td>"$3"</td></tr>" }' \
+| sed -e "s/<td>[^<]*\/Gentoo/<td>Gentoo/g" \
+| sed -e "s/\$REGION/$1/g" \
+| tail -n +2
+}
+
 function start_current_images
 {
 echo "<table>"
 echo "</table>"
 }
 
+function start_current_minimal_images
+{
+echo "<hr>"
+echo "<p>Minimal Images</p>"
+echo "<table>"
+echo "<thead>"
+echo "<tr><th>Region</th><th>Image ID</th><th>Architecture</th><th>Root Device Type</th><th>Kernel ID</th><th>Name</th></tr>"
+echo "</thead>"
+echo "<tbody>"
+}
+
+function end_current_minimal_images
+{
+echo "</tbody>"
+echo "</table>"
+}
+
 function start_old_images
 {
 echo "<hr>"
 echo "</table>"
 }
 
+function start_old_minimal_images
+{
+echo "<hr>"
+echo "<p>Old Minimal Images</p>"
+echo "<table>"
+echo "<thead>"
+echo "<tr><th>Region</th><th>Image ID</th><th>Architecture</th><th>Root Device Type</th><th>Kernel ID</th><th>Name</th></tr>"
+echo "</thead>"
+echo "<tbody>"
+}
+
+function end_old_minimal_images
+{
+echo "</tbody>"
+echo "</table>"
+}
+
 function intro
 {
 echo "<p>Dowd and Associates is proud to offer <a href=\"http://www.gentoo.org/\">Gentoo Linux</a> images on Amazon's EC2 Service.</p>"
 current_image "us-west-2" "instance-store" "x86_64"
 
 end_current_images
+
+start_current_minmal_images
+
+current_minimal_image "ap-northeast-1" "ebs" "i386"
+current_minimal_image "ap-northeast-1" "ebs" "x86_64"
+current_minimal_image "ap-northeast-1" "instance-store" "i386"
+current_minimal_image "ap-northeast-1" "instance-store" "x86_64"
+
+current_minimal_image "ap-southeast-1" "ebs" "i386"
+current_minimal_image "ap-southeast-1" "ebs" "x86_64"
+current_minimal_image "ap-southeast-1" "instance-store" "i386"
+current_minimal_image "ap-southeast-1" "instance-store" "x86_64"
+
+current_minimal_image "ap-southeast-2" "ebs" "i386"
+current_minimal_image "ap-southeast-2" "ebs" "x86_64"
+current_minimal_image "ap-southeast-2" "instance-store" "i386"
+current_minimal_image "ap-southeast-2" "instance-store" "x86_64"
+
+current_minimal_image "eu-west-1" "ebs" "i386"
+current_minimal_image "eu-west-1" "ebs" "x86_64"
+current_minimal_image "eu-west-1" "instance-store" "i386"
+current_minimal_image "eu-west-1" "instance-store" "x86_64"
+
+current_minimal_image "sa-east-1" "ebs" "i386"
+current_minimal_image "sa-east-1" "ebs" "x86_64"
+current_minimal_image "sa-east-1" "instance-store" "i386"
+current_minimal_image "sa-east-1" "instance-store" "x86_64"
+
+current_minimal_image "us-east-1" "ebs" "i386"
+current_minimal_image "us-east-1" "ebs" "x86_64"
+current_minimal_image "us-east-1" "instance-store" "i386"
+current_minimal_image "us-east-1" "instance-store" "x86_64"
+
+current_minimal_image "us-west-1" "ebs" "i386"
+current_minimal_image "us-west-1" "ebs" "x86_64"
+current_minimal_image "us-west-1" "instance-store" "i386"
+current_minimal_image "us-west-1" "instance-store" "x86_64"
+
+current_minimal_image "us-west-2" "ebs" "i386"
+current_minimal_image "us-west-2" "ebs" "x86_64"
+current_minimal_image "us-west-2" "instance-store" "i386"
+current_minimal_image "us-west-2" "instance-store" "x86_64"
+
+end_current_minimal_images
+
 start_old_images
 
 old_images "ap-northeast-1" "ebs" "i386"
 
 end_old_images
 
+start_old_minimal_images
+
+old_minimal_images "ap-northeast-1" "ebs" "i386"
+old_minimal_images "ap-northeast-1" "ebs" "x86_64"
+old_minimal_images "ap-northeast-1" "instance-store" "i386"
+old_minimal_images "ap-northeast-1" "instance-store" "x86_64"
+
+old_minimal_images "ap-southeast-1" "ebs" "i386"
+old_minimal_images "ap-southeast-1" "ebs" "x86_64"
+old_minimal_images "ap-southeast-1" "instance-store" "i386"
+old_minimal_images "ap-southeast-1" "instance-store" "x86_64"
+
+old_minimal_images "ap-southeast-2" "ebs" "i386"
+old_minimal_images "ap-southeast-2" "ebs" "x86_64"
+old_minimal_images "ap-southeast-2" "instance-store" "i386"
+old_minimal_images "ap-southeast-2" "instance-store" "x86_64"
+
+old_minimal_images "eu-west-1" "ebs" "i386"
+old_minimal_images "eu-west-1" "ebs" "x86_64"
+old_minimal_images "eu-west-1" "instance-store" "i386"
+old_minimal_images "eu-west-1" "instance-store" "x86_64"
+
+old_minimal_images "sa-east-1" "ebs" "i386"
+old_minimal_images "sa-east-1" "ebs" "x86_64"
+old_minimal_images "sa-east-1" "instance-store" "i386"
+old_minimal_images "sa-east-1" "instance-store" "x86_64"
+
+old_minimal_images "us-east-1" "ebs" "i386"
+old_minimal_images "us-east-1" "ebs" "x86_64"
+old_minimal_images "us-east-1" "instance-store" "i386"
+old_minimal_images "us-east-1" "instance-store" "x86_64"
+
+old_minimal_images "us-west-1" "ebs" "i386"
+old_minimal_images "us-west-1" "ebs" "x86_64"
+old_minimal_images "us-west-1" "instance-store" "i386"
+old_minimal_images "us-west-1" "instance-store" "x86_64"
+
+old_minimal_images "us-west-2" "ebs" "i386"
+old_minimal_images "us-west-2" "ebs" "x86_64"
+old_minimal_images "us-west-2" "instance-store" "i386"
+old_minimal_images "us-west-2" "instance-store" "x86_64"
+
+end_old_minimal_images
+

make_latest_public.sh

 
 start_time=`date +%Y-%m-%dT%H:%M:%S`
 
+echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: AMI_TYPE = $AMI_TYPE"
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: region = $region"
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: architecture = $architecture"
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: root_device_type = $root_device_type"
 
 echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding latest image"
 
+if [ -z $AMI_TYPE ]; then
+    manifest_location="*/Gentoo_*"
+else
+    manifest_location="*/{$AMI_TYPE}-Gentoo_*"
+fi
+
 latest_image=`ec2-describe-images \
 --region $region \
 --owner self \
 --filter image-type=machine \
---filter manifest-location=*/Gentoo_* \
+--filter manifest-location=${manifest_location} \
 --filter architecture=$architecture \
 --filter root-device-type=$root_device_type \
 | grep "^IMAGE" \
+
+#-------------------------------------------------------------------------------
+# remote_gentoo.sh
+#-------------------------------------------------------------------------------
+# Copyright 2012 Dowd and Associates
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#-------------------------------------------------------------------------------
+
+ARCHITECTURE=$1
+TYPE=$2
+
+if [ -z $ARCHITECTURE ]; then
+    echo "Architecture not set"
+    exit
+fi
+
+if [ $ARCHITECTURE != "i386" -a $ARCHITECTURE != "x86_64" ]; then
+    echo "Unknown architecture: $ARCHITECTURE"
+    echo "Valid architecture values: i386, x86_64"
+    exit
+fi
+
+if [ -z $TYPE ]; then
+    TYPE="normal"
+fi
+
+echo "mkfs -t ext4 /dev/xvdf"
+mkfs -t ext4 /dev/xvdf
+echo "mkdir -p /mnt/gentoo"
+mkdir -p /mnt/gentoo
+
+mount /dev/xvdf /mnt/gentoo
+
+cd /tmp
+echo "Download stage3"
+if [[ $ARCHITECTURE == "i386" ]]; then
+curl -O http://gentoo.mirrors.pair.com/releases/x86/autobuilds/`curl --silent http://gentoo.mirrors.pair.com/releases/x86/autobuilds/latest-stage3-i686.txt | grep stage3-i686`
+else
+curl -O http://gentoo.mirrors.pair.com/releases/amd64/autobuilds/`curl --silent http://gentoo.mirrors.pair.com/releases/amd64/autobuilds/latest-stage3-amd64.txt | grep stage3-amd64`
+fi
+echo "Download portage"
+curl -O http://gentoo.mirrors.pair.com/snapshots/portage-latest.tar.bz2
+echo "Unpack stage3"
+tar -xjpf /tmp/stage3-*.tar.bz2 -C /mnt/gentoo
+echo "Unpack portage"
+tar -xjf /tmp/portage*.tar.bz2 -C /mnt/gentoo/usr
+
+echo "Setup files"
+
+mkdir -p /mnt/gentoo/boot/grub
+echo "/boot/grub/menu.lst"
+cat <<'EOF'>/mnt/gentoo/boot/grub/menu.lst
+default 0
+timeout 3
+title EC2
+root (hd0)
+kernel /boot/bzImage root=/dev/xvda1 rootfstype=ext4
+EOF
+
+if [[ $ARCHITECTURE = "i386" ]]; then
+echo "/etc/fstab"
+cat <<'EOF'>/mnt/gentoo/etc/fstab
+/dev/xvda1 / ext4 defaults 1 1
+/dev/xvda3 none swap sw 0 0
+none /dev/pts devpts gid=5,mode=620 0 0
+none /dev/shm tmpfs defaults 0 0
+none /proc proc defaults 0 0
+none /sys sysfs defaults 0 0
+EOF
+else
+echo "/etc/fstab"
+cat <<'EOF'>/mnt/gentoo/etc/fstab
+/dev/xvda1 / ext4 defaults 1 1
+none /dev/pts devpts gid=5,mode=620 0 0
+none /dev/shm tmpfs defaults 0 0
+none /proc proc defaults 0 0
+none /sys sysfs defaults 0 0
+EOF
+fi
+
+mkdir -p /mnt/gentoo/etc/local.d
+
+echo "/etc/local.d/public-keys.start"
+cat <<'EOF'>/mnt/gentoo/etc/local.d/public-keys.start
+# /etc/local.d/public-keys.start
+
+[ ! -e /home/ec2-user ] && cp -r /etc/skel /home/ec2-user && chown -R ec2-user /home/ec2-user && chgrp -R ec2-user /home/ec2-user
+if [ ! -d /home/ec2-user/.ssh ] ; then
+mkdir -p /home/ec2-user/.ssh
+chmod 700 /home/ec2-user/.ssh
+chown ec2-user /home/ec2-user/.ssh
+chgrp ec2-user /home/ec2-user/.ssh
+fi
+wget -q -O /tmp/my-key http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key
+if [ $? -eq 0 ] ; then
+cat /tmp/my-key > /home/ec2-user/.ssh/authorized_keys
+chmod 600 /home/ec2-user/.ssh/authorized_keys
+chown ec2-user /home/ec2-user/.ssh/authorized_keys
+chgrp ec2-user /home/ec2-user/.ssh/authorized_keys
+rm /tmp/my-key
+fi
+EOF
+chmod 755 /mnt/gentoo/etc/local.d/public-keys.start
+
+echo "/etc/local.d/public-keys.stop"
+cat <<'EOF'>/mnt/gentoo/etc/local.d/public-keys.stop
+# /etc/local.d/public-keys.stop
+
+rm -f /home/ec2-user/.ssh/authorized_keys
+EOF
+chmod 755 /mnt/gentoo/etc/local.d/public-keys.stop
+
+if [[ $TYPE != "minimal" ]]; then
+    echo "/etc/local.d/killall_nash-hotplug.start"
+cat <<'EOF'>/mnt/gentoo/etc/local.d/killall_nash-hotplug.start
+# /etc/local.d/killall_nash-hotplug.start
+
+killall nash-hotplug
+EOF
+    chmod 755 /mnt/gentoo/etc/local.d/killall_nash-hotplug.start
+
+    echo "/etc/local.d/makeopts.start"
+cat <<'EOF'>/mnt/gentoo/etc/local.d/makeopts.start
+# /etc/local.d/makeopts.start
+
+cp /etc/portage/make.conf /etc/portage/make.conf.orig
+sed \
+-e "s/MAKEOPTS=.*/MAKEOPTS=\"-j`grep "^processor" /proc/cpuinfo | awk '{ print $3 + 2 }'`\"/g" \
+/etc/portage/make.conf.orig \
+| sed \
+-e "s/EMERGE_DEFAULT_OPTS=.*/EMERGE_DEFAULT_OPTS=\"--jobs=`grep "^processor" /proc/cpuinfo | awk '{ print $3 + 1 }'` --load-average=`grep "^processor" /proc/cpuinfo | awk '{ print $3 + 2 }'`.0\"/g" \
+> /etc/portage/make.conf
+EOF
+    chmod 755 /mnt/gentoo/etc/local.d/makeopts.start
+fi
+
+mkdir -p /mnt/gentoo/etc/portage
+
+echo "/etc/portage/make.conf"
+if [[ $ARCHITECTURE == "i386" ]]; then
+cat <<'EOF'>/mnt/gentoo/etc/portage/make.conf
+CFLAGS="-O2 -march=i686 -mno-tls-direct-seg-refs -pipe"
+CXXFLAGS="${CFLAGS}"
+CHOST="i686-pc-linux-gnu"
+EOF
+else
+cat <<'EOF'>/mnt/gentoo/etc/portage/make.conf
+CFLAGS="-O2 -pipe"
+CXXFLAGS="${CFLAGS}"
+CHOST="x86_64-pc-linux-gnu"
+USE="mmx sse sse2"
+EOF
+fi
+if [[ $TYPE != "minimal" ]]; then
+cat <<'EOF'>>/mnt/gentoo/etc/portage/make.conf
+MAKEOPTS="-j3"
+EMERGE_DEFAULT_OPTS="--jobs=2 --load-average=3.0"
+EOF
+cp /etc/portage/make.conf /etc/portage/make.conf.orig
+sed \
+-e "s/MAKEOPTS=.*/MAKEOPTS=\"-j`grep "^processor" /proc/cpuinfo | awk '{ print $3 + 2 }'`\"/g" \
+/etc/portage/make.conf.orig \
+| sed \
+-e "s/EMERGE_DEFAULT_OPTS=.*/EMERGE_DEFAULT_OPTS=\"--jobs=`grep "^processor" /proc/cpuinfo | awk '{ print $3 + 1 }'` --load-average=`grep "^processor" /proc/cpuinfo | awk '{ print $3 + 2 }'`.0\"/g" \
+> /etc/portage/make.conf
+rm /etc/portage/make.conf.orig
+fi
+
+echo "/etc/resolv.conf"
+cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
+
+mkdir -p /mnt/gentoo/etc/sudoers.d
+echo "/etc/sudoers.d/ec2-user"
+cat <<'EOF'>/mnt/gentoo/etc/sudoers.d/ec2-user
+ec2-user  ALL=(ALL) NOPASSWD:ALL
+EOF
+chmod 440 /mnt/gentoo/etc/sudoers.d/ec2-user
+
+echo "/etc/sudoers.d/_sudo"
+cat <<'EOF'>/mnt/gentoo/etc/sudoers.d/_sudo
+%sudo     ALL=(ALL) ALL
+EOF
+chmod 440 /mnt/gentoo/etc/sudoers.d/_sudo
+
+echo "/usr/src/linux/.config"
+mkdir -p /mnt/gentoo/tmp
+cp /tmp/.config /mnt/gentoo/tmp/.config
+
+mkdir -p /mnt/gentoo/var/lib/portage
+echo "/var/lib/portage/world"
+if [[ $TYPE = "minimal" ]]; then
+cat <<'EOF'>/mnt/gentoo/var/lib/portage/world
+app-admin/sudo
+sys-kernel/gentoo-sources
+EOF
+else
+cat <<'EOF'>/mnt/gentoo/var/lib/portage/world
+app-admin/logrotate
+EOF
+    if [[ $ARCHITECTURE = "x86_64" ]]; then
+cat <<'EOF'>>/mnt/gentoo/var/lib/portage/world
+app-admin/mcelog
+EOF
+    fi
+cat <<'EOF'>>/mnt/gentoo/var/lib/portage/world
+app-admin/sudo
+app-admin/syslog-ng
+app-arch/unzip
+app-editors/nano
+app-editors/vim
+app-misc/screen
+app-portage/eix
+app-portage/gentoolkit
+dev-vcs/git
+net-misc/curl
+net-misc/ntp
+sys-fs/lvm2
+sys-fs/mdadm
+sys-kernel/gentoo-sources
+sys-process/atop
+sys-process/fcron
+sys-process/htop
+EOF
+fi
+
+echo "/tmp/build.sh"
+
+cat <<'EOF'>/mnt/gentoo/tmp/build.sh
+#!/bin/bash
+
+env-update
+source /etc/profile
+
+emerge --sync
+
+cp /usr/share/zoneinfo/UTC /etc/localtime
+
+emerge --oneshot sys-apps/portage
+EOF
+
+if [[ $ARCHITECTURE = "i386" ]]; then
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+eselect profile set default/linux/x86/13.0
+emerge --unmerge sys-apps/module-init-tools
+EOF
+else
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+eselect profile set default/linux/amd64/13.0/no-multilib
+EOF
+fi
+
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+emerge --update --deep --with-bdeps=y --newuse @world
+
+cd /usr/src/linux
+mv /tmp/.config ./.config
+yes "" | make oldconfig
+make && make modules_install
+EOF
+
+if [[ $ARCHITECTURE = "i386" ]]; then
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+cp -L arch/x86/boot/bzImage /boot/bzImage
+EOF
+else
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+cp -L arch/x86_64/boot/bzImage /boot/bzImage
+EOF
+fi
+
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+groupadd sudo
+useradd -r -m -s /bin/bash ec2-user
+
+ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
+
+rc-update add net.eth0 default
+rc-update add sshd default
+EOF
+
+if [[ $TYPE != "minimal" ]]; then
+cat <<'EOF'>>/mnt/gentoo/tmp/build.sh
+rc-update add syslog-ng default
+rc-update add fcron default
+rc-update add ntpd default
+rc-update add lvm boot
+rc-update add mdraid boot
+EOF
+fi
+
+chmod 755 /mnt/gentoo/tmp/build.sh
+
+mount -t proc none /mnt/gentoo/proc
+mount --rbind /dev /mnt/gentoo/dev
+mount --rbind /dev/pts /mnt/gentoo/dev/pts
+
+chroot /mnt/gentoo /tmp/build.sh
+
+rm -fR /mnt/gentoo/tmp/*
+rm -fR /mnt/gentoo/var/tmp/*
+rm -fR /mnt/gentoo/usr/portage/distfiles/*
+
+shutdown -h now

x86_64/remote_gentoo.sh

-
-#-------------------------------------------------------------------------------
-# x86_64/remote_gentoo.sh
-#-------------------------------------------------------------------------------
-# Copyright 2012 Dowd and Associates
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#-------------------------------------------------------------------------------
-
-echo "mkfs -t ext4 /dev/xvdf"
-mkfs -t ext4 /dev/xvdf
-echo "mkdir -p /mnt/gentoo"
-mkdir -p /mnt/gentoo
-
-mount /dev/xvdf /mnt/gentoo
-
-cd /tmp
-echo "Download stage3"
-curl -O http://gentoo.mirrors.pair.com/releases/amd64/autobuilds/`curl --silent http://gentoo.mirrors.pair.com/releases/amd64/autobuilds/latest-stage3-amd64.txt | grep stage3-amd64`
-echo "Download portage"
-curl -O http://gentoo.mirrors.pair.com/snapshots/portage-latest.tar.bz2
-echo "Unpack stage3"
-tar -xjpf /tmp/stage3-*.tar.bz2 -C /mnt/gentoo
-echo "Unpack portage"
-tar -xjf /tmp/portage*.tar.bz2 -C /mnt/gentoo/usr
-
-echo "Setup files"
-
-mkdir -p /mnt/gentoo/boot/grub
-echo "/boot/grub/menu.lst"
-cat <<'EOF'>/mnt/gentoo/boot/grub/menu.lst
-default 0
-timeout 3
-title EC2
-root (hd0)
-kernel /boot/bzImage root=/dev/xvda1 rootfstype=ext4
-EOF
-
-echo "/etc/fstab"
-cat <<'EOF'>/mnt/gentoo/etc/fstab
-/dev/xvda1 / ext4 defaults 1 1
-none /dev/pts devpts gid=5,mode=620 0 0
-none /dev/shm tmpfs defaults 0 0
-none /proc proc defaults 0 0
-none /sys sysfs defaults 0 0
-EOF
-
-mkdir -p /mnt/gentoo/etc/local.d
-echo "/etc/local.d/killall_nash-hotplug.start"
-cat <<'EOF'>/mnt/gentoo/etc/local.d/killall_nash-hotplug.start
-# /etc/local.d/killall_nash-hotplug.start
-
-killall nash-hotplug
-EOF
-chmod 755 /mnt/gentoo/etc/local.d/killall_nash-hotplug.start
-
-echo "/etc/local.d/public-keys.start"
-cat <<'EOF'>/mnt/gentoo/etc/local.d/public-keys.start
-# /etc/local.d/public-keys.start
-
-[ ! -e /home/ec2-user ] && cp -r /etc/skel /home/ec2-user && chown -R ec2-user /home/ec2-user && chgrp -R ec2-user /home/ec2-user
-if [ ! -d /home/ec2-user/.ssh ] ; then
-mkdir -p /home/ec2-user/.ssh
-chmod 700 /home/ec2-user/.ssh
-chown ec2-user /home/ec2-user/.ssh
-chgrp ec2-user /home/ec2-user/.ssh
-fi
-curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/my-key
-if [ $? -eq 0 ] ; then
-cat /tmp/my-key >> /home/ec2-user/.ssh/authorized_keys
-chmod 600 /home/ec2-user/.ssh/authorized_keys
-chown ec2-user /home/ec2-user/.ssh/authorized_keys
-chgrp ec2-user /home/ec2-user/.ssh/authorized_keys
-rm /tmp/my-key
-fi
-EOF
-chmod 755 /mnt/gentoo/etc/local.d/public-keys.start
-
-echo "/etc/local.d/public-keys.stop"
-cat <<'EOF'>/mnt/gentoo/etc/local.d/public-keys.stop
-# /etc/local.d/public-keys.stop
-
-rm -f /home/ec2-user/.ssh/authorized_keys
-EOF
-chmod 755 /mnt/gentoo/etc/local.d/public-keys.stop
-
-mkdir -p /mnt/gentoo/etc/portage
-
-echo "/etc/portage/make.conf"
-cat <<'EOF'>/mnt/gentoo/etc/portage/make.conf
-# These settings were set by the catalyst build script that automatically
-# built this stage.
-# Please consult /usr/share/portage/config/make.conf.example for a more
-# detailed example.
-CFLAGS="-O2 -pipe"
-CXXFLAGS="${CFLAGS}"
-# WARNING: Changing your CHOST is not something that should be done lightly.
-# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
-CHOST="x86_64-pc-linux-gnu"
-# These are the USE flags that were used in addition to what is provided by the
-# profile used for building.
-USE="mmx sse sse2"
-MAKEOPTS="-j3"
-EMERGE_DEFAULT_OPTS="--jobs=2 --load-average=3.0"
-EOF
-
-echo "/etc/resolv.conf"
-cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
-
-mkdir -p /mnt/gentoo/etc/sudoers.d
-echo "/etc/sudoers.d/ec2-user"
-cat <<'EOF'>/mnt/gentoo/etc/sudoers.d/ec2-user
-ec2-user  ALL=(ALL) NOPASSWD:ALL
-EOF
-chmod 440 /mnt/gentoo/etc/sudoers.d/ec2-user
-
-echo "/etc/sudoers.d/_sudo"
-cat <<'EOF'>/mnt/gentoo/etc/sudoers.d/_sudo
-%sudo     ALL=(ALL) ALL
-EOF
-chmod 440 /mnt/gentoo/etc/sudoers.d/_sudo
-
-echo "/usr/src/linux/.config"
-mkdir -p /mnt/gentoo/tmp
-cp /tmp/.config /mnt/gentoo/tmp/.config
-
-mkdir -p /mnt/gentoo/var/lib/portage
-echo "/var/lib/portage/world"
-cat <<'EOF'>/mnt/gentoo/var/lib/portage/world
-app-admin/logrotate
-app-admin/mcelog
-app-admin/sudo
-app-admin/syslog-ng
-app-arch/unzip
-app-editors/nano
-app-editors/vim
-app-misc/screen
-app-portage/eix
-app-portage/gentoolkit
-dev-vcs/git
-net-misc/curl
-net-misc/dhcpcd
-net-misc/ntp
-sys-fs/lvm2
-sys-fs/mdadm
-sys-kernel/gentoo-sources
-sys-process/atop
-sys-process/fcron
-sys-process/htop
-EOF
-
-echo "/tmp/build.sh"
-
-cat <<'EOF'>/mnt/gentoo/tmp/build.sh
-#!/bin/bash
-
-env-update
-source /etc/profile
-
-emerge --sync
-
-cp /usr/share/zoneinfo/GMT /etc/localtime
-
-eselect profile set default/linux/amd64/13.0/no-multilib
-emerge --oneshot sys-apps/portage
-emerge --update --deep --with-bdeps=y --newuse @world
-
-cd /usr/src/linux
-mv /tmp/.config ./.config
-yes "" | make oldconfig
-make -j3 && make -j3 modules_install
-cp -L arch/x86_64/boot/bzImage /boot/bzImage
-
-groupadd sudo
-useradd -r -m -s /bin/bash ec2-user
-
-ln -s /etc/init.d/net.lo /etc/init.d/net.eth0
-
-rc-update add net.eth0 default
-rc-update add sshd default
-rc-update add syslog-ng default
-rc-update add fcron default
-rc-update add ntpd default
-rc-update add lvm boot
-rc-update add mdraid boot
-
-mv /etc/portage/make.conf /etc/portage/make.conf.bkup
-sed "s/MAKEOPTS=\"-j.*\"/MAKEOPTS=\"-j2\"/g" /etc/portage/make.conf.bkup > /etc/portage/make.conf
-rm /etc/portage/make.conf.bkup
-
-EOF
-
-chmod 755 /mnt/gentoo/tmp/build.sh
-
-mount -t proc none /mnt/gentoo/proc
-mount --rbind /dev /mnt/gentoo/dev
-mount --rbind /dev/pts /mnt/gentoo/dev/pts
-
-chroot /mnt/gentoo /tmp/build.sh
-
-rm -fR /mnt/gentoo/tmp/*
-rm -fR /mnt/gentoo/var/tmp/*
-rm -fR /mnt/gentoo/usr/portage/distfiles/*
-
-shutdown -h now