Commits

Eric Dowd committed 6f9d923

Added report_status function to deduplicate output

  • Participants
  • Parent commits 898e77f

Comments (0)

Files changed (1)

 
 sleep 120
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: copying files to remote server"
+report_status "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"
+report_status "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"
+report_status "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)"
+    report_status "checking if install is done (1 minute check)"
     let stopped_check="`ec2-describe-instances \
             --region $region \
             $instance \
             | wc -c`"
 done
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: install is done"
+report_status "install is done"
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: get volume on which gentoo was installed"
+report_status "get volume on which gentoo was installed"
 
 volume=`ec2-describe-volumes \
 --region $region \
 | awk '{ print $2 } '`
 
 if [ -z $AMI_TYPE ]; then
-    name=${AMI_NAME:-${default_name}-`date +%Y-%m-%d-%H-%M-%S`}
+    name=${AMI_NAME:-${default_name}-`date --utc +%Y-%m-%d-%H-%M-%S`}
 else
-    name=${AMI_NAME:-${AMI_TYPE}-${default_name}-`date +%Y-%m-%d-%H-%M-%S`}
+    name=${AMI_NAME:-${AMI_TYPE}-${default_name}-`date --utc +%Y-%m-%d-%H-%M-%S`}
 fi
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: creating snapshot"
+report_status "creating snapshot"
 
 snapshot=`ec2-create-snapshot \
 --region $region \
 --description $name \
 | awk '{ print $2 }'`
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if snapshot is done"
+report_status "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)"
+    report_status "checking if snapshot is done (1 minute check)"
     let completed_check="`ec2-describe-snapshots \
         --region $region \
         $snapshot \
         | wc -c`"
 done
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: snapshot is done"
+report_status "snapshot is done"
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: register image"
+report_status "register image"
 
 if [ $architecture = "i386" ]; then
 gentoo_image=`ec2-register \
 | awk '{ print $2 }'`
 fi
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: image-id = $gentoo_image"
+report_status "image-id = $gentoo_image"
 
 gentoo_instance=`ec2-run-instances \
 --region $region \
 | grep "^INSTANCE" \
 | awk '{ print $2 }'`
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: gentoo instance = $gentoo_instance"
+report_status "gentoo instance = $gentoo_instance"
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: start checking if instance is running"
+report_status "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)"
+    report_status "checking if instance is running (10 second check)"
     let running_check="`ec2-describe-instances \
             --region $region \
             $gentoo_instance \
             | wc -c`"
 done
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instance is running"
+report_status "instance is running"
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: getting hostname"
+report_status "getting hostname"
 
 server=`ec2-describe-instances \
 --region $region \
 | grep "^INSTANCE" \
 | awk '{ print $4 }'`
 
-echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: hostname = $server"
+report_status "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"
+report_status "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"
+report_status "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"
+    report_status "connection successful"
+    report_status "terminating instances"
     ec2-terminate-instances --region $region $instance $gentoo_instance
-    echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: instances terminated"
+    report_status "instances terminated"
     if [ $remove_keypair = "true" ]; then
-        echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: deleting keypair"
+        report_status "deleting keypair"
         ec2-delete-keypair --region $region $key
         rm $keyfile
-        echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: keypair deleted"
+        report_status "keypair deleted"
     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:"
+    report_status "gentoo image-id = $gentoo_image"
+    report_status "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"
+    report_status "connection failed"
+    report_status "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"
+    report_status "instance stopped"
+    report_status "issue with script, could not verify image. Check instances:"
+    report_status "bootstrap instance: $instance"
+    report_status "gentoo instance: $gentoo_instance"
+    report_status "gentoo image-id = $gentoo_image"
 fi