3 # Copyright (C) 2010-2011 Red Hat, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Uncomment for debugging.
21 # $bucket is iwhd bucket (not S3 bucket, see $ami_bkt below).
23 # $object is iwhd's image name, which also serves as a basename in S3.
24 # So, if $object=foo.img, then we end uploading foo.img.manifest.xml and
25 # a bunch of foo.img.part.NN files.
26 # The foo.img itself is an uncompressed root filesystem, a device image.
27 # Finally, $object is in local directory $bucket/ (as fs back-end works).
29 # $api_key is "key ID" for S3.
31 # $api_secret is "secret" for S3.
33 # $cert_file contains X.509 certificate for EC2 (cert-foo.pem).
35 # $key_file contains private key for EC2 (pk-foo.pem).
37 # $api_uid is AWS account ID, but without dashes.
39 # $ami_bkt is S3 bucket into which we upload foo.img.manifest.xml etc.
41 # $kernel is an aki-xxxxxxxx ID (e.g. aki-99a0f1dc is pvgrub)
43 # $ramdisk is an ari-xxxxxxxx ID or "_default_" (most of the time for pvgrub)
46 # We do not set JAVA_HOME and EC2_HOME because they are not necessary
47 # if pre-packaged versions of ec2-api-tools and ec2-ami-tools are installed
48 # from RPMfusion and Amazon respectively. This also allows the user to
49 # set these locations in case an alternative set of tools is desired.
51 # However, we look for each missing tool in commonly overlooked locations.
55 ret
=$
(/usr
/bin
/which $cmd 2>/dev
/null
)
57 if [ -x /usr
/local
/bin
/$cmd ]; then
58 ret
=/usr
/local
/bin
/$cmd
59 elif [ -x ~
/bin
/$cmd ]; then
63 if [ -z "$ret" ]; then
64 echo "ERROR missing_$cmd" >&2
70 ec2_bundle_image
=$
(which_it ec2-bundle-image
)
71 ec2_upload_bundle
=$
(which_it ec2-upload-bundle
)
72 ec2_register
=$
(which_it ec2-register
)
73 [ -z "$ec2_bundle_image" -o -z "$ec2_upload_bundle" -o -z "$ec2_register" ] && exit 1
75 # XXX Is this safe against running 2 requests simultaneously?
76 tmpdir
=$
(mktemp
-d -p $PWD/$bucket) ||
exit 1
77 trap "rm -rf $tmpdir" EXIT
79 bundle_args
="--batch --arch x86_64 -c $cert_file -k $key_file -u $api_uid"
80 if [ "$kernel" != "_default_" ]; then
81 bundle_args
="$bundle_args --kernel $kernel"
83 if [ "$ramdisk" != "_default_" ]; then
84 bundle_args
="$bundle_args --ramdisk $ramdisk"
86 $ECHO $ec2_bundle_image -i $bucket/$object -d $tmpdir $bundle_args
88 echo "ERROR bundling_failed" >&2
89 echo $ec2_bundle_image -i $bucket/$object -d $tmpdir $bundle_args >&2
93 upload_args
="--batch --retry -b $ami_bkt -a $api_key -s $api_secret"
94 $ECHO $ec2_upload_bundle -m $tmpdir/$object.manifest.xml
$upload_args
96 echo "ERROR uploading_failed" >&2
97 echo $ec2_upload_bundle -m $tmpdir/$object.manifest.xml
$upload_args >&2
101 register_args
="-C $cert_file -K $key_file"
102 $ECHO $ec2_register $register_args $ami_bkt/$object.manifest.xml
-n $object
104 echo "ERROR registration_failed" >&2
105 echo $ec2_register $register_args $ami_bkt/$object.manifest.xml
-n $object >&2