Commits

Xu Xiaodong committed 15e25c0

minor update

Comments (0)

Files changed (8)

 #!/usr/bin/env perl
 #
-# name:      automatically create ebuild for Perl module
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Feb 15
-# modified:  2011 Nov 12
+# name     : create_ebuild.pl, automatically create ebuild for Perl module
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Feb 15
+# modified : 2012 May 13
 #
 
 use strict;
 use warnings;
-
+use autodie;
 use HTTP::Tiny;
 use JSON::XS;
-use autodie;
 
 # Get module infomation, get_module_info($module)
 sub get_module_info {
 SRC_TEST="do"
 TEMPLETE
 
-  my $root_path = '/usr/local/portage/dev-perl';
+  my $path = "/usr/local/portage/dev-perl/$name";
 
-  mkdir $root_path unless -d $root_path;
-  chdir $root_path;
-
-  mkdir $name;
-  chdir $name;
+  mkdir $path unless -d $path;
+  chdir $path;
 
   open my ($out_fh), '>', "$name-$version.ebuild";
   print $out_fh $ebuild;

create_gem_ebuild.rb

 #!/usr/bin/env ruby
 #
-# name:      create_gem_ebuild.rb, create ebuild for rubygems
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 May 07
-# modified:  2011 May 08
+# name     : create_gem_ebuild.rb, create ebuild for rubygems
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 May 07
+# modified : 2012 May 13
 #
 
 require 'uri'
 require 'yajl/http_stream'
 
 class Ebuild
-  def initialize(name)
-    @name = name
-  end
+	def initialize(name)
+		@name = name
+	end
 
-  def create
-    url = URI.parse("http://rubygems.org/api/v1/gems/#{@name}.json")
-    Yajl::HttpStream.get(url) do |meta|
-      desc   = meta['info']
-      ver    = meta['version']
-      home   = meta['homepage_uri']
-      depend = meta['dependencies']['runtime']
+	def create
+		url = URI.parse("http://rubygems.org/api/v1/gems/#{@name}.json")
+		Yajl::HttpStream.get(url) do |meta|
+			desc   = meta['info']
+			ver    = meta['version']
+			home   = meta['homepage_uri']
+			depend = meta['dependencies']['runtime']
 
-      Dir.chdir('/usr/local/portage/dev-ruby')
-      Dir.mkdir(@name)
-      Dir.chdir(@name)
+			Dir.chdir('/usr/local/portage/dev-ruby')
+			Dir.mkdir(@name)
+			Dir.chdir(@name)
 
-      lines = []
-      lines << %Q<# Copyright 1999-2011 Gentoo Foundation>
-      lines << %Q<# Distributed under the terms of the GNU General Public License v2>
-      lines << %Q<>
-      lines << %Q<EAPI=3>
-      lines << %Q<USE_RUBY="ruby19">
-      lines << %Q<>
-      lines << %Q<RUBY_FAKEGEM_BINWRAP="">
-      lines << %Q<>
-      lines << %Q<RUBY_FAKEGEM_TASK_DOC="">
-      lines << %Q<RUBY_FAKEGEM_TASK_TEST="">
-      lines << %Q<>
-      lines << %Q<inherit ruby-fakegem>
-      lines << %Q<>
-      lines << %Q<DESCRIPTION="#{desc}">
-      lines << %Q<HOMEPAGE="#{home}">
-      lines << %Q<>
-      lines << %Q<LICENSE="MIT">
-      lines << %Q<SLOT="3.0">
-      lines << %Q<KEYWORDS="~amd64 ~x86">
-      lines << %Q<>
-      lines << %Q<IUSE="">
-      lines << %Q<>
-      lines << %Q<ruby_add_rdepend ">
+			lines = []
+			lines << %Q<# Copyright 1999-2011 Gentoo Foundation>
+			lines << %Q<# Distributed under the terms of the GNU General Public License v2>
+			lines << %Q<>
+			lines << %Q<EAPI=3>
+			lines << %Q<USE_RUBY="ruby19">
+			lines << %Q<>
+			lines << %Q<RUBY_FAKEGEM_BINWRAP="">
+			lines << %Q<>
+			lines << %Q<RUBY_FAKEGEM_TASK_DOC="">
+			lines << %Q<RUBY_FAKEGEM_TASK_TEST="">
+			lines << %Q<>
+			lines << %Q<inherit ruby-fakegem>
+			lines << %Q<>
+			lines << %Q<DESCRIPTION="#{desc}">
+			lines << %Q<HOMEPAGE="#{home}">
+			lines << %Q<>
+			lines << %Q<LICENSE="MIT">
+			lines << %Q<SLOT="3.0">
+			lines << %Q<KEYWORDS="~amd64 ~x86">
+			lines << %Q<>
+			lines << %Q<IUSE="">
+			lines << %Q<>
+			lines << %Q<ruby_add_rdepend ">
 
-      depend_name = nil
-      depend.each do |hash|
-        depend_name = hash['name']
-        lines << %Q<\tdev-ruby/#{depend_name}>
-      end
+			depend_name = nil
+			depend.each do |hash|
+				depend_name = hash['name']
+				lines << %Q<\tdev-ruby/#{depend_name}>
+			end
 
-      lines << %Q<">
-      lines << %Q<>
-      lines << %Q<all_ruby_install() {>
-      lines << %Q<\tall_fakegem_install>
-      lines << %Q<}>
-      lines.join("\n")
+			lines << %Q<">
+			lines << %Q<>
+			lines << %Q<all_ruby_install() {>
+			lines << %Q<\tall_fakegem_install>
+			lines << %Q<}>
+			lines.join("\n")
 
-      filename = "#{@name}-#{ver}.ebuild"
-      f = File.open(filename, 'w')
-      f.puts lines
-      f.close
+			filename = "#{@name}-#{ver}.ebuild"
+			f = File.open(filename, 'w')
+			f.puts lines
+			f.close
 
-      system('ebuild', filename, 'manifest')
-    end
-  end
+			system('ebuild', filename, 'manifest')
+		end
+	end
 
 end
 
 if __FILE__ == $0
-  if ARGV.empty?
-    puts 'Usage: create_gem_ebuild.rb <gem>'
-  else
-    ARGV.each do |gem|
-      eb = Ebuild.new(gem)
-      eb.create
-    end
-  end
+	if ARGV.empty?
+		puts 'Usage: create_gem_ebuild.rb <gem>'
+	else
+		ARGV.each do |gem|
+			eb = Ebuild.new(gem)
+			eb.create
+		end
+	end
 end
 #!/usr/bin/env perl
 #
-# name:      fix_java_font.pl, fix java chinese problem
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Apr 27
-# modified:  2011 Apr 27
+# name     : fix_java_font.pl, fix java chinese problem
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Apr 27
+# modified : 2012 May 13
 #
 
-use Modern::Perl;
+use strict;
+use warnings;
 
 my ($jre_ver)
-    = qx(eix -I --format '<installedversions:NAMEVERSION>' sun-jre-bin)
-    =~ m!/(.*)\Z!;
+  = qx(eix -I --format '<installedversions:NAMEVERSION>' sun-jre-bin)
+  =~ m!/(.*)\Z!;
 my $jre_path = "/opt/$jre_ver/lib/fonts/fallback";
 
 mkdir $jre_path unless -e $jre_path;
 chdir $jre_path;
 symlink '/usr/share/fonts/ttf-droid/DroidSansFallback.ttf',
-    'DroidSansFallback.ttf';
+  'DroidSansFallback.ttf';
 system 'mkfontdir';
 system 'mkfontscale';
 #!/usr/bin/env perl
 #
-# name:      not_dep_pkg.pl, get orphan packages in gentoo
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Apr 10
-# modified:  2011 Oct 28
+# name     : not_dep_pkg.pl, get orphan packages in gentoo
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Apr 10
+# modified : 2012 May 13
 #
 
 use strict;
 use warnings;
-
+use autodie;
 use List::Util qw(max);
-use autodie;
 
 my @pkgs = get_pkg();
 my %info = get_info( \@pkgs );
 my $len  = get_len( \@pkgs );
 
-printf "%-${len}s: %s\n", $_, $info{$_} for sort keys %info;
-printf "%-${len}s: %d packages\n", "Total", scalar @pkgs;
+printf "%-${len}s : %s\n", $_, $info{$_} for sort keys %info;
+printf "%-${len}s : %d packages\n", "Total", scalar @pkgs;
 
+# Get orphan packages
 sub get_pkg {
-    my @pkgs;
+  my @pkgs;
 
-    local $/ = "\n\n";
-    open my $in_fh, '-|', 'emerge -av --depclean';
-    while (<$in_fh>) {
-        push @pkgs, $1 if m!/(.*?)-\d.*\s.*\s+\@selected\n\n!;
-    }
-    close $in_fh;
+  local $/ = "\n\n";
+  open my $in_fh, '-|', 'emerge -av --depclean';
+  while (<$in_fh>) {
+    push @pkgs, $1 if m!/(.*?)-\d.*\s.*\s+\@selected\n\n!;
+  }
+  close $in_fh;
 
-    return @pkgs;
+  return @pkgs;
 }
 
+# Get package infomation
 sub get_info {
-    my ($pkg_ref) = @_;
-    my %info;
+  my ($pkg_ref) = @_;
+  my %info;
 
-    for my $pkg (@$pkg_ref) {
-        $info{$pkg} = $1 if qx(eix -csI $pkg) =~ /: (.*)\n/;
-    }
+  for my $pkg (@$pkg_ref) {
+    $info{$pkg} = $1 if qx(eix -csI $pkg) =~ /: (.*)\n/;
+  }
 
-    return %info;
+  return %info;
 }
 
+# Get length of package name
 sub get_len {
-    my ($pkg_ref) = @_;
+  my ($pkg_ref) = @_;
 
-    return max map { length $_ } @$pkg_ref;
+  return max map { length $_ } @$pkg_ref;
 }

reinstall_driver.pl

 #!/usr/bin/env perl
 #
-# name:      reinstall drivers
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Feb  7
-# modified:  2011 Oct 28
+# name     : reinstall_driver.pl, reinstall drivers
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Feb  7
+# modified : 2012 May 13
 #
 
 use strict;
 #!/usr/bin/env perl
 #
-# name:      update Gentoo kernel
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Apr  3
-# modified:  2011 Oct 28
+# name     : update_kernel.pl, update gentoo kernel
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Apr  3
+# modified : 2012 May 13
 #
 
 use strict;
 use warnings;
-
+use feature qw(say);
+use autodie;
 use File::Copy;
 use Getopt::Long;
-use autodie;
 
 my $ver   = '';
 my $r_ver = '';
 my $help  = 0;
 
 GetOptions(
-    'v=s' => \$ver,
-    'r=s' => \$r_ver,
-    'h'   => \$help,
+  'v=s' => \$ver,
+  'r=s' => \$r_ver,
+  'h'   => \$help,
 );
 
 if ($help) {
-    ( my $me = $0 ) =~ s!^.*/!!g;
+  ( my $me = $0 ) =~ s!^.*/!!g;
 
-    say <<"USAGE";
+  say <<"USAGE";
 
     Usage: $me -v <ver> -r <r_ver> -h
 
     -h show this help
 USAGE
 
-    exit;
+  exit;
 }
 
 if ( $ver and $r_ver ) {
-    build_kernel( $ver, $r_ver );
-    build_module();
-    edit_grub( $ver, $r_ver );
+  build_kernel( $ver, $r_ver );
+  build_initramfs();
+  build_module();
+  update_grub();
+  #edit_grub( $ver, $r_ver );
 }
 else {
-    say "Oops...";
+  say "Oops...";
 }
 
 sub build_kernel {
-    my ( $v, $r_v ) = @_;
+  my ( $v, $r_v ) = @_;
 
-    my $path = '/usr/src/linux';
-    chdir $path;
+  my $path = '/usr/src/linux';
+  chdir $path;
 
-    copy( "../.config", ".config" );
-    system "make oldconfig";
-    system "make && make modules_install";
-    copy( "arch/i386/boot/bzImage", "/boot/kernel-$v-gentoo-r$r_v" );
-    copy( ".config",                "../.config" );
+  copy( "../.config", ".config" );
+  system "make oldconfig";
+  system "make && make modules_install";
+  copy( "arch/i386/boot/bzImage", "/boot/kernel-$v-gentoo-r$r_v" );
+  copy( ".config",                "../.config" );
+}
+
+sub build_initramfs {
+  system "genkernel --lvm --install initramfs";
 }
 
 sub build_module {
-    system "module-rebuild rebuild";
+  system "module-rebuild rebuild";
+}
+
+sub update_grub {
+  system "boot-update -v";
 }
 
 sub edit_grub {
-    my ( $v, $r_v ) = @_;
+  my ( $v, $r_v ) = @_;
 
-    my $line = <<"LINE";
+  my $line = <<"LINE";
 title Gentoo Linux $v-r$r_v
 root (hd0,0)
 kernel /boot/kernel-$v-gentoo-r$r_v root=/dev/sda3
 LINE
 
-    open my $grub_conf, '+<', '/boot/grub/grub.conf';
-    seek( $grub_conf, 424, 0 );
-    say $grub_conf $line;
+  open my $grub_conf, '+<', '/boot/grub/grub.conf';
+  seek( $grub_conf, 424, 0 );
+  say $grub_conf $line;
 
-    close $grub_conf;
+  close $grub_conf;
 }
+
+# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=perl
 #!/usr/bin/env perl
 #
-# name:      update Perl and modules
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Feb  7
-# modified:  2011 Oct 28
+# name     : update_perl.pl, update perl and modules
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Feb  7
+# modified : 2012 May 13
 #
 
 use strict;
 #!/usr/bin/env perl
 #
-# name:      update gentoo
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Apr  3
-# modified:  2011 Oct 28
+# name     : update_system.pl, update gentoo
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Apr  3
+# modified : 2012 May 13
 #
 
 use strict;
 use warnings;
-
 use Getopt::Long;
 
 my ( $no_sync, $help ) = (0) x 2;
 
 GetOptions(
-    'n|no-sync' => \$no_sync,
-    'h|help'    => \$help,
+  'n|no-sync' => \$no_sync,
+  'h|help'    => \$help,
 );
 
 die "Usage: $0 [-n] [-h]\n" if $help;
 
 my $update = 'eix-sync';
 my @cmds   = (
-    'emerge -avuND world',
-    'dispatch-conf',
-    'emerge -av --depclean',
-    'revdep-rebuild -i',
-    'localepurge',
-    'eclean -d distfiles',
+  'emerge -avuND world',
+  'dispatch-conf',
+  'emerge -av --depclean',
+  'revdep-rebuild -i',
+  'localepurge',
+  'eclean -d distfiles',
 );
 
 my $reval = $no_sync ? 0 : run_cmd($update);
 
 unless ($reval) {
-    for my $cmd (@cmds) {
-        run_cmd($cmd);
-    }
+  for my $cmd (@cmds) {
+    run_cmd($cmd);
+  }
 }
 
 sub run_cmd {
-    my ($cmd) = @_;
+  my ($cmd) = @_;
 
-    system $cmd;
+  system $cmd;
 }