toft 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/Rakefile +13 -0
- data/features/checker.feature +1 -1
- data/features/step_definitions/node.rb +2 -2
- data/features/support/env.rb +1 -1
- data/lib/toft/node.rb +7 -6
- data/lib/toft/node_controller.rb +2 -2
- data/lib/toft/version.rb +1 -1
- data/lib/toft.rb +2 -2
- data/scripts/centos/bin/lxc-prepare-host +39 -0
- data/scripts/cookbooks/lxc/files/default/lxc-create-ubuntu-image +26 -12
- data/scripts/cookbooks/lxc/recipes/default.rb +7 -1
- data/scripts/cookbooks/lxc/templates/default/lxc-lucid-chef +11 -7
- data/scripts/cookbooks/lxc/templates/default/lxc-natty-chef +253 -0
- data/scripts/{bash → ubuntu/bin}/install-chef-ubuntu.sh +8 -0
- data/scripts/{bash → ubuntu/bin}/install-rvm.sh +2 -0
- data/scripts/ubuntu/bin/lxc-create-centos-image +56 -0
- data/scripts/ubuntu/bin/lxc-create-ubuntu-image +75 -0
- data/scripts/ubuntu/bin/lxc-prepare-host +24 -0
- data/scripts/ubuntu/lxc-templates/lxc-centos-6 +283 -0
- data/scripts/ubuntu/lxc-templates/lxc-lucid +332 -0
- data/scripts/ubuntu/lxc-templates/lxc-natty +253 -0
- metadata +15 -7
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -1 +1,14 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "clean artifacts"
|
4
|
+
task :clean do
|
5
|
+
`rm -rf pkg`
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "build gem and scripts package"
|
9
|
+
task :package => [:build, :package_scripts]
|
10
|
+
|
11
|
+
task :package_scripts do
|
12
|
+
mkdir_p "pkg"
|
13
|
+
`tar zcf pkg/toft_ubuntu_scripts-#{Toft::VERSION}.tar.gz scripts/ubuntu`
|
14
|
+
end
|
data/features/checker.feature
CHANGED
@@ -8,7 +8,7 @@ Scenario: Dir checker
|
|
8
8
|
|
9
9
|
Scenario: File checker
|
10
10
|
Given I have a clean running node "n1" with ip "192.168.20.2"
|
11
|
-
When Running ssh command "if getent passwd n1; then userdel n1; fi; useradd -m n1" on "n1" should succeed
|
11
|
+
When Running ssh command "if getent passwd n1; then userdel -fr n1; fi; useradd -m n1" on "n1" should succeed
|
12
12
|
And Running ssh command "sudo -u n1 touch /tmp/a" on "n1" should succeed
|
13
13
|
Then Node "n1" should have file or directory "/tmp/a"
|
14
14
|
And Node "n1" should have "regular empty file" "/tmp/a" owned by user "n1" and group "n1" with permission "644"
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Given /^I have a clean running node "([^"]*)" with ip "([^"]*)"$/ do |node, ip|
|
2
|
-
create_node node, ip
|
2
|
+
create_node node, ip, "centos-6"
|
3
3
|
@n1.start
|
4
4
|
@n1.rm "/tmp/stub"
|
5
5
|
end
|
6
6
|
|
7
7
|
When /^I add another node "([^"]*)" with ip "([^"]*)"$/ do |node, ip|
|
8
|
-
create_node node, ip
|
8
|
+
create_node node, ip, "centos-6"
|
9
9
|
end
|
10
10
|
|
11
11
|
When /^I destroy node "([^"]*)"$/ do |node|
|
data/features/support/env.rb
CHANGED
data/lib/toft/node.rb
CHANGED
@@ -37,12 +37,12 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
|
|
37
37
|
|
38
38
|
include Observable
|
39
39
|
|
40
|
-
def initialize(hostname, ip)
|
40
|
+
def initialize(hostname, ip, type)
|
41
41
|
@hostname = hostname
|
42
42
|
@ip = ip
|
43
43
|
unless exists?
|
44
44
|
conf_file = generate_lxc_config
|
45
|
-
system "lxc-create -n #{hostname} -f #{conf_file} -t
|
45
|
+
system "lxc-create -n #{hostname} -f #{conf_file} -t #{type.to_s}"
|
46
46
|
end
|
47
47
|
@chef_runner = Toft::Chef::ChefRunner.new("#{rootfs}") do |chef_command|
|
48
48
|
run_ssh chef_command
|
@@ -78,17 +78,18 @@ CQWv13UgQjiHgQILXSb7xdzpWK1wpDoqIEWQugRyPQDeZhPWVbB4Lg==
|
|
78
78
|
def run_ssh(command)
|
79
79
|
raise ArgumentError, "Trying to run empty command on node #{@hostname}", caller if command.blank?
|
80
80
|
output = ""
|
81
|
+
error = false
|
81
82
|
Net::SSH.start(@ip, "root", :key_data => [PRIVATE_KEY]) do |ssh|
|
82
83
|
ssh.exec! command do |ch, stream, data|
|
83
84
|
if stream == :stderr
|
84
|
-
|
85
|
-
else
|
86
|
-
output += data
|
85
|
+
error = true
|
87
86
|
end
|
87
|
+
output += data
|
88
88
|
end
|
89
89
|
end
|
90
|
+
raise RuntimeError, output, caller if error
|
90
91
|
puts output
|
91
|
-
yield output if block_given?
|
92
|
+
return yield output if block_given?
|
92
93
|
return true
|
93
94
|
end
|
94
95
|
|
data/lib/toft/node_controller.rb
CHANGED
data/lib/toft/version.rb
CHANGED
data/lib/toft.rb
CHANGED
@@ -8,8 +8,8 @@ module Toft
|
|
8
8
|
attr_accessor :cookbook_path, :role_path
|
9
9
|
end
|
10
10
|
|
11
|
-
def create_node(hostname, ip)
|
12
|
-
NodeController.instance.create_node(hostname, ip)
|
11
|
+
def create_node(hostname, ip, type)
|
12
|
+
NodeController.instance.create_node(hostname, ip, type)
|
13
13
|
end
|
14
14
|
|
15
15
|
def find(hostname)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
username=`id -nu`
|
4
|
+
if [ ! "$username" = "root" ]; then
|
5
|
+
echo "This command has to be run as root!"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
9
|
+
# intsall lxc
|
10
|
+
if [[ ! -f /usr/bin/lxc-ls ]]; then
|
11
|
+
(cd /tmp && \
|
12
|
+
wget http://lxc.sourceforge.net/download/lxc/lxc-0.7.4.tar.gz && \
|
13
|
+
tar zxf lxc-0.7.4.tar.gz && \
|
14
|
+
cd lxc-0.7.4 && \
|
15
|
+
./configure --prefix=/usr && \
|
16
|
+
make && \
|
17
|
+
make install)
|
18
|
+
fi
|
19
|
+
|
20
|
+
yum install bridge-utils
|
21
|
+
|
22
|
+
if [[ ! `ip link ls dev br0` ]]; then
|
23
|
+
brctl addbr br0
|
24
|
+
ifconfig br0 192.168.20.1 netmask 255.255.255.0 up
|
25
|
+
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
26
|
+
sysctl -w net.ipv4.ip_forward=1
|
27
|
+
fi
|
28
|
+
|
29
|
+
if [[ ! -d /cgroup ]]; then
|
30
|
+
mkdir -p /cgroup
|
31
|
+
fi
|
32
|
+
|
33
|
+
if [[ ! `mount | grep cgroup` ]]; then
|
34
|
+
mount none -t cgroup /cgroup
|
35
|
+
fi
|
36
|
+
|
37
|
+
# allow people to ping this machine
|
38
|
+
iptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited
|
39
|
+
iptables -D INPUT -j REJECT --reject-with icmp-host-prohibited
|
@@ -1,7 +1,18 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
+
if [ $# -eq 0 ]; then
|
4
|
+
echo "Usage: `basename $0` <ubuntu-suite>"
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
username=`id -nu`
|
9
|
+
if [ ! "$username" = "root" ]; then
|
10
|
+
echo "This command has to be run as root!"
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
|
3
14
|
cache="/var/cache/lxc/ubuntu"
|
4
|
-
suite
|
15
|
+
suite=$1
|
5
16
|
|
6
17
|
arch=$(arch)
|
7
18
|
if [ "$arch" == "x86_64" ]; then
|
@@ -17,29 +28,31 @@ if [ -e "$cache/$suite-$arch.tar.gz" ]; then
|
|
17
28
|
exit 0
|
18
29
|
fi
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
|
31
|
+
lucid_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,dhcp3-client,ssh,lsb-release,wget,gpgv,gnupg,sudo,ruby,rubygems1.8,ruby-dev,libopenssl-ruby,build-essential,wget,ssl-cert
|
32
|
+
natty_packages=dialog,apt,apt-utils,resolvconf,iproute,inetutils-ping,isc-dhcp-client,isc-dhcp-common,ssh,lsb-release,gnupg,netbase,lxcguest,sudo,ruby,rubygems1.8,ruby-dev,libruby,build-essential,wget,ssl-cert
|
23
33
|
# check the mini ubuntu was not already downloaded
|
24
|
-
|
34
|
+
rm -rf "$cache/$suite-$arch"
|
35
|
+
mkdir -p "$cache/$suite-$arch"
|
25
36
|
if [ $? -ne 0 ]; then
|
26
|
-
echo "Failed to create '$cache
|
37
|
+
echo "Failed to create '$cache/$suite-$arch' directory"
|
27
38
|
exit 1
|
28
39
|
fi
|
29
40
|
|
30
41
|
# download a mini ubuntu into a cache
|
31
42
|
echo "Downloading ubuntu minimal ..."
|
32
|
-
|
43
|
+
eval "packages=\$${suite}_packages"
|
44
|
+
cmd="debootstrap --verbose --variant=minbase --components=main,universe --arch=$arch --include=$packages $suite $cache/$suite-$arch"
|
45
|
+
echo $cmd
|
46
|
+
eval $cmd
|
33
47
|
if [ $? -ne 0 ]; then
|
34
48
|
echo "Failed to download the rootfs, aborting."
|
35
49
|
exit 1
|
36
50
|
fi
|
37
51
|
|
38
|
-
mv "$cache/partial-$arch" "$cache/rootfs-$arch"
|
39
52
|
echo "Download complete."
|
40
53
|
|
41
54
|
# install chef
|
42
|
-
cat <<EOF > "$cache
|
55
|
+
cat <<EOF > "$cache/$suite-$arch/tmp/install-chef-ubuntu.sh"
|
43
56
|
echo "deb http://apt.opscode.com/ $suite-0.10 main" | tee /etc/apt/sources.list.d/opscode.list
|
44
57
|
|
45
58
|
mkdir -p /etc/apt/trusted.gpg.d
|
@@ -52,10 +65,11 @@ yes | apt-get install opscode-keyring --force-yes -y # permanent upgradeable key
|
|
52
65
|
export DEBIAN_FRONTEND=noninteractive
|
53
66
|
apt-get install chef --force-yes -qy
|
54
67
|
EOF
|
55
|
-
chroot "$cache
|
68
|
+
chroot "$cache/$suite-$arch" bash /tmp/install-chef-ubuntu.sh
|
56
69
|
|
57
70
|
# compress root image
|
58
|
-
|
59
|
-
|
71
|
+
echo "Packaging rootfs ..."
|
72
|
+
(cd $cache/$suite-$arch && tar zcf $suite-$arch.tar.gz .)
|
73
|
+
mv $cache/$suite-$arch/$suite-$arch.tar.gz $cache
|
60
74
|
|
61
75
|
|
@@ -29,6 +29,12 @@ template "/usr/lib/lxc/templates/lxc-lucid-chef" do
|
|
29
29
|
action :create
|
30
30
|
end
|
31
31
|
|
32
|
+
template "/usr/lib/lxc/templates/lxc-natty-chef" do
|
33
|
+
source "lxc-natty-chef"
|
34
|
+
mode "0755"
|
35
|
+
action :create
|
36
|
+
end
|
37
|
+
|
32
38
|
cookbook_file "/usr/local/bin/lxc-create-ubuntu-image" do
|
33
39
|
source "lxc-create-ubuntu-image"
|
34
40
|
mode "0755"
|
@@ -36,7 +42,7 @@ end
|
|
36
42
|
|
37
43
|
bash "create ubuntu rootfs image ... this will take a while" do
|
38
44
|
code <<-EOH
|
39
|
-
/usr/local/bin/lxc-create-ubuntu-image
|
45
|
+
/usr/local/bin/lxc-create-ubuntu-image natty
|
40
46
|
EOH
|
41
47
|
end
|
42
48
|
|
@@ -1,10 +1,16 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
+
echo "Creating lucid node..."
|
4
|
+
|
3
5
|
configure_ubuntu()
|
4
6
|
{
|
5
7
|
rootfs=$1
|
6
8
|
hostname=$2
|
7
9
|
|
10
|
+
# disable selinux in ubuntu
|
11
|
+
mkdir -p $rootfs/selinux
|
12
|
+
echo 0 > $rootfs/selinux/enforce
|
13
|
+
|
8
14
|
# add host root ssh access
|
9
15
|
mkdir $rootfs/root/.ssh
|
10
16
|
chmod 0600 $rootfs/root/.ssh
|
@@ -104,15 +110,13 @@ none /var/lock tmpfs nodev,noexec,nosuid,sh
|
|
104
110
|
none /lib/init/rw tmpfs mode=0755,nosuid,optional 0 0
|
105
111
|
EOF
|
106
112
|
|
107
|
-
|
108
|
-
|
109
113
|
# reconfigure some services
|
110
114
|
if [ -z "$LANG" ]; then
|
111
|
-
|
112
|
-
|
115
|
+
chroot $rootfs locale-gen en_US.UTF-8
|
116
|
+
chroot $rootfs update-locale LANG=en_US.UTF-8
|
113
117
|
else
|
114
|
-
|
115
|
-
|
118
|
+
chroot $rootfs locale-gen $LANG
|
119
|
+
chroot $rootfs update-locale LANG=$LANG
|
116
120
|
fi
|
117
121
|
|
118
122
|
# remove pointless services in a container
|
@@ -137,7 +141,7 @@ copy_ubuntu()
|
|
137
141
|
rootfs=$3
|
138
142
|
|
139
143
|
# make a local copy of the miniubuntu
|
140
|
-
echo
|
144
|
+
echo "Extracting rootfs image to $rootfs ..."
|
141
145
|
mkdir $rootfs
|
142
146
|
tar zxf $cache/lucid-$arch.tar.gz -C $rootfs || return 1
|
143
147
|
return 0
|
@@ -0,0 +1,253 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
echo "Creating natty 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
|
+
# copy host resolve
|
22
|
+
rm $rootfs/etc/resolv.conf
|
23
|
+
cp /etc/resolv.conf $rootfs/etc/resolv.conf
|
24
|
+
|
25
|
+
# add default route to host
|
26
|
+
cat <<EOF > $rootfs/etc/rc.local
|
27
|
+
#!/bin/sh -e
|
28
|
+
route add default gw <%= node.network.gateway_ip %>
|
29
|
+
exit 0
|
30
|
+
EOF
|
31
|
+
|
32
|
+
# disable selinux in ubuntu
|
33
|
+
mkdir -p $rootfs/selinux
|
34
|
+
echo 0 > $rootfs/selinux/enforce
|
35
|
+
|
36
|
+
# set the hostname
|
37
|
+
cat <<EOF > $rootfs/etc/hostname
|
38
|
+
$hostname
|
39
|
+
EOF
|
40
|
+
# set minimal hosts
|
41
|
+
cat <<EOF > $rootfs/etc/hosts
|
42
|
+
127.0.0.1 localhost $hostname
|
43
|
+
EOF
|
44
|
+
|
45
|
+
# suppress log level output for udev
|
46
|
+
sed -i "s/=\"err\"/=0/" $rootfs/etc/udev/udev.conf
|
47
|
+
|
48
|
+
# remove jobs for consoles 5 and 6 since we only create 4 consoles in
|
49
|
+
# this template
|
50
|
+
rm -f $rootfs/etc/init/tty{5,6}.conf
|
51
|
+
|
52
|
+
echo "Set root password to 'root'"
|
53
|
+
echo "root:root" | chroot $rootfs chpasswd
|
54
|
+
|
55
|
+
return 0
|
56
|
+
}
|
57
|
+
|
58
|
+
copy_ubuntu()
|
59
|
+
{
|
60
|
+
cache=$1
|
61
|
+
arch=$2
|
62
|
+
rootfs=$3
|
63
|
+
|
64
|
+
# make a local copy of the miniubuntu
|
65
|
+
echo "Extracting rootfs image to $rootfs ..."
|
66
|
+
mkdir $rootfs
|
67
|
+
tar zxf $cache/natty-$arch.tar.gz -C $rootfs || return 1
|
68
|
+
return 0
|
69
|
+
}
|
70
|
+
|
71
|
+
install_ubuntu()
|
72
|
+
{
|
73
|
+
cache="/var/cache/lxc/ubuntu"
|
74
|
+
rootfs=$1
|
75
|
+
mkdir -p /var/lock/subsys/
|
76
|
+
(
|
77
|
+
flock -n -x 200
|
78
|
+
if [ $? -ne 0 ]; then
|
79
|
+
echo "Cache repository is busy."
|
80
|
+
return 1
|
81
|
+
fi
|
82
|
+
|
83
|
+
arch=$(arch)
|
84
|
+
if [ "$arch" == "x86_64" ]; then
|
85
|
+
arch=amd64
|
86
|
+
fi
|
87
|
+
|
88
|
+
if [ "$arch" == "i686" ]; then
|
89
|
+
arch=i386
|
90
|
+
fi
|
91
|
+
|
92
|
+
echo "Checking image cache in $cache/rootfs-$arch ... "
|
93
|
+
if [ ! -e "$cache/rootfs-$arch" ]; then
|
94
|
+
if [ $? -ne 0 ]; then
|
95
|
+
echo "Failed to download 'ubuntu base'"
|
96
|
+
return 1
|
97
|
+
fi
|
98
|
+
fi
|
99
|
+
|
100
|
+
copy_ubuntu $cache $arch $rootfs
|
101
|
+
if [ $? -ne 0 ]; then
|
102
|
+
echo "Failed to copy rootfs"
|
103
|
+
return 1
|
104
|
+
fi
|
105
|
+
|
106
|
+
return 0
|
107
|
+
|
108
|
+
) 200>/var/lock/subsys/lxc
|
109
|
+
|
110
|
+
return $?
|
111
|
+
}
|
112
|
+
|
113
|
+
copy_configuration()
|
114
|
+
{
|
115
|
+
path=$1
|
116
|
+
rootfs=$2
|
117
|
+
name=$3
|
118
|
+
|
119
|
+
cat <<EOF >> $path/config
|
120
|
+
lxc.utsname = $name
|
121
|
+
|
122
|
+
lxc.tty = 4
|
123
|
+
lxc.pts = 1024
|
124
|
+
lxc.rootfs = $rootfs
|
125
|
+
lxc.mount = $path/fstab
|
126
|
+
|
127
|
+
lxc.cgroup.devices.deny = a
|
128
|
+
# /dev/null and zero
|
129
|
+
lxc.cgroup.devices.allow = c 1:3 rwm
|
130
|
+
lxc.cgroup.devices.allow = c 1:5 rwm
|
131
|
+
# consoles
|
132
|
+
lxc.cgroup.devices.allow = c 5:1 rwm
|
133
|
+
lxc.cgroup.devices.allow = c 5:0 rwm
|
134
|
+
# lxc.cgroup.devices.allow = c 4:0 rwm
|
135
|
+
# lxc.cgroup.devices.allow = c 4:1 rwm
|
136
|
+
# /dev/{,u}random
|
137
|
+
lxc.cgroup.devices.allow = c 1:9 rwm
|
138
|
+
lxc.cgroup.devices.allow = c 1:8 rwm
|
139
|
+
lxc.cgroup.devices.allow = c 136:* rwm
|
140
|
+
lxc.cgroup.devices.allow = c 5:2 rwm
|
141
|
+
# rtc
|
142
|
+
lxc.cgroup.devices.allow = c 254:0 rwm
|
143
|
+
EOF
|
144
|
+
|
145
|
+
cat <<EOF > $path/fstab
|
146
|
+
proc $rootfs/proc proc nodev,noexec,nosuid 0 0
|
147
|
+
devpts $rootfs/dev/pts devpts defaults 0 0
|
148
|
+
sysfs $rootfs/sys sysfs defaults 0 0
|
149
|
+
EOF
|
150
|
+
|
151
|
+
if [ $? -ne 0 ]; then
|
152
|
+
echo "Failed to add configuration"
|
153
|
+
return 1
|
154
|
+
fi
|
155
|
+
|
156
|
+
return 0
|
157
|
+
}
|
158
|
+
|
159
|
+
clean()
|
160
|
+
{
|
161
|
+
cache="/var/cache/lxc/ubuntu"
|
162
|
+
|
163
|
+
if [ ! -e $cache ]; then
|
164
|
+
exit 0
|
165
|
+
fi
|
166
|
+
|
167
|
+
# lock, so we won't purge while someone is creating a repository
|
168
|
+
(
|
169
|
+
flock -n -x 200
|
170
|
+
if [ $? != 0 ]; then
|
171
|
+
echo "Cache repository is busy."
|
172
|
+
exit 1
|
173
|
+
fi
|
174
|
+
|
175
|
+
echo -n "Purging the download cache..."
|
176
|
+
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
|
177
|
+
exit 0
|
178
|
+
|
179
|
+
) 200>/var/lock/subsys/lxc
|
180
|
+
}
|
181
|
+
|
182
|
+
usage()
|
183
|
+
{
|
184
|
+
cat <<EOF
|
185
|
+
$1 -h|--help -p|--path=<path> --clean
|
186
|
+
EOF
|
187
|
+
return 0
|
188
|
+
}
|
189
|
+
|
190
|
+
options=$(getopt -o hp:n:c -l help,path:,name:,clean -- "$@")
|
191
|
+
if [ $? -ne 0 ]; then
|
192
|
+
usage $(basename $0)
|
193
|
+
exit 1
|
194
|
+
fi
|
195
|
+
eval set -- "$options"
|
196
|
+
|
197
|
+
while true
|
198
|
+
do
|
199
|
+
case "$1" in
|
200
|
+
-h|--help) usage $0 && exit 0;;
|
201
|
+
-p|--path) path=$2; shift 2;;
|
202
|
+
-n|--name) name=$2; shift 2;;
|
203
|
+
-c|--clean) clean=$2; shift 2;;
|
204
|
+
--) shift 1; break ;;
|
205
|
+
*) break ;;
|
206
|
+
esac
|
207
|
+
done
|
208
|
+
|
209
|
+
if [ ! -z "$clean" -a -z "$path" ]; then
|
210
|
+
clean || exit 1
|
211
|
+
exit 0
|
212
|
+
fi
|
213
|
+
|
214
|
+
type debootstrap
|
215
|
+
if [ $? -ne 0 ]; then
|
216
|
+
echo "'debootstrap' command is missing"
|
217
|
+
exit 1
|
218
|
+
fi
|
219
|
+
|
220
|
+
if [ -z "$path" ]; then
|
221
|
+
echo "'path' parameter is required"
|
222
|
+
exit 1
|
223
|
+
fi
|
224
|
+
|
225
|
+
if [ "$(id -u)" != "0" ]; then
|
226
|
+
echo "This script should be run as 'root'"
|
227
|
+
exit 1
|
228
|
+
fi
|
229
|
+
|
230
|
+
rootfs=$path/rootfs
|
231
|
+
|
232
|
+
install_ubuntu $rootfs
|
233
|
+
if [ $? -ne 0 ]; then
|
234
|
+
echo "failed to install ubuntu"
|
235
|
+
exit 1
|
236
|
+
fi
|
237
|
+
|
238
|
+
configure_ubuntu $rootfs $name
|
239
|
+
if [ $? -ne 0 ]; then
|
240
|
+
echo "failed to configure ubuntu for a container"
|
241
|
+
exit 1
|
242
|
+
fi
|
243
|
+
|
244
|
+
copy_configuration $path $rootfs $name
|
245
|
+
if [ $? -ne 0 ]; then
|
246
|
+
echo "failed write configuration file"
|
247
|
+
exit 1
|
248
|
+
fi
|
249
|
+
|
250
|
+
if [ ! -z $clean ]; then
|
251
|
+
clean || exit 1
|
252
|
+
exit 0
|
253
|
+
fi
|
@@ -1,3 +1,11 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
username=`id -nu`
|
4
|
+
if [ ! "$username" = "root" ]; then
|
5
|
+
echo "This command has to be run as root!"
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
1
9
|
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list
|
2
10
|
|
3
11
|
mkdir -p /etc/apt/trusted.gpg.d
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
if [ $# -eq 0 ]; then
|
4
|
+
echo "Usage: `basename $0` <centos-6|centos-5|centos-4>"
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
username=`id -nu`
|
9
|
+
if [ ! "$username" = "root" ]; then
|
10
|
+
echo "This command has to be run as root!"
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
|
14
|
+
cache="/var/cache/lxc/centos"
|
15
|
+
suite=$1
|
16
|
+
|
17
|
+
arch=$(arch)
|
18
|
+
if [ "$arch" == "i686" ]; then
|
19
|
+
arch=i386
|
20
|
+
fi
|
21
|
+
|
22
|
+
if [ -e "$cache/$suite-$arch.tar.gz" ]; then
|
23
|
+
echo "Cache rootfs already exists!"
|
24
|
+
exit 0
|
25
|
+
fi
|
26
|
+
|
27
|
+
# install latest rinse
|
28
|
+
if [[ ! `type rinse` ]]; then
|
29
|
+
echo "Rinse does not exist. Installing..."
|
30
|
+
(cd /tmp && \
|
31
|
+
wget http://www.steve.org.uk/Software/rinse/rinse-1.9.1.tar.gz && \
|
32
|
+
tar zxf rinse-1.9.1.tar.gz && \
|
33
|
+
cd rinse-1.9.1 && \
|
34
|
+
make install)
|
35
|
+
fi
|
36
|
+
|
37
|
+
# install rpm
|
38
|
+
apt-get install -y rpm
|
39
|
+
|
40
|
+
# create centos image using rinse
|
41
|
+
cat <<EOF > /tmp/after_post_install
|
42
|
+
chroot $cache/$suite-$arch rpm -Uvh http://rbel.co/rbel6
|
43
|
+
chroot $cache/$suite-$arch yum -y install man sudo openssh-server openssh-clients rubygem-chef
|
44
|
+
EOF
|
45
|
+
chmod +x /tmp/after_post_install
|
46
|
+
|
47
|
+
echo "Creating $suite-$arch image"
|
48
|
+
rinse --config /etc/rinse/rinse.conf \
|
49
|
+
--arch=$arch --distribution=$suite \
|
50
|
+
--directory=$cache/$suite-$arch \
|
51
|
+
--after-post-install=/tmp/after_post_install
|
52
|
+
|
53
|
+
# compress root image
|
54
|
+
echo "Packaging rootfs ..."
|
55
|
+
(cd $cache/$suite-$arch && tar zcf $suite-$arch.tar.gz .)
|
56
|
+
mv $cache/$suite-$arch/$suite-$arch.tar.gz $cache
|