Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 2701669

Browse files
committed
Remove dependency on expect package.
Instead use ruby, PTY and expect.
1 parent a6042e3 commit 2701669

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

manifests/package.pp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,12 @@
5353
}
5454
}
5555

56-
case $::kernel {
57-
'Darwin': {}
58-
default: {
59-
ensure_packages(['expect'])
60-
Package['expect'] -> Exec["update-android-package-${title}"]
61-
}
62-
}
63-
6456
file { "${android::installdir}/expect-install-${title}":
6557
content => template("android/expect-script.erb"),
58+
mode => '0755',
6659
} ->
6760
exec { "update-android-package-${title}":
68-
command => "/usr/bin/expect -f ${android::installdir}/expect-install-${title}",
61+
command => "${android::installdir}/expect-install-${title}",
6962
creates => $creates,
7063
timeout => 0,
7164
require => [Class['android::sdk']],

spec/classes/init_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
it { should contain_file("#{dir}/expect-install-platform-tools")
2121
.with_content(/android update sdk -u --all -t platform-tools/) }
2222
it { should contain_exec('update-android-package-platform-tools')
23-
.with_command("/usr/bin/expect -f #{dir}/expect-install-platform-tools") }
23+
.with_command("#{dir}/expect-install-platform-tools") }
2424

2525
it { should contain_file(dir).with( { :owner => 'root', :group => 'root' }) }
2626
it { should contain_exec('unpack-androidsdk').with( { :cwd => dir, :user => 'root' } ) }
@@ -47,7 +47,7 @@
4747
it { should contain_file("#{dir}/expect-install-platform-tools")
4848
.with_content(/android update sdk -u --all -t platform-tools --proxy-host myhost --proxy-port 1234/) }
4949
it { should contain_exec('update-android-package-platform-tools')
50-
.with_command("/usr/bin/expect -f #{dir}/expect-install-platform-tools") }
50+
.with_command("#{dir}/expect-install-platform-tools") }
5151
end
5252

5353
context 'with installdir', :compile do
@@ -100,7 +100,7 @@
100100
it { should contain_file("#{dir}/expect-install-platform-tools")
101101
.with_content(/android update sdk -u --all -t platform-tools --proxy-host myhost --proxy-port 1234/) }
102102
it { should contain_exec('update-android-package-platform-tools')
103-
.with_command("/usr/bin/expect -f #{dir}/expect-install-platform-tools") }
103+
.with_command("#{dir}/expect-install-platform-tools") }
104104

105105
it { should contain_file(dir).with( { :owner => 'root', :group => 'admin' }) }
106106
it { should contain_exec('unpack-androidsdk').with( { :cwd => dir,:user => 'root' } ) }

spec/defines/package_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
it { should contain_file("#{dir}/expect-install-android-15")
1111
.with_content(/android update sdk -u --all -t android-15/) }
1212
it { should contain_exec('update-android-package-android-15').with({
13-
:command => "/usr/bin/expect -f #{dir}/expect-install-android-15",
13+
:command => "#{dir}/expect-install-android-15",
1414
:creates => "#{dir}/android-sdk-linux/platforms/android-15",
1515
}) }
1616
end
@@ -34,7 +34,7 @@
3434
let(:params) { { :type => 'platform' } }
3535
it { should contain_file("#{dir}/expect-install-android-15").with_content(/android update sdk -u --all -t android-15/) }
3636
it { should contain_exec('update-android-package-android-15').with({
37-
:command => "/usr/bin/expect -f #{dir}/expect-install-android-15",
37+
:command => "#{dir}/expect-install-android-15",
3838
:creates => "#{dir}/android-sdk-macosx/platforms/android-15",
3939
}) }
4040
end

templates/expect-script.erb

100644100755
Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
set timeout -1;
2-
spawn <%= scope.lookupvar('android::paths::sdk_home') %>/tools/android update sdk -u --all -t <%= @title %> <%= @proxy_host %> <%= @proxy_port %>;
3-
expect {
4-
"Do you accept the license" { exp_send "y\r" ; exp_continue }
5-
"Error: Ignoring unknown package" { exit 1 }
6-
eof
7-
}
1+
#!/usr/bin/env ruby
2+
3+
require 'pty'
4+
require 'expect'
5+
6+
command="<%= scope.lookupvar('android::paths::sdk_home') %>/tools/android update sdk -u --all -t <%= @title %> <%= @proxy_host %> <%= @proxy_port %>"
7+
match=%r/^\s*Do you accept the license .* \[y\/n\]:\s*/
8+
response="y"
9+
10+
puts command
11+
12+
PTY.spawn(command) do |r,w,p|
13+
14+
w.sync = true
15+
16+
begin
17+
while true do
18+
r.expect(match)
19+
sleep(0.1)
20+
w.puts(response)
21+
end
22+
rescue Errno::EIO, PTY::ChildExited
23+
end
24+
end
25+
26+
exit
27+
# vim: set ts=2 sw=2 tw=0 et:

0 commit comments

Comments
 (0)