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

Update to new android sdk #54

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions manifests/ndk.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
include android::params
include wget

$base_path = "http://dl.google.com/android/ndk/${ndk_version}"
$ndk_installer = "${android::paths::installdir}/${ndk_version}"
$ndk_package = "android-ndk-${ndk_version}-linux-x86_64"
$base_path = "https://dl.google.com/android/repository/${ndk_package}.zip"
$ndk_installer = "${android::paths::installdir}/${ndk_package}"
wget::fetch { 'download-androidndk':
source => $base_path,
destination => $ndk_installer,
Expand Down
32 changes: 19 additions & 13 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,47 @@

$proxy_host = $android::proxy_host ? { undef => '', default => "--proxy-host ${android::proxy_host}" }
$proxy_port = $android::proxy_port ? { undef => '', default => "--proxy-port ${android::proxy_port}" }
$cleaned_title = regsubst($title, ';', '-', 'G')

case $type {
'platform-tools': {
$creates = "${android::paths::sdk_home}/platform-tools"
$create_path_suffix = 'platform-tools'
$package_name = $title
}
'platform': {
$creates = "${android::paths::sdk_home}/platforms/${title}"
$create_path_suffix = "platforms/${title}"
$package_name = "platforms;${title}"
}
'system-images': {
$title_parts = split($title, '-')
$creates = "${android::paths::sdk_home}/system-images/android-${title_parts[-1]}/default/${title_parts[2]}-${title_parts[3]}"
$title_parts = split($title, ';')
$create_path_suffix = "${type}/${title_parts[0]}/${title_parts[1]}/${title_parts[2]}"
$package_name = "${type};${title}"
}
'addon': {
$creates = "${android::paths::sdk_home}/add-ons/${title}"
$create_path_suffix = "add-ons/${title}"
$package_name = "add-ons;${title}"
}
'extra': {
$title_parts = split($title, '-')
$creates = "${android::paths::sdk_home}/extras/${title_parts[1]}/${title_parts[2]}"
$title_parts = split($title, ';')
$create_path_suffix = join(['extras', join($title_parts, '/')], '/')
$package_name = "extras;${title}"
}
'build-tools': {
$title_parts = split($title, '-')
$creates = "${android::paths::sdk_home}/build-tools/${title_parts[2]}"
$create_path_suffix = "build-tools/${title}"
$package_name = "${type};${title}"
}
default: {
fail("Unsupported package type: ${type}")
}
}

file { "${android::installdir}/expect-install-${title}":
file { "${android::installdir}/expect-install-${cleaned_title}":
content => template('android/expect-script.erb'),
mode => '0755',
} ->
exec { "update-android-package-${title}":
command => "${android::installdir}/expect-install-${title}",
creates => $creates,
exec { "update-android-package-${cleaned_title}":
command => "${android::installdir}/expect-install-${cleaned_title}",
creates => "${android::paths::sdk_home}/${create_path_suffix}",
timeout => 0,
require => [Class['android::sdk']],
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#
class android::params {

$version = '22.3'
$version = '4333796'
$proxy_host = undef
$proxy_port = undef
$installdir = '/usr/local/android'

$ndk_version = 'android-ndk-r10d-linux-x86_64.bin'
$ndk_version = 'r18b'

case $::kernel {
'Linux': {
Expand Down
8 changes: 4 additions & 4 deletions manifests/paths.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
case $::kernel {
'Linux': {
$sdk_home = "${installdir}/android-sdk-linux"
$distrib_file = "android-sdk_r${version}-linux.tgz"
$distrib_file = "sdk-tools-linux-${version}.zip"
}
'Darwin': {
$sdk_home = "${installdir}/android-sdk-macosx"
$distrib_file = "android-sdk_r${version}-macosx.zip"
$sdk_home = "${installdir}/android-sdk-darwin"
$distrib_file = "sdk-tools-darwin-${version}.zip"
}
default: {
fail("Unsupported Kernel: ${::kernel} operatingsystem: ${::operatingsystem}")
}
}
$source = "http://dl.google.com/android/${distrib_file}"
$source = "https://dl.google.com/android/repository/${distrib_file}"
$archive = "${installdir}/${distrib_file}"

$toolsdir = "${sdk_home}/tools"
Expand Down
23 changes: 9 additions & 14 deletions manifests/sdk.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,26 @@
Exec { user => $android::user }
}

case $::kernel {
'Linux': {
$unpack_command = "/bin/tar -xvf ${android::paths::archive} --no-same-owner --no-same-permissions && chmod -R a+rx ${android::paths::sdk_home}"
}
'Darwin': {
$unpack_command = "/usr/bin/unzip ${android::paths::archive} && chmod -R a+rx ${android::paths::sdk_home}"
}
default: {
fail("Unsupported Kernel: ${::kernel} operatingsystem: ${::operatingsystem}")
}
}
$unpack_command = "/usr/bin/unzip -q -o ${android::paths::archive} && chmod -R a+rx ${android::paths::sdk_home}"

file { $android::paths::installdir:
ensure => directory,
owner => $android::user,
group => $android::group,
} ->
file { $android::paths::sdk_home:
ensure => directory,
owner => $android::user,
group => $android::group,
} ->
wget::fetch { 'download-androidsdk':
source => $android::paths::source,
destination => $android::paths::archive,
} ->
exec { 'unpack-androidsdk':
command => $unpack_command,
creates => $android::paths::sdk_home,
cwd => $android::paths::installdir,
creates => $android::paths::toolsdir,
cwd => $android::paths::sdk_home,
}->
file { 'android-executable':
ensure => present,
Expand All @@ -56,7 +51,7 @@
# For 64bit systems, we need to install some 32bit libraries for the SDK
# to work.
if ($::kernel == 'Linux') and ($::architecture == 'x86_64' or $::architecture == 'amd64') {
if $::lsbdistcodename == 'jessie' or $::lsbdistrelease == 14.04 {
if $::lsbdistcodename == 'jessie' or $::lsbdistcodename == 'stretch' or $::lsbdistrelease == 14.04 {
ensure_packages(['libc6-i386', 'lib32stdc++6', 'lib32gcc1', 'lib32ncurses5', 'lib32z1'])
} else {
ensure_packages($::osfamily ? {
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"description": "A Puppet module to install the Android SDK.",
"dependencies": [
{
"name": "maestrodev/wget",
"version_requirement": ">=1.0.0"
"name": "puppet/wget",
"version_requirement": ">=2.0.0"
},
{
"name": "puppetlabs/stdlib",
Expand Down
38 changes: 38 additions & 0 deletions spec/classes/sdk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,42 @@
it { should contain_package('ia32-libs') }
end

context '64bit Debian Jessie, x86_64 architecture', :compile do
let(:facts) { {
:operatingsystem => 'Debian',
:osfamily => 'Debian'
:lsbdistcodename => 'jessie'
} }
it { should_not contain_package('ia32-libs') }
end

context '64bit Debian Jessie, amd64 architecture', :compile do
let(:facts) { {
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'jessie'
:architecture => 'amd64'
} }
it { should_not contain_package('ia32-libs') }
end

context '64bit Ubuntu 14.04, x86_64 architecture', :compile do
let(:facts) { {
:operatingsystem => 'Ubuntu',
:osfamily => 'Debian'
:lsbdistrelease => '14.04'
} }
it { should_not contain_package('ia32-libs') }
end

context '64bit Ubuntu 14.04, amd64 architecture', :compile do
let(:facts) { {
:operatingsystem => 'Ubuntu',
:osfamily => 'Debian',
:lsbdistrelease => '14.04'
:architecture => 'amd64'
} }
it { should_not contain_package('ia32-libs') }
end

end
28 changes: 3 additions & 25 deletions templates/expect-script.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
#!/usr/bin/env ruby
#!/usr/bin/env bash

require 'pty'
require 'expect'
yes | <%= scope.lookupvar('android::paths::sdk_home') %>/tools/bin/sdkmanager --install --include_obsolete '<%= @package_name %>' <%= @proxy_host %> <%= @proxy_port %>

command="<%= scope.lookupvar('android::paths::sdk_home') %>/tools/android update sdk -u --all -t <%= @title %> <%= @proxy_host %> <%= @proxy_port %>"
match=%r/^\s*Do you accept the license .* \[y\/n\]:\s*/
response="y"

puts command

PTY.spawn(command) do |r,w,p|

w.sync = true

begin
while true do
r.expect(match)
sleep(0.1)
w.puts(response)
end
rescue Errno::EIO, PTY::ChildExited
end
end

exit
# vim: set ts=2 sw=2 tw=0 et:
exit 0