1. #!/bin/sh
  2. # buildoe -- build openembedded via ec2
  3.  
  4. usage() {
  5. echo "Usage: buildoe INSTANCETYPE" 1>&2
  6. exit 1
  7. }
  8.  
  9. if test -z "$1"; then
  10. usage
  11. fi
  12.  
  13. if ! ssh-add -l | grep -q ' id_dsa_ec2 '; then
  14. echo "Adding the EC2 SSH key."
  15. ssh-add ~/id_dsa_ec2
  16. fi
  17.  
  18. if test -z "$JAVA_HOME"; then
  19. source ~/ec2.sh
  20. fi
  21.  
  22. case "$1" in
  23. m1.small|c1.medium)
  24. image=ami-bb709dd2
  25. ;;
  26. *)
  27. image=ami-55739e3c
  28. ;;
  29. esac
  30.  
  31.  
  32. # Ubuntu 9.10 server amd64: ami-55739e3c
  33. # Ubuntu 9.10 server i386: ami-bb709dd2
  34. echo -n 'Starting instance...'
  35. instancerequest="`ec2-request-spot-instances "$image" -z us-east-1a -r one-time -p 1.00 -k id_dsa_ec2 -t "$1" | awk '/^SPOTINSTANCEREQUEST/ { print $2 }'`"
  36. while true; do
  37. instance="`ec2-describe-spot-instance-requests "$instancerequest" | awk '/^SPOTINSTANCEREQUEST/ { print $8; exit 0; }'`"
  38. if test "$?" -ne 0; then
  39. exit 1
  40. fi
  41. if echo "$instance" | grep '^i-........$'; then
  42. break
  43. fi
  44. echo -n '.'
  45. done
  46. #instance="`ec2run "$image" -k id_dsa_ec2 -z us-east-1a -t "$1" | awk '/^INSTANCE/ { print $2 }'`"
  47. while true; do
  48. addr="`ec2din $instance | awk '/^INSTANCE/ { if($4 != "terminated" && $4 != "pending") { print $4; exit 0; } }'`"
  49. if test "$?" -ne 0; then
  50. exit 1
  51. fi
  52. if test 'xpending' != "x$addr"; then
  53. break
  54. fi
  55. sleep 10
  56. echo -n '!'
  57. done
  58. ec2-attach-volume vol-3d13bf54 -i $instance -d /dev/sdf
  59. ssh -o 'StrictHostKeyChecking no' -fN ubuntu@$addr
  60. if test "$?" -ne 0; then
  61. exit 1
  62. fi
  63. cat <<"EOF" | ssh ubuntu@$addr 'cat > buildit.sh'
  64. sudo apt-get update -y
  65. if test `uname -m` != x86_64; then
  66. psyco="python-psyco"
  67. else
  68. psyco=""
  69. fi
  70. sudo modprobe dm_mod
  71. sudo apt-get -y install git-core subversion gcc build-essential diffstat texinfo help2man texi2html gawk chrpath lvm2 $psyco
  72. echo 'Yes, do as I say!' | sudo apt-get install xz-utils
  73. sudo ln -fs /bin/bash /bin/sh
  74. mkdir ~/overo-oe
  75. sudo mount /dev/sda2 ~/overo-oe
  76. #sudo mount /dev/mapper/storageVG-storageFS ~/overo-oe
  77. cd ~/overo-oe
  78. sudo chmod 777 ~/overo-oe
  79. #sudo lvchange -a y /dev/storageVG/storageFS
  80. git clone git://gitorious.org/gumstix-oe/mainline.git org.openembedded.dev
  81. cd org.openembedded.dev
  82. git checkout --track -b overo origin/overo
  83. cd ~/overo-oe
  84. git clone git://git.openembedded.net/bitbake bitbake
  85. cd bitbake
  86. git checkout 1.8.18
  87. cd ~/overo-oe
  88. cp -r org.openembedded.dev/contrib/gumstix/build .
  89. . ~/overo-oe/build/profile
  90. # 84 is _SC_NPROCESSORS_ONLN
  91. NCPU=`python -c 'import ctypes; print ctypes.cdll.LoadLibrary("libc.so.6").sysconf(84)'`
  92. echo PARALLEL_MAKE = \"-j $NCPU\" >> ~/overo-oe/build/conf/site.conf
  93. echo BB_NUMBER_THREADS = \"$NCPU\" >> ~/overo-oe/build/conf/site.conf
  94. bitbake omap3-console-image
  95. EOF
  96. ssh ubuntu@$addr 'screen -dmS build ; screen -r build -X exec echo /usr/bin/time sh ~/buildit.sh'
  97.  
  98.  
  99. # source this to set up environment for EC2 tools
  100. export EC2_PRIVATE_KEY=~/Downloads/pk-XXX.pem
  101. export EC2_PRIVATE_KEY=~/Downloads/pk-XXX.pem
  102. export EC2_CERT=~/Downloads/cert-XXX.pem
  103. export JAVA_HOME=/Library/Java/Home
  104. export EC2_HOME=~/Downloads/ec2-api-tools-1.3-46266
  105. export PATH=$PATH:$EC2_HOME/bin