This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
forked from camptocamp/build-debian-cloud
-
Notifications
You must be signed in to change notification settings - Fork 43
/
ec2
111 lines (94 loc) · 4.32 KB
/
ec2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# AMI details
ami_id=
name_suffix=$(date +%Y%m%d)
description=
snapshot_id=
volume_id=
volume_size='1'
apt_mirrors='http://http.debian.net/debian'
# EC2 known regions
known_regions=('us-east-1')
known_regions+=('us-west-1')
known_regions+=('us-west-2')
known_regions+=('eu-west-1')
known_regions+=('ap-southeast-1')
known_regions+=('ap-southeast-2')
known_regions+=('ap-northeast-1')
known_regions+=('sa-east-1')
known_regions+=('us-gov-west-1')
# EC2 host info
instance_id=
region=
availability_zone=
# Build-time info
debootstrap_dir='/target'
# List of options for ec2 subcommand
help="build-debian-cloud ec2
This subcommand creates a Debian Squeeze Amazon Machine Image.
Options (defaults in ${txtbld}bold${txtdef}):
${txtund}Bootstrapping${txtdef}
--arch ARCH [i386|amd64] Processor architecture of the image (${txtbld}${arch}${txtdef})
--codename C [squeeze|wheezy] Debian version codename to bootstrap (${txtbld}${codename}${txtdef})
--filesystem FS [ext2..4|xfs] Filesystem of the root volume (${txtbld}${filesystem}${txtdef})
--volume-size SIZE Default size of the root volume in GB (${txtbld}${volume_size}${txtdef})
--plugin FILE Path to plugin script.
Can be specified more than once.
--timezone ZONE Standard timezone (${txtbld}${timezone}${txtdef})
--locale LOCALE Standard locale (${txtbld}${locale}${txtdef})
--charmap CHARMAP Standard charmap (${txtbld}${charmap}${txtdef})
--debootstrap-dir DIR Debootstrap directory (${txtbld}${debootstrap_dir}${txtdef})
The created volume will be mounted
at \$debootstrap_dir/\$volume_id.
--name SUFFIX AMI name suffix (${txtbld}${name_suffix}${txtdef})
--description DESC Description of the AMI
--apt-mirrors \"URL[ URL...]\" APT mirror URLs, space-separated (${txtbld}${apt_mirrors}${txtdef})
${txtund}AWS${txtdef}
--access-key ID AWS Access Key (${txtbld}\$EC2_ACCESS_KEY${txtdef})
--secret-key KEY AWS Secret Key (${txtbld}\$EC2_SECRET_KEY${txtdef})
${txtund}Other options${txtdef}
--debug Print debugging information
--help Prints this help message
"
# Run through the parameters and save them to variables.
while [ $# -gt 0 ]; do
case $1 in
--arch) arch=$2; shift 2 ;;
--codename) codename=$2; shift 2 ;;
--filesystem) filesystem=$2; shift 2 ;;
--volume-size) volume_size=$2; shift 2 ;;
--name) name_suffix=$2; shift 2 ;;
--description) description=$2; shift 2 ;;
--apt-mirrors) apt_mirrors=$2; shift 2 ;;
--access-key) EC2_ACCESS_KEY=$2; shift 2 ;;
--secret-key) EC2_SECRET_KEY=$2; shift 2 ;;
--timezone) timezone=$2; shift 2 ;;
--locale) locale=$2; shift 2 ;;
--charmap) charmap=$2; shift 2 ;;
--debootstrap-dir) debootstrap_dir=$2; shift 2 ;;
--plugin) plugins+=("$2"); shift 2 ;;
--debug) set -x; shift ;;
-h|--help) printf -- "$help"; exit 0 ;;
*) die "Unrecognized option: $1" \
"Type '$0 --help' to see a list of possible options"; ;;
esac
done
# Required and default parameters
true ${EC2_ACCESS_KEY:?} ${EC2_SECRET_KEY:?}
# Export the AWS credentials, so that we can launch ec2-tools without specifying them
export EC2_ACCESS_KEY EC2_SECRET_KEY
# Specify points in the bootstrapping process, which the plugins can latch onto.
# This way plugins don't need fixing if we rename files.
TASK_PACKAGES="01-packages"
TASK_CREATE_VOLUME="10-create-volume"
TASK_MOUNT_VOLUME="13-mount-volume"
TASK_MOUNT_SPECIALS="15-mount-specials"
TASK_BOOTSTRAP="14-bootstrap"
TASK_APT_SOURCES="21-apt-sources"
TASK_APT_UPGRADE="22-apt-upgrade"
TASK_INITSCRIPTS="51-init-scripts"
TASK_UNMOUNT_SPECIALS="71-unmount-specials"
TASK_UNMOUNT_VOLUME="72-unmount-volume"
TASK_SNAPSHOT="80-ebs-snapshot"
TASK_DELETE_VOLUME="82-delete-volume"
TASK_CREATE_AMI="95-register-ami"