toft-puppet 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +62 -0
  3. data/Rakefile +121 -0
  4. data/features/checker.feature +14 -0
  5. data/features/chef.feature +70 -0
  6. data/features/command.feature +20 -0
  7. data/features/node.feature +41 -0
  8. data/features/puppet.feature +40 -0
  9. data/features/step_definitions/centos/checks.rb +9 -0
  10. data/features/step_definitions/checker.rb +15 -0
  11. data/features/step_definitions/chef.rb +43 -0
  12. data/features/step_definitions/command.rb +28 -0
  13. data/features/step_definitions/node.rb +65 -0
  14. data/features/step_definitions/puppet.rb +7 -0
  15. data/features/support/env.rb +25 -0
  16. data/fixtures/chef/attributes.json +9 -0
  17. data/fixtures/chef/cookbooks/test/attributes/default.rb +4 -0
  18. data/fixtures/chef/cookbooks/test/recipes/attribute.rb +19 -0
  19. data/fixtures/chef/cookbooks/test/recipes/default.rb +4 -0
  20. data/fixtures/chef/cookbooks/test/recipes/role.rb +4 -0
  21. data/fixtures/chef/roles/test.rb +3 -0
  22. data/fixtures/puppet/conf/fileserver.conf +3 -0
  23. data/fixtures/puppet/conf/puppet.conf +15 -0
  24. data/fixtures/puppet/conf/puppet_exec.conf +9 -0
  25. data/fixtures/puppet/conf/puppet_fileserver.conf +8 -0
  26. data/fixtures/puppet/conf/puppet_modules.conf +7 -0
  27. data/fixtures/puppet/conf/puppet_template.conf +8 -0
  28. data/fixtures/puppet/manifests/fileserver/conf/test_fileserver +1 -0
  29. data/fixtures/puppet/manifests/nodes/test_node.pp +26 -0
  30. data/fixtures/puppet/manifests/site.pp +1 -0
  31. data/fixtures/puppet/manifests/templates/template_test +2 -0
  32. data/fixtures/puppet/manifests/test.pp +8 -0
  33. data/fixtures/puppet/manifests/test_fileserver.pp +14 -0
  34. data/fixtures/puppet/manifests/test_install.pp +5 -0
  35. data/fixtures/puppet/manifests/test_module.pp +5 -0
  36. data/fixtures/puppet/manifests/test_service.pp +11 -0
  37. data/fixtures/puppet/manifests/test_template.pp +12 -0
  38. data/fixtures/puppet/modules/test_module/manifests/init.pp +8 -0
  39. data/lib/toft.rb +39 -0
  40. data/lib/toft/chef/chef_attributes.rb +29 -0
  41. data/lib/toft/chef/chef_runner.rb +77 -0
  42. data/lib/toft/command_executor.rb +16 -0
  43. data/lib/toft/file_checker.rb +47 -0
  44. data/lib/toft/node.rb +243 -0
  45. data/lib/toft/node_controller.rb +32 -0
  46. data/lib/toft/puppet/puppet_runner.rb +38 -0
  47. data/lib/toft/version.rb +3 -0
  48. data/scripts/bin/centos/lxc-prepare-host +172 -0
  49. data/scripts/bin/centos/provision_vagrant +11 -0
  50. data/scripts/bin/share/install-chef-ubuntu.sh +19 -0
  51. data/scripts/bin/share/lxc-create-centos-image +60 -0
  52. data/scripts/bin/ubuntu/lxc-create-ubuntu-image +77 -0
  53. data/scripts/bin/ubuntu/lxc-prepare-host +199 -0
  54. data/scripts/bin/ubuntu/provision_vagrant +9 -0
  55. data/scripts/lxc-templates/files/rc.local +38 -0
  56. data/scripts/lxc-templates/lxc-centos-6 +279 -0
  57. data/scripts/lxc-templates/lxc-lenny +255 -0
  58. data/scripts/lxc-templates/lxc-lucid +313 -0
  59. data/scripts/lxc-templates/lxc-natty +237 -0
  60. data/spec/fixtures/illegal_syntax.json +1 -0
  61. data/spec/spec_helper.rb +6 -0
  62. data/spec/toft/chef/chef_attributes_spec.rb +39 -0
  63. data/spec/toft/chef/chef_runner_spec.rb +34 -0
  64. data/spec/toft/node_spec.rb +18 -0
  65. data/spec/toft/puppet/puppet_runner_spec.rb +26 -0
  66. metadata +234 -0
@@ -0,0 +1,255 @@
1
+ #!/bin/bash
2
+
3
+ echo "Creating lenny node..."
4
+
5
+ configure_ubuntu()
6
+ {
7
+ rootfs=$1
8
+ hostname=$2
9
+
10
+ # disable selinux in ubuntu
11
+ mkdir -p $rootfs/selinux
12
+ echo 0 > $rootfs/selinux/enforce
13
+
14
+ # add host root ssh access
15
+ mkdir $rootfs/root/.ssh
16
+ chmod 0600 $rootfs/root/.ssh
17
+ cat <<-EOF > $rootfs/root/.ssh/authorized_keys
18
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSlgXtgHDo7eZhNSm5zCeoyGd32OKeLxuxCCEkXfDDF1aa2a6twcASE3pmWNdnBS7auiOH4P7g+eQ4Aw9v7DdESbIVgHF/NDiAEFFdmApYNM3oCX2FhEVNVKxkkIokUr4axYFJzmJ6Xoi5Sd8JtPC85FZVXqDucZDnHQlOcCkbSo0UOmsWQGwtu8eUHoDeUG0dB8ntb9xlBeLctdrAPhuFYCX8IfFkdcakkzv61ETPbKE6g9wdTDC/TEep7/AHGYmarziRnwKiVOL1jnE1coOJLqy8wOC3dKGmRZy9D4sTc+FRV root insecure public key
19
+ EOF
20
+
21
+ cp /usr/lib/lxc/templates/files/rc.local $rootfs/etc/rc.local
22
+
23
+ # set the hostname
24
+ cat <<EOF > $rootfs/etc/hostname
25
+ $hostname
26
+ EOF
27
+ # set minimal hosts
28
+ cat <<EOF > $rootfs/etc/hosts
29
+ 127.0.0.1 localhost $hostname
30
+ EOF
31
+
32
+ cat <<EOF > $rootfs/etc/inittab
33
+ id:3:initdefault:
34
+ si::sysinit:/etc/init.d/rcS
35
+ l0:0:wait:/etc/init.d/rc 0
36
+ l1:1:wait:/etc/init.d/rc 1
37
+ l2:2:wait:/etc/init.d/rc 2
38
+ l3:3:wait:/etc/init.d/rc 3
39
+ l4:4:wait:/etc/init.d/rc 4
40
+ l5:5:wait:/etc/init.d/rc 5
41
+ l6:6:wait:/etc/init.d/rc 6
42
+ # Normally not reached, but fallthrough in case of emergency.
43
+ z6:6:respawn:/sbin/sulogin
44
+ 1:2345:respawn:/sbin/getty 38400 console
45
+ c1:12345:respawn:/sbin/getty 38400 tty1 linux
46
+ c2:12345:respawn:/sbin/getty 38400 tty2 linux
47
+ c3:12345:respawn:/sbin/getty 38400 tty3 linux
48
+ c4:12345:respawn:/sbin/getty 38400 tty4 linux
49
+ EOF
50
+
51
+ # reconfigure some services
52
+ if [ -z "$LANG" ]; then
53
+ chroot $rootfs locale-gen en_US.UTF-8
54
+ chroot $rootfs update-locale LANG=en_US.UTF-8
55
+ else
56
+ chroot $rootfs locale-gen $LANG
57
+ chroot $rootfs update-locale LANG=$LANG
58
+ fi
59
+
60
+ echo "Set root password to 'root'"
61
+ echo "root:root" | chroot $rootfs chpasswd
62
+
63
+ return 0
64
+ }
65
+
66
+ copy_ubuntu()
67
+ {
68
+ cache=$1
69
+ arch=$2
70
+ rootfs=$3
71
+
72
+ # make a local copy of the miniubuntu
73
+ echo "Extracting rootfs image to $rootfs ..."
74
+ mkdir $rootfs
75
+ tar zxf $cache/lenny-$arch.tar.gz -C $rootfs || return 1
76
+ return 0
77
+ }
78
+
79
+ install_ubuntu()
80
+ {
81
+ cache="/var/cache/lxc"
82
+ rootfs=$1
83
+ mkdir -p /var/lock/subsys/
84
+ (
85
+ flock -n -x 200
86
+ if [ $? -ne 0 ]; then
87
+ echo "Cache repository is busy."
88
+ return 1
89
+ fi
90
+
91
+ arch=$(arch)
92
+ if [ "$arch" == "x86_64" ]; then
93
+ arch=amd64
94
+ fi
95
+
96
+ if [ "$arch" == "i686" ]; then
97
+ arch=i386
98
+ fi
99
+
100
+ echo "Checking image cache in $cache/rootfs-$arch ... "
101
+ if [ ! -e "$cache/rootfs-$arch" ]; then
102
+ if [ $? -ne 0 ]; then
103
+ echo "Failed to download 'ubuntu base'"
104
+ return 1
105
+ fi
106
+ fi
107
+
108
+ copy_ubuntu $cache $arch $rootfs
109
+ if [ $? -ne 0 ]; then
110
+ echo "Failed to copy rootfs"
111
+ return 1
112
+ fi
113
+
114
+ return 0
115
+
116
+ ) 200>/var/lock/subsys/lxc
117
+
118
+ return $?
119
+ }
120
+
121
+ copy_configuration()
122
+ {
123
+ path=$1
124
+ rootfs=$2
125
+ name=$3
126
+
127
+ cat <<EOF >> $path/config
128
+ lxc.utsname = $name
129
+
130
+ lxc.tty = 4
131
+ lxc.pts = 1024
132
+ lxc.rootfs = $rootfs
133
+ lxc.mount = $path/fstab
134
+
135
+ lxc.cgroup.devices.deny = a
136
+ # /dev/null and zero
137
+ lxc.cgroup.devices.allow = c 1:3 rwm
138
+ lxc.cgroup.devices.allow = c 1:5 rwm
139
+ # consoles
140
+ lxc.cgroup.devices.allow = c 5:1 rwm
141
+ lxc.cgroup.devices.allow = c 5:0 rwm
142
+ lxc.cgroup.devices.allow = c 4:0 rwm
143
+ lxc.cgroup.devices.allow = c 4:1 rwm
144
+ # /dev/{,u}random
145
+ lxc.cgroup.devices.allow = c 1:9 rwm
146
+ lxc.cgroup.devices.allow = c 1:8 rwm
147
+ lxc.cgroup.devices.allow = c 136:* rwm
148
+ lxc.cgroup.devices.allow = c 5:2 rwm
149
+ # rtc
150
+ lxc.cgroup.devices.allow = c 254:0 rwm
151
+ EOF
152
+
153
+ cat <<EOF > $path/fstab
154
+ proc $rootfs/proc proc nodev,noexec,nosuid 0 0
155
+ devpts $rootfs/dev/pts devpts defaults 0 0
156
+ sysfs $rootfs/sys sysfs defaults 0 0
157
+ EOF
158
+
159
+ if [ $? -ne 0 ]; then
160
+ echo "Failed to add configuration"
161
+ return 1
162
+ fi
163
+
164
+ return 0
165
+ }
166
+
167
+ clean()
168
+ {
169
+ cache="/var/cache/lxc"
170
+
171
+ if [ ! -e $cache ]; then
172
+ exit 0
173
+ fi
174
+
175
+ # lock, so we won't purge while someone is creating a repository
176
+ (
177
+ flock -n -x 200
178
+ if [ $? != 0 ]; then
179
+ echo "Cache repository is busy."
180
+ exit 1
181
+ fi
182
+
183
+ echo -n "Purging the download cache..."
184
+ rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
185
+ exit 0
186
+
187
+ ) 200>/var/lock/subsys/lxc
188
+ }
189
+
190
+ usage()
191
+ {
192
+ cat <<EOF
193
+ $1 -h|--help -p|--path=<path> --clean
194
+ EOF
195
+ return 0
196
+ }
197
+
198
+ options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
199
+ if [ $? -ne 0 ]; then
200
+ usage $(basename $0)
201
+ exit 1
202
+ fi
203
+ eval set -- "$options"
204
+
205
+ while true
206
+ do
207
+ case "$1" in
208
+ -h|--help) usage $0 && exit 0;;
209
+ -p|--path) path=$2; shift 2;;
210
+ -n|--name) name=$2; shift 2;;
211
+ -c|--clean) clean=$2; shift 2;;
212
+ --) shift 1; break ;;
213
+ *) break ;;
214
+ esac
215
+ done
216
+
217
+ if [ ! -z "$clean" -a -z "$path" ]; then
218
+ clean || exit 1
219
+ exit 0
220
+ fi
221
+
222
+ if [ -z "$path" ]; then
223
+ echo "'path' parameter is required"
224
+ exit 1
225
+ fi
226
+
227
+ if [ "$(id -u)" != "0" ]; then
228
+ echo "This script should be run as 'root'"
229
+ exit 1
230
+ fi
231
+
232
+ rootfs=$path/rootfs
233
+
234
+ install_ubuntu $rootfs
235
+ if [ $? -ne 0 ]; then
236
+ echo "failed to install ubuntu"
237
+ exit 1
238
+ fi
239
+
240
+ configure_ubuntu $rootfs $name
241
+ if [ $? -ne 0 ]; then
242
+ echo "failed to configure ubuntu for a container"
243
+ exit 1
244
+ fi
245
+
246
+ copy_configuration $path $rootfs $name
247
+ if [ $? -ne 0 ]; then
248
+ echo "failed write configuration file"
249
+ exit 1
250
+ fi
251
+
252
+ if [ ! -z $clean ]; then
253
+ clean || exit 1
254
+ exit 0
255
+ fi
@@ -0,0 +1,313 @@
1
+ #!/bin/bash
2
+
3
+ echo "Creating lucid node..."
4
+
5
+ configure_ubuntu()
6
+ {
7
+ rootfs=$1
8
+ hostname=$2
9
+
10
+ # disable selinux in ubuntu
11
+ mkdir -p $rootfs/selinux
12
+ echo 0 > $rootfs/selinux/enforce
13
+
14
+ # add host root ssh access
15
+ mkdir $rootfs/root/.ssh
16
+ chmod 0600 $rootfs/root/.ssh
17
+ cat <<-EOF > $rootfs/root/.ssh/authorized_keys
18
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCguB7XL3ARzLZYLsIMZe4UUO371m+H5C6V8MhtmSlgXtgHDo7eZhNSm5zCeoyGd32OKeLxuxCCEkXfDDF1aa2a6twcASE3pmWNdnBS7auiOH4P7g+eQ4Aw9v7DdESbIVgHF/NDiAEFFdmApYNM3oCX2FhEVNVKxkkIokUr4axYFJzmJ6Xoi5Sd8JtPC85FZVXqDucZDnHQlOcCkbSo0UOmsWQGwtu8eUHoDeUG0dB8ntb9xlBeLctdrAPhuFYCX8IfFkdcakkzv61ETPbKE6g9wdTDC/TEep7/AHGYmarziRnwKiVOL1jnE1coOJLqy8wOC3dKGmRZy9D4sTc+FRV root insecure public key
19
+ EOF
20
+
21
+ cp /usr/lib/lxc/templates/files/rc.local $rootfs/etc/rc.local
22
+
23
+ # set the hostname
24
+ cat <<EOF > $rootfs/etc/hostname
25
+ $hostname
26
+ EOF
27
+ # set minimal hosts
28
+ cat <<EOF > $rootfs/etc/hosts
29
+ 127.0.0.1 localhost $hostname
30
+ EOF
31
+
32
+ # provide the lxc service
33
+ cat <<EOF > $rootfs/etc/init/lxc.conf
34
+ # fake some events needed for correct startup other services
35
+
36
+ description "Container Upstart"
37
+
38
+ start on startup
39
+
40
+ script
41
+ rm -rf /var/run/*.pid
42
+ rm -rf /var/run/network/*
43
+ /sbin/initctl emit stopped JOB=udevtrigger --no-wait
44
+ /sbin/initctl emit started JOB=udev --no-wait
45
+ end script
46
+ EOF
47
+
48
+ # fix buggus runlevel with sshd
49
+ cat <<EOF > $rootfs/etc/init/ssh.conf
50
+ # ssh - OpenBSD Secure Shell server
51
+ #
52
+ # The OpenSSH server provides secure shell access to the system.
53
+
54
+ description "OpenSSH server"
55
+
56
+ start on filesystem
57
+ stop on runlevel [!2345]
58
+
59
+ expect fork
60
+ respawn
61
+ respawn limit 10 5
62
+ umask 022
63
+ # replaces SSHD_OOM_ADJUST in /etc/default/ssh
64
+ oom never
65
+
66
+ pre-start script
67
+ test -x /usr/sbin/sshd || { stop; exit 0; }
68
+ test -e /etc/ssh/sshd_not_to_be_run && { stop; exit 0; }
69
+ test -c /dev/null || { stop; exit 0; }
70
+
71
+ mkdir -p -m0755 /var/run/sshd
72
+ end script
73
+
74
+ # if you used to set SSHD_OPTS in /etc/default/ssh, you can change the
75
+ # 'exec' line here instead
76
+ exec /usr/sbin/sshd
77
+ EOF
78
+
79
+ cat <<EOF > $rootfs/etc/init/console.conf
80
+ # console - getty
81
+ #
82
+ # This service maintains a console on tty1 from the point the system is
83
+ # started until it is shut down again.
84
+
85
+ start on stopped rc RUNLEVEL=[2345]
86
+ stop on runlevel [!2345]
87
+
88
+ respawn
89
+ exec /sbin/getty -8 38400 /dev/console
90
+ EOF
91
+
92
+ cat <<EOF > $rootfs/lib/init/fstab
93
+ # /lib/init/fstab: lxc system fstab
94
+ none /spu spufs gid=spu,optional 0 0
95
+ none /tmp none defaults 0 0
96
+ none /var/lock tmpfs nodev,noexec,nosuid,showthrough 0 0
97
+ none /lib/init/rw tmpfs mode=0755,nosuid,optional 0 0
98
+ EOF
99
+
100
+ # reconfigure some services
101
+ if [ -z "$LANG" ]; then
102
+ chroot $rootfs locale-gen en_US.UTF-8
103
+ chroot $rootfs update-locale LANG=en_US.UTF-8
104
+ else
105
+ chroot $rootfs locale-gen $LANG
106
+ chroot $rootfs update-locale LANG=$LANG
107
+ fi
108
+
109
+ # remove pointless services in a container
110
+ chroot $rootfs /usr/sbin/update-rc.d -f ondemand remove
111
+
112
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls u*.conf); do mv $f $f.orig; done'
113
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls tty[2-9].conf); do mv $f $f.orig; done'
114
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls plymouth*.conf); do mv $f $f.orig; done'
115
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls hwclock*.conf); do mv $f $f.orig; done'
116
+ chroot $rootfs /bin/bash -c 'cd /etc/init; for f in $(ls module*.conf); do mv $f $f.orig; done'
117
+
118
+ echo "Set root password to 'root'"
119
+ echo "root:root" | chroot $rootfs chpasswd
120
+
121
+ return 0
122
+ }
123
+
124
+ copy_ubuntu()
125
+ {
126
+ cache=$1
127
+ arch=$2
128
+ rootfs=$3
129
+
130
+ # make a local copy of the miniubuntu
131
+ echo "Extracting rootfs image to $rootfs ..."
132
+ mkdir $rootfs
133
+ tar zxf $cache/lucid-$arch.tar.gz -C $rootfs || return 1
134
+ return 0
135
+ }
136
+
137
+ install_ubuntu()
138
+ {
139
+ cache="/var/cache/lxc"
140
+ rootfs=$1
141
+ mkdir -p /var/lock/subsys/
142
+ (
143
+ flock -n -x 200
144
+ if [ $? -ne 0 ]; then
145
+ echo "Cache repository is busy."
146
+ return 1
147
+ fi
148
+
149
+ arch=$(arch)
150
+ if [ "$arch" == "x86_64" ]; then
151
+ arch=amd64
152
+ fi
153
+
154
+ if [ "$arch" == "i686" ]; then
155
+ arch=i386
156
+ fi
157
+
158
+ echo "Checking image cache in $cache/rootfs-$arch ... "
159
+ if [ ! -e "$cache/rootfs-$arch" ]; then
160
+ if [ $? -ne 0 ]; then
161
+ echo "Failed to download 'ubuntu base'"
162
+ return 1
163
+ fi
164
+ fi
165
+
166
+ copy_ubuntu $cache $arch $rootfs
167
+ if [ $? -ne 0 ]; then
168
+ echo "Failed to copy rootfs"
169
+ return 1
170
+ fi
171
+
172
+ return 0
173
+
174
+ ) 200>/var/lock/subsys/lxc
175
+
176
+ return $?
177
+ }
178
+
179
+ copy_configuration()
180
+ {
181
+ path=$1
182
+ rootfs=$2
183
+ name=$3
184
+
185
+ cat <<EOF >> $path/config
186
+ lxc.utsname = $name
187
+
188
+ lxc.tty = 4
189
+ lxc.pts = 1024
190
+ lxc.rootfs = $rootfs
191
+ lxc.mount = $path/fstab
192
+
193
+ lxc.cgroup.devices.deny = a
194
+ # /dev/null and zero
195
+ lxc.cgroup.devices.allow = c 1:3 rwm
196
+ lxc.cgroup.devices.allow = c 1:5 rwm
197
+ # consoles
198
+ lxc.cgroup.devices.allow = c 5:1 rwm
199
+ lxc.cgroup.devices.allow = c 5:0 rwm
200
+ lxc.cgroup.devices.allow = c 4:0 rwm
201
+ lxc.cgroup.devices.allow = c 4:1 rwm
202
+ # /dev/{,u}random
203
+ lxc.cgroup.devices.allow = c 1:9 rwm
204
+ lxc.cgroup.devices.allow = c 1:8 rwm
205
+ lxc.cgroup.devices.allow = c 136:* rwm
206
+ lxc.cgroup.devices.allow = c 5:2 rwm
207
+ # rtc
208
+ lxc.cgroup.devices.allow = c 254:0 rwm
209
+ EOF
210
+
211
+ cat <<EOF > $path/fstab
212
+ proc $rootfs/proc proc nodev,noexec,nosuid 0 0
213
+ devpts $rootfs/dev/pts devpts defaults 0 0
214
+ sysfs $rootfs/sys sysfs defaults 0 0
215
+ EOF
216
+
217
+ if [ $? -ne 0 ]; then
218
+ echo "Failed to add configuration"
219
+ return 1
220
+ fi
221
+
222
+ return 0
223
+ }
224
+
225
+ clean()
226
+ {
227
+ cache="/var/cache/lxc"
228
+
229
+ if [ ! -e $cache ]; then
230
+ exit 0
231
+ fi
232
+
233
+ # lock, so we won't purge while someone is creating a repository
234
+ (
235
+ flock -n -x 200
236
+ if [ $? != 0 ]; then
237
+ echo "Cache repository is busy."
238
+ exit 1
239
+ fi
240
+
241
+ echo -n "Purging the download cache..."
242
+ rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
243
+ exit 0
244
+
245
+ ) 200>/var/lock/subsys/lxc
246
+ }
247
+
248
+ usage()
249
+ {
250
+ cat <<EOF
251
+ $1 -h|--help -p|--path=<path> --clean
252
+ EOF
253
+ return 0
254
+ }
255
+
256
+ options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
257
+ if [ $? -ne 0 ]; then
258
+ usage $(basename $0)
259
+ exit 1
260
+ fi
261
+ eval set -- "$options"
262
+
263
+ while true
264
+ do
265
+ case "$1" in
266
+ -h|--help) usage $0 && exit 0;;
267
+ -p|--path) path=$2; shift 2;;
268
+ -n|--name) name=$2; shift 2;;
269
+ -c|--clean) clean=$2; shift 2;;
270
+ --) shift 1; break ;;
271
+ *) break ;;
272
+ esac
273
+ done
274
+
275
+ if [ ! -z "$clean" -a -z "$path" ]; then
276
+ clean || exit 1
277
+ exit 0
278
+ fi
279
+
280
+ if [ -z "$path" ]; then
281
+ echo "'path' parameter is required"
282
+ exit 1
283
+ fi
284
+
285
+ if [ "$(id -u)" != "0" ]; then
286
+ echo "This script should be run as 'root'"
287
+ exit 1
288
+ fi
289
+
290
+ rootfs=$path/rootfs
291
+
292
+ install_ubuntu $rootfs
293
+ if [ $? -ne 0 ]; then
294
+ echo "failed to install ubuntu"
295
+ exit 1
296
+ fi
297
+
298
+ configure_ubuntu $rootfs $name
299
+ if [ $? -ne 0 ]; then
300
+ echo "failed to configure ubuntu for a container"
301
+ exit 1
302
+ fi
303
+
304
+ copy_configuration $path $rootfs $name
305
+ if [ $? -ne 0 ]; then
306
+ echo "failed write configuration file"
307
+ exit 1
308
+ fi
309
+
310
+ if [ ! -z $clean ]; then
311
+ clean || exit 1
312
+ exit 0
313
+ fi