File _run_me.sh of Package dba-ruby-rubygems-193

#!/usr/bin/perl


# oste020 20123-01-17
#
# run this file to create a spec file for all gems listed below
# the source will be retrieved from rubygems.org and be installed locally to a tempdir
# when done, check the specfile with a local build, if successful  do "osc addremove *" on the shell
#
# requires RPMs dba-ruby-193 dba-ruby-193-devel on local buildserver

# get these gems
my @gems=qw( 
	bundler-1.2.3
	rubygems-bundler-1.1.0
	json_pure-1.7.6
	hiera-1.1.2
);

# for puppet:		json_pure hiera

# init
my $rubypath="/DBA/ruby/1.9.3";
my $rubypkg="dba-ruby-193";
my $c=0;
my %cfg;

foreach $gem (@gems) {

	# get source
	print "get source: $gem.gem".$/;
	`wget "http://rubygems.org/downloads/$gem.gem" -nv -N`.$/;
	next if $?;

	# build as subpackage of rubygems
	$cfg{source}	.= "Source$c:	$gem.gem\n"	;
	$cfg{prep}	.= "%{dba_ruby_path}/bin/gem unpack %{SOURCE$c}\n";
	$cfg{install}	.= "%{dba_ruby_path}/bin/gem install --local --force --no-rdoc --no-ri -i %{buildroot}%{gempath} %{SOURCE$c}\n";
	
	$cfg{package}	.= <<EOL;
%package $gem
Summary:        Ruby GEM built for %{dba_ruby_pkg}: $gem
Group:		System Environment/Base
Requires:	$rubypkg

%description $gem
Ruby GEM built for %{dba_ruby_pkg}: $gem

EOL
	# add to "all" metapackage
	$cfg{meta}	.= "Requires: %{pkg_name}-%{pkg_vers}-$gem\n";

	# we have to build the gems locally to find the installed files and dirs
	print "build source $gem.gem locally\n";
	`mkdir buildtmp`;
	`$rubypath/bin/gem install --local --force --no-rdoc --no-ri -i buildtmp $gem.gem`;

	# list files
	$files=`find buildtmp -type f`;
	$files=~s/buildtmp/%{gempath}/g;

	# list dirs
	$dirs =`find buildtmp -type d`;
	$dirs=~s/buildtmp/%dir %{gempath}/g;

	`rm -rf buildtmp`;

	# add files+dirs to subpackages
	$cfg{files}	.= <<EOL;
%files $gem
%defattr(-,root,root,-)
$dirs
$files
EOL

	$c++;
}


# read spec template
open (IN , 'dba-ruby-rubygems-193.spec.tmpl');
$/=undef; $template=<IN>; $/="\n";
close IN;

# replace into template
$template=~s/###sed_([\w\d]*)###/$cfg{$1}/g;

# write template
open (OUT, '>dba-ruby-rubygems-193.spec');
print OUT $template;
close OUT;

print "spec file written".$/;


#
# now inspect or build the specfile
#

openSUSE Build Service is sponsored by