<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java in Mind</title>
	<atom:link href="http://www.javainmind.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javainmind.com</link>
	<description>talk about Java</description>
	<lastBuildDate>Mon, 04 Feb 2013 08:46:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>try JavaFX scene builder1.1</title>
		<link>http://www.javainmind.com/try-javafx-scene-builder1-1/</link>
		<comments>http://www.javainmind.com/try-javafx-scene-builder1-1/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 08:18:16 +0000</pubDate>
		<dc:creator>TaijiMark</dc:creator>
				<category><![CDATA[JavaFX]]></category>

		<guid isPermaLink="false">http://www.javainmind.com/?p=701</guid>
		<description><![CDATA[http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html]]></description>
				<content:encoded><![CDATA[<p>http://www.oracle.com/technetwork/java/javafx/downloads/devpreview-1429449.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javainmind.com/try-javafx-scene-builder1-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of 2012-08</title>
		<link>http://www.javainmind.com/review-of-2012-08/</link>
		<comments>http://www.javainmind.com/review-of-2012-08/#comments</comments>
		<pubDate>Sun, 30 Sep 2012 11:29:17 +0000</pubDate>
		<dc:creator>TaijiMark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.laobanit.com/?p=165</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://www.javainmind.com/review-of-2012-08/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review of 2012-07</title>
		<link>http://www.javainmind.com/review-of-2012-07/</link>
		<comments>http://www.javainmind.com/review-of-2012-07/#comments</comments>
		<pubDate>Thu, 30 Aug 2012 11:28:50 +0000</pubDate>
		<dc:creator>TaijiMark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.laobanit.com/?p=163</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://www.javainmind.com/review-of-2012-07/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash</title>
		<link>http://www.javainmind.com/bash/</link>
		<comments>http://www.javainmind.com/bash/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 12:05:43 +0000</pubDate>
		<dc:creator>TaijiMark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.laobanit.com/?p=446</guid>
		<description><![CDATA[u@nb:~/bash$ ls -l ??? 8 -rwxrwxr-x 1 u u 96 8? 2 20:04 b1 -rwxrwxr-x 1 u u 100 8? 2 20:02 b1~ u@nb:~/bash$ cat b1 #!/bin/bash echo a{p,c,d,b}e # ape ace ade abe echo {a,b,c}{d,e,f} # ad ae af bd be bf cd ce cf u@nb:~/bash$ which bash /bin/bash u@nb:~/bash$ ./b1 ape ace ade [...]]]></description>
				<content:encoded><![CDATA[<p>u@nb:~/bash$ ls -l<br />
??? 8<br />
-rwxrwxr-x 1 u u  96  8?  2 20:04 b1<br />
-rwxrwxr-x 1 u u 100  8?  2 20:02 b1~<br />
u@nb:~/bash$ cat b1<br />
#!/bin/bash<br />
echo a{p,c,d,b}e # ape ace ade abe<br />
echo {a,b,c}{d,e,f} # ad ae af bd be bf cd ce cf<br />
u@nb:~/bash$ which bash<br />
/bin/bash<br />
u@nb:~/bash$ ./b1<br />
ape ace ade abe<br />
ad ae af bd be bf cd ce cf<br />
u@nb:~/bash$ </p>
]]></content:encoded>
			<wfw:commentRss>http://www.javainmind.com/bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>apt-mirror</title>
		<link>http://www.javainmind.com/apt-mirror/</link>
		<comments>http://www.javainmind.com/apt-mirror/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 10:04:22 +0000</pubDate>
		<dc:creator>TaijiMark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.laobanit.com/?p=439</guid>
		<description><![CDATA[after sudo apt-get install apt-mirror we&#8217;ll find it, /usr/bin/apt-mirror source as follows ========================================= #!/usr/bin/perl -w =pod =head1 NAME apt-mirror &#8211; apt sources mirroring tool =head1 SYNOPSIS apt-mirror [configfile] =head1 DESCRIPTION A small and efficient tool that lets you mirror a part of or the whole Debian GNU/Linux distribution or any other apt sources. Main features: [...]]]></description>
				<content:encoded><![CDATA[<p>after<br />
sudo apt-get install apt-mirror<br />
we&#8217;ll find it, /usr/bin/apt-mirror<br />
source as follows<br />
=========================================<br />
#!/usr/bin/perl -w</p>
<p>=pod</p>
<p>=head1 NAME</p>
<p>apt-mirror &#8211; apt sources mirroring tool</p>
<p>=head1 SYNOPSIS</p>
<p>apt-mirror [configfile]</p>
<p>=head1 DESCRIPTION</p>
<p>A small and efficient tool that lets you mirror a part of or<br />
the whole Debian GNU/Linux distribution or any other apt sources.</p>
<p>Main features:<br />
 * It uses a config similar to apts F<sources.list><br />
 * It&#8217;s fully pool comply<br />
 * It supports multithreaded downloading<br />
 * It supports multiple architectures at the same time<br />
 * It can automatically remove unneeded files<br />
 * It works well on overloaded channel to internet<br />
 * It never produces an inconsistent mirror including while mirroring<br />
 * It works on all POSIX compliant systems with perl and wget</p>
<p>=head1 COMMENTS</p>
<p>apt-mirror uses F</etc/apt/mirror.list> as a configuration file.<br />
By default it is tuned to official Debian or Ubuntu mirrors. Change<br />
it for your needs.</p>
<p>After you setup the configuration file you may run as root:</p>
<p>    # su &#8211; apt-mirror -c apt-mirror</p>
<p>Or uncomment line in F</etc/cron.d/apt-mirror> to enable daily mirror updates.</p>
<p>=head1 FILES</p>
<p>F</etc/apt/mirror.list><br />
        Main configuration file</p>
<p>F</etc/cron.d/apt-mirror><br />
        Cron configuration template</p>
<p>F</var/spool/apt-mirror/mirror><br />
        Mirror places here</p>
<p>F</var/spool/apt-mirror/skel><br />
        Place for temporarily downloaded indexes</p>
<p>F</var/spool/apt-mirror/var><br />
        Log files placed here. URLs and MD5 summs also here.</p>
<p>=head1 CONFIGURATION EXAMPLES</p>
<p>The mirror.list configuration supports many options, the file is well commented explinging each option.<br />
here are some sample mirror configuration lines showing the various supported ways :</p>
<p>Normal:<br />
deb http://example.com/debian stable main contrib non-free</p>
<p>Arch Specific: ( many other arch&#8217;s are supported )<br />
deb-powerpc http://example.com/debian stable main contrib non-free</p>
<p>HTTP and FTP Auth or non-standard port:<br />
deb http://user:pass@example.com:8080/debian stable main contrib non-free</p>
<p>Source Mirroring:<br />
deb-src http://example.com/debian stable main contrib non-free</p>
<p>=head1 ORIGINAL AUTHOR</p>
<p>Dmitry N. Hramtsov E<lt>hdn@nsu.ruE<gt></p>
<p>=head1 CURRENT AUTHORS</p>
<p>Dmitry N. Hramtsov E<lt>hdn@nsu.ruE<gt><br />
Brandon Holtsclaw E<lt>me@brandonholtsclaw.comE<gt></p>
<p>=cut</p>
<p>use strict;<br />
use File::Copy;<br />
use File::Path;<br />
use File::Basename;<br />
use Fcntl qw(:flock);</p>
<p>my $config_file;</p>
<p>my %config_variables = (<br />
    &#8220;defaultarch&#8221; => `dpkg &#8211;print-installation-architecture 2>/dev/null` || &#8216;i386&#8242;,<br />
    &#8220;nthreads&#8221;    => 20,<br />
    &#8220;base_path&#8221;   => &#8216;/var/spool/apt-mirror&#8217;,<br />
    &#8220;mirror_path&#8221; => &#8216;$base_path/mirror&#8217;,<br />
    &#8220;skel_path&#8221;   => &#8216;$base_path/skel&#8217;,<br />
    &#8220;var_path&#8221;    => &#8216;$base_path/var&#8217;,<br />
    &#8220;cleanscript&#8221; => &#8216;$var_path/clean.sh&#8217;,<br />
    &#8220;_contents&#8221;   => 1,<br />
    &#8220;_autoclean&#8221;  => 0,<br />
    &#8220;_tilde&#8221;	  => 0,<br />
    &#8220;limit_rate&#8221;  => &#8217;100m&#8217;,<br />
    &#8220;run_postmirror&#8221; => 1,<br />
    &#8220;postmirror_script&#8221; => &#8216;$var_path/postmirror.sh&#8217;<br />
);</p>
<p>my @config_binaries = ();<br />
my @config_sources = ();</p>
<p>my @index_urls;<br />
my @childrens = ();<br />
my %skipclean = ();<br />
my %clean_directory = ();</p>
<p>######################################################################################<br />
## Setting up $config_file variable</p>
<p>$config_file = &#8220;/etc/apt/mirror.list&#8221;;	# Default value<br />
if($_ = shift) {<br />
    die(&#8220;apt-mirror: invalid config file specified&#8221;) unless -f $_;<br />
    $config_file = $_;<br />
}</p>
<p>chomp $config_variables{&#8220;defaultarch&#8221;};</p>
<p>######################################################################################<br />
## Common subroutines</p>
<p>sub round_number<br />
{<br />
	my $n = shift;<br />
	my $minus = $n < 0 ? '-' : '';<br />
	$n = abs($n);<br />
	$n = int(($n + .05) * 10) / 10;<br />
	$n .= '.0' unless $n =~ /\./;<br />
	$n .= '0' if substr($n,(length($n) - 1),1) eq '.';<br />
	chop $n if $n =~ /\.\d\d0$/;<br />
	return "$minus$n";<br />
}</p>
<p>sub format_bytes {<br />
	my $bytes = shift;<br />
	my $bytes_out = '0';<br />
	my $size_name = 'bytes';<br />
	my $KiB = 1024;<br />
	my $MiB = 1024 * 1024;<br />
	my $GiB = 1024 * 1024 * 1024;</p>
<p>	if ($bytes >= $KiB) {<br />
		$bytes_out = $bytes / $KiB;<br />
		$size_name = &#8216;KiB&#8217;;<br />
		if ($bytes >= $MiB) {<br />
			$bytes_out = $bytes / $MiB;<br />
			$size_name = &#8216;MiB&#8217;;<br />
			if ($bytes >= $GiB) {<br />
				$bytes_out = $bytes / $GiB;<br />
				$size_name = &#8216;GiB&#8217;;<br />
			}<br />
		}<br />
	} else {<br />
		$bytes_out = $bytes;<br />
		$size_name = &#8216;bytes&#8217;;<br />
	}</p>
<p>	$bytes_out = round_number($bytes_out);<br />
	return &#8220;$bytes_out $size_name&#8221;;<br />
}</p>
<p>sub get_variable {<br />
    my $value = $config_variables{shift @_};<br />
    my $count = 16;<br />
    while($value =~ s/\$(\w+)/$config_variables{$1}/xg) {<br />
	die(&#8220;apt-mirror: too many substitution while evaluating variable&#8221;) if ($count &#8211;) < 0;<br />
    }<br />
    return $value;<br />
}</p>
<p>sub lock_aptmirror {<br />
	open (LOCK_FILE, '>&#8216;, get_variable(&#8220;var_path&#8221;) . &#8220;/apt-mirror.lock&#8221;);<br />
	my $lock = flock(LOCK_FILE, LOCK_EX | LOCK_NB);<br />
	if (!$lock)<br />
	{<br />
		die(&#8220;apt-mirror is already running, exiting&#8221;);<br />
	}<br />
}</p>
<p>sub unlock_aptmirror {<br />
	close(LOCK_FILE);<br />
	unlink(get_variable(&#8220;var_path&#8221;) . &#8220;/apt-mirror.lock&#8221;);<br />
}</p>
<p>sub download_urls {<br />
    my $stage = shift;<br />
    my @urls;<br />
    my $i = 0;<br />
    my $pid;<br />
    my $nthreads = get_variable(&#8220;nthreads&#8221;);<br />
    local $| = 1;</p>
<p>    @urls = @_;<br />
    $nthreads = @urls if @urls < $nthreads;</p>
<p>    print "Downloading " . scalar(@urls) . " $stage files using $nthreads threads...\n";</p>
<p>    while(scalar @urls) {<br />
	my @part = splice(@urls, 0, int(@urls / $nthreads));<br />
	open URLS, ">&#8221; . get_variable(&#8220;var_path&#8221;) . &#8220;/$stage-urls.$i&#8221; or die(&#8220;apt-mirror: can&#8217;t write to intermediate file ($stage-urls.$i)&#8221;);<br />
	foreach (@part) { print URLS &#8220;$_\n&#8221;; }<br />
	close URLS or die(&#8220;apt-mirror: can&#8217;t close intermediate file ($stage-urls.$i)&#8221;);</p>
<p>	$pid = fork();</p>
<p>	die(&#8220;apt-mirror: can&#8217;t do fork in download_urls&#8221;) if $pid < 0;</p>
<p>	if($pid == 0) {<br />
	    exec 'wget', '--no-cache', '--limit-rate='.get_variable("limit_rate"), '-t', '5', '-r', '-N', '-l', 'inf', '-o', get_variable("var_path") . "/$stage-log.$i", '-i', get_variable("var_path") . "/$stage-urls.$i";<br />
	    # shouldn't reach this unless exec fails<br />
	    die("\n\nCould not run wget, please make sure its installed and in your path\n\n");<br />
	}</p>
<p>	push @childrens, $pid;<br />
	$i++; $nthreads--;<br />
    }</p>
<p>    print "Begin time: " . localtime() . "\n[" . scalar(@childrens) . "]... ";<br />
    while(scalar @childrens) {<br />
	my $dead = wait();<br />
	@childrens = grep { $_ != $dead } @childrens;<br />
	print "[" . scalar(@childrens) . "]... ";<br />
    }<br />
    print "\nEnd time: " . localtime() . "\n\n";<br />
}</p>
<p>## Parse config</p>
<p>open CONFIG, "<$config_file" or die("apt-mirror: can't open config file ($config_file)");<br />
while(<CONFIG>) {<br />
    next if /^\s*#/;<br />
    next unless /\S/;<br />
    my @config_line = split;<br />
    my $config_line = shift @config_line;</p>
<p>    if($config_line eq &#8220;set&#8221;) {<br />
	$config_variables{$config_line[0]} = $config_line[1];<br />
	next;<br />
    }</p>
<p>    if($config_line eq &#8220;deb&#8221;) {<br />
	push @config_binaries, [get_variable("defaultarch"), @config_line];<br />
	next;<br />
    }</p>
<p>    if($config_line =~ /deb-(alpha|amd64|armel|arm|armhf|hppa|hurd-i386|i386|ia64|kfreebsd-i386|kfreebsd-amd64|lpia|m68k|mipsel|mips|powerpc|s390|s390x|sh|sparc)/) {<br />
	push @config_binaries, [$1, @config_line];<br />
	next;<br />
    }</p>
<p>    if($config_line eq &#8220;deb-src&#8221;) {<br />
	push @config_sources, [@config_line];<br />
	next;<br />
    }</p>
<p>    if($config_line eq &#8220;skip-clean&#8221;) {<br />
	$config_line[0] =~ s[^(\w+)://][];<br />
	$config_line[0] =~ s[/$][];<br />
	$config_line[0] =~ s[~][%7E]g if get_variable(&#8220;_tilde&#8221;);<br />
	$skipclean{$config_line[0]} = 1;<br />
	next;<br />
    }</p>
<p>    if($config_line eq &#8220;clean&#8221;) {<br />
	$config_line[0] =~ s[^(\w+)://][];<br />
	$config_line[0] =~ s[/$][];<br />
	$config_line[0] =~ s[~][%7E]g if get_variable(&#8220;_tilde&#8221;);<br />
	$clean_directory{$config_line[0]} = 1;<br />
	next;<br />
    }</p>
<p>    die(&#8220;apt-mirror: invalid line in config file ($.: $config_line &#8230;)&#8221;);<br />
}<br />
close CONFIG;</p>
<p>die(&#8220;Please explicitly specify &#8216;defaultarch&#8217; in mirror.list&#8221;) unless get_variable(&#8220;defaultarch&#8221;);</p>
<p>######################################################################################<br />
## Create the 3 needed directories if they don&#8217;t exist yet<br />
my @needed_directories = (get_variable(&#8220;mirror_path&#8221;), get_variable(&#8220;skel_path&#8221;), get_variable(&#8220;var_path&#8221;));<br />
foreach my $needed_directory (@needed_directories) {<br />
    unless (-d $needed_directory) {<br />
        mkdir($needed_directory) or die(&#8220;apt-mirror: can&#8217;t create $needed_directory directory&#8221;);<br />
    }<br />
}<br />
#<br />
#######################################################################################</p>
<p>lock_aptmirror();</p>
<p>######################################################################################<br />
## Skel download</p>
<p>my %urls_to_download = ();<br />
my ($url, $arch);</p>
<p>sub remove_double_slashes {<br />
    local $_ = shift;<br />
    while(s[/\./][/]g) {}<br />
    while(s[(?<!:)//][/]g) {}<br />
    while(s[(?<!:/)/[^/]+/\.\./][/]g) {}<br />
    s/~/\%7E/g if get_variable(&#8220;_tilde&#8221;);<br />
    return $_;<br />
}</p>
<p>sub add_url_to_download {<br />
    my $url = remove_double_slashes(shift);<br />
    $urls_to_download{$url} = shift;<br />
}</p>
<p>foreach (@config_sources) {<br />
    my ($uri, $distribution, @components) = @{$_};</p>
<p>    if(@components) {<br />
	$url = $uri . &#8220;/dists/&#8221; . $distribution . &#8220;/&#8221;;</p>
<p>	add_url_to_download($url . &#8220;Release&#8221;);<br />
	add_url_to_download($url . &#8220;Release.gpg&#8221;);<br />
	foreach (@components) {<br />
	    add_url_to_download($url . $_ . &#8220;/source/Release&#8221;);<br />
	    add_url_to_download($url . $_ . &#8220;/source/Sources.gz&#8221;);<br />
	    add_url_to_download($url . $_ . &#8220;/source/Sources.bz2&#8243;);<br />
	}<br />
    } else {<br />
    add_url_to_download($uri . &#8220;/$distribution/Release&#8221;);<br />
	add_url_to_download($uri . &#8220;/$distribution/Release.gpg&#8221;);<br />
	add_url_to_download($uri . &#8220;/$distribution/Sources.gz&#8221;);<br />
	add_url_to_download($uri . &#8220;/$distribution/Sources.bz2&#8243;);<br />
    }<br />
}</p>
<p>foreach (@config_binaries) {<br />
    my ($arch, $uri, $distribution, @components) = @{$_};</p>
<p>    if(@components) {<br />
	$url = $uri . &#8220;/dists/&#8221; . $distribution . &#8220;/&#8221;;</p>
<p>	add_url_to_download($url . &#8220;Release&#8221;);<br />
	add_url_to_download($url . &#8220;Release.gpg&#8221;);<br />
        if (get_variable(&#8220;_contents&#8221;)) {<br />
            add_url_to_download($url . &#8220;Contents-&#8221; . $arch . &#8220;.gz&#8221;);<br />
            add_url_to_download($url . &#8220;Contents-&#8221; . $arch . &#8220;.bz2&#8243;);<br />
        }<br />
	foreach (@components) {<br />
	    add_url_to_download($url . $_ . &#8220;/binary-&#8221; . $arch . &#8220;/Release&#8221;);<br />
	    add_url_to_download($url . $_ . &#8220;/binary-&#8221; . $arch . &#8220;/Packages.gz&#8221;);<br />
	    add_url_to_download($url . $_ . &#8220;/binary-&#8221; . $arch . &#8220;/Packages.bz2&#8243;);<br />
	}<br />
    } else {<br />
	add_url_to_download($uri . &#8220;/$distribution/Release&#8221;);<br />
	add_url_to_download($uri . &#8220;/$distribution/Release.gpg&#8221;);<br />
	add_url_to_download($uri . &#8220;/$distribution/Packages.gz&#8221;);<br />
	add_url_to_download($uri . &#8220;/$distribution/Packages.bz2&#8243;);<br />
    }<br />
}</p>
<p>chdir get_variable(&#8220;skel_path&#8221;) or die(&#8220;apt-mirror: can&#8217;t chdir to skel&#8221;);<br />
@index_urls = sort keys %urls_to_download;<br />
download_urls(&#8220;index&#8221;, @index_urls);</p>
<p>foreach (keys %urls_to_download) {<br />
    s[^(\w+)://][];<br />
    s[~][%7E]g if get_variable(&#8220;_tilde&#8221;);<br />
    $skipclean{$_} = 1;<br />
    $skipclean{$_} = 1 if s[\.gz$][];<br />
    $skipclean{$_} = 1 if s[\.bz2$][];<br />
}</p>
<p>######################################################################################<br />
## Main download prepair</p>
<p>%urls_to_download = ();</p>
<p>open FILES_ALL, &#8220;>&#8221; . get_variable(&#8220;var_path&#8221;) . &#8220;/ALL&#8221; or die(&#8220;apt-mirror: can&#8217;t write to intermediate file (ALL)&#8221;);<br />
open FILES_NEW, &#8220;>&#8221; . get_variable(&#8220;var_path&#8221;) . &#8220;/NEW&#8221; or die(&#8220;apt-mirror: can&#8217;t write to intermediate file (NEW)&#8221;);<br />
open FILES_MD5, &#8220;>&#8221; . get_variable(&#8220;var_path&#8221;) . &#8220;/MD5&#8243; or die(&#8220;apt-mirror: can&#8217;t write to intermediate file (MD5)&#8221;);</p>
<p>my %stat_cache = ();</p>
<p>sub _stat {<br />
  my ($filename) = shift;<br />
  return @{$stat_cache{$filename}} if exists $stat_cache{$filename};<br />
  my @res = stat($filename);<br />
  $stat_cache{$filename} = \@res;<br />
  return @res;<br />
}</p>
<p>sub clear_stat_cache {<br />
  %stat_cache = ();<br />
}</p>
<p>sub need_update {<br />
    my $filename = shift;<br />
    my $size_on_server = shift;</p>
<p>    my (undef, undef, undef, undef, undef, undef, undef, $size) = _stat($filename);</p>
<p>    return 1 unless($size);<br />
    return 0 if $size_on_server == $size;<br />
    return 1;<br />
}</p>
<p>sub remove_spaces($) {<br />
    my $hashref = shift;<br />
    foreach (keys %{$hashref}) {<br />
	while(substr($hashref->{$_}, 0, 1) eq &#8216; &#8216;) {<br />
	    substr($hashref->{$_}, 0, 1) = &#8221;;<br />
	}<br />
    }<br />
}</p>
<p>sub sanitise_uri {<br />
    my $uri = shift;<br />
    $uri =~ s[^(\w+)://][];<br />
    $uri =~ s/^([^@]+)?@?// if $uri =~ /@/;<br />
    $uri =~ s&#038;:\d+/&#038;/&#038;; # and port information<br />
    $uri =~ s/~/\%7E/g if get_variable(&#8220;_tilde&#8221;);<br />
    return $uri;<br />
}</p>
<p>sub proceed_index_gz {<br />
    my $uri = shift;<br />
    my $index = shift;<br />
    my ($path, $package, $mirror, $files) = &#8221;;</p>
<p>    $path = sanitise_uri($uri);<br />
    local $/ = &#8220;\n\n&#8221;;<br />
    $mirror = get_variable(&#8220;mirror_path&#8221;) . &#8220;/&#8221; . $path;</p>
<p>    if($index =~ s/\.gz$//) {<br />
	system(&#8220;gunzip < $path/$index.gz > $path/$index&#8221;);<br />
    }</p>
<p>    open STREAM, &#8220;<$path/$index" or die("apt-mirror: can't open index in proceed_index_gz");</p>
<p>    while($package = <STREAM>) {<br />
	local $/ = &#8220;\n&#8221;;<br />
	chomp $package;<br />
	my (undef, %lines) = split(/^([\w\-]+:)/m, $package);</p>
<p>	$lines{&#8220;Directory:&#8221;} = &#8220;&#8221; unless defined $lines{&#8220;Directory:&#8221;};<br />
	chomp(%lines);<br />
	remove_spaces(\%lines);</p>
<p>	if(exists $lines{&#8220;Filename:&#8221;}) {	# Packages index<br />
	    $skipclean{remove_double_slashes($path . &#8220;/&#8221; . $lines{&#8220;Filename:&#8221;})} = 1;<br />
	    print FILES_ALL remove_double_slashes($path . &#8220;/&#8221; . $lines{&#8220;Filename:&#8221;}) . &#8220;\n&#8221;;<br />
	    print FILES_MD5 $lines{&#8220;MD5sum:&#8221;} . &#8221;  &#8221; . remove_double_slashes($path . &#8220;/&#8221; . $lines{&#8220;Filename:&#8221;}) . &#8220;\n&#8221;;<br />
	    if(need_update($mirror . &#8220;/&#8221; . $lines{&#8220;Filename:&#8221;}, $lines{&#8220;Size:&#8221;})) {<br />
		print FILES_NEW remove_double_slashes($uri . &#8220;/&#8221; . $lines{&#8220;Filename:&#8221;}) . &#8220;\n&#8221;;<br />
		add_url_to_download($uri . &#8220;/&#8221; . $lines{&#8220;Filename:&#8221;}, $lines{&#8220;Size:&#8221;});<br />
	    }<br />
	} else {				# Sources index<br />
	    foreach (split(/\n/, $lines{&#8220;Files:&#8221;})) {<br />
		next if $_ eq &#8221;;<br />
		my @file = split;<br />
		die(&#8220;apt-mirror: invalid Sources format&#8221;) if @file != 3;<br />
		$skipclean{remove_double_slashes($path . &#8220;/&#8221; . $lines{&#8220;Directory:&#8221;} . &#8220;/&#8221; . $file[2])} = 1;<br />
		print FILES_ALL remove_double_slashes($path . &#8220;/&#8221; . $lines{&#8220;Directory:&#8221;} . &#8220;/&#8221; . $file[2]) . &#8220;\n&#8221;;<br />
		print FILES_MD5 $file[0] . &#8221;  &#8221; . remove_double_slashes($path . &#8220;/&#8221; . $lines{&#8220;Directory:&#8221;} . &#8220;/&#8221; . $file[2]) . &#8220;\n&#8221;;<br />
		if(need_update($mirror . &#8220;/&#8221; . $lines{&#8220;Directory:&#8221;} . &#8220;/&#8221; . $file[2], $file[1])) {<br />
		    print FILES_NEW remove_double_slashes($uri . &#8220;/&#8221; . $lines{&#8220;Directory:&#8221;} . &#8220;/&#8221; . $file[2]) . &#8220;\n&#8221;;<br />
		    add_url_to_download($uri . &#8220;/&#8221; . $lines{&#8220;Directory:&#8221;} . &#8220;/&#8221; . $file[2], $file[1]);<br />
		}<br />
	    }<br />
	}<br />
    }</p>
<p>    close STREAM;<br />
}</p>
<p>print &#8220;Proceed indexes: [";</p>
<p>foreach (@config_sources) {<br />
    my ($uri, $distribution, @components) = @{$_};<br />
    print "S";<br />
    if(@components) {<br />
	my $component;<br />
	foreach $component (@components) {<br />
	    proceed_index_gz($uri, "/dists/$distribution/$component/source/Sources.gz");<br />
	}<br />
    } else {<br />
	proceed_index_gz($uri, "/$distribution/Sources.gz");<br />
    }<br />
}</p>
<p>foreach (@config_binaries) {<br />
    my ($arch, $uri, $distribution, @components) = @{$_};<br />
    print "P";<br />
    if(@components) {<br />
	my $component;<br />
	foreach $component (@components) {<br />
	    proceed_index_gz($uri, "/dists/$distribution/$component/binary-$arch/Packages.gz");<br />
	}<br />
    } else {<br />
	proceed_index_gz($uri, "/$distribution/Packages.gz");<br />
    }<br />
}</p>
<p>clear_stat_cache();</p>
<p>print "]\n\n&#8221;;</p>
<p>close FILES_ALL;<br />
close FILES_NEW;<br />
close FILES_MD5;</p>
<p>######################################################################################<br />
## Main download</p>
<p>chdir get_variable(&#8220;mirror_path&#8221;) or die(&#8220;apt-mirror: can&#8217;t chdir to mirror&#8221;);</p>
<p>my $need_bytes = 0;<br />
foreach (values %urls_to_download) {<br />
    $need_bytes += $_;<br />
}</p>
<p>my $size_output = format_bytes($need_bytes);</p>
<p>print &#8220;$size_output will be downloaded into archive.\n&#8221;;</p>
<p>download_urls(&#8220;archive&#8221;, sort keys %urls_to_download);</p>
<p>######################################################################################<br />
## Copy skel to main archive</p>
<p>sub copy_file {<br />
    my ($from, $to) = @_;<br />
    my $dir = dirname($to);<br />
    return unless -f $from;<br />
    mkpath($dir) unless -d $dir;<br />
    unless(copy($from, $to)) {<br />
	warn(&#8220;apt-mirror: can&#8217;t copy $from to $to&#8221;);<br />
	return;<br />
    }<br />
    my ($atime,$mtime) = ( stat($from) ) [8, 9];<br />
    utime($atime, $mtime, $to) or die(&#8220;apt-mirror: can&#8217;t utime $to&#8221;);<br />
}</p>
<p>foreach (@index_urls) {<br />
    die(&#8220;apt-mirror: invalid url in index_urls&#8221;) unless s[^(\w+)://][];<br />
    copy_file(get_variable(&#8220;skel_path&#8221;) . &#8220;/&#8221; . sanitise_uri(&#8220;$_&#8221;), get_variable(&#8220;mirror_path&#8221;) . &#8220;/&#8221; . sanitise_uri(&#8220;$_&#8221;));<br />
    copy_file(get_variable(&#8220;skel_path&#8221;) . &#8220;/&#8221; . sanitise_uri(&#8220;$_&#8221;), get_variable(&#8220;mirror_path&#8221;) . &#8220;/&#8221; . sanitise_uri(&#8220;$_&#8221;)) if(s/\.gz$//);<br />
    copy_file(get_variable(&#8220;skel_path&#8221;) . &#8220;/&#8221; . sanitise_uri(&#8220;$_&#8221;), get_variable(&#8220;mirror_path&#8221;) . &#8220;/&#8221; . sanitise_uri(&#8220;$_&#8221;)) if(s/\.bz2$//);<br />
}</p>
<p>######################################################################################<br />
## Make cleaning script</p>
<p>my (@rm_dirs, @rm_files) = ();<br />
my $unnecessary_bytes = 0;</p>
<p>sub process_symlink {<br />
    return 1;		# symlinks are always needed<br />
}</p>
<p>sub process_file {<br />
    my $file = shift;<br />
    $file =~ s[~][%7E]g if get_variable(&#8220;_tilde&#8221;);<br />
    return 1 if $skipclean{$file};<br />
    push @rm_files, sanitise_uri($file);<br />
    my (undef, undef, undef, undef, undef, undef, undef, $size, undef, undef, undef, undef, $blocks) = stat($file);<br />
    $unnecessary_bytes += $blocks * 512;<br />
    return 0;<br />
}</p>
<p>sub process_directory {<br />
    my $dir = shift;<br />
    my $is_needed = 0;<br />
    return 1 if $skipclean{$dir};<br />
    opendir(my $dir_h, $dir) or die &#8220;apt-mirror: can&#8217;t opendir $dir: $!&#8221;;<br />
    foreach (grep { !/^\.$/ &#038;&#038; !/^\.\.$/ } readdir($dir_h)) {<br />
	my $item = $dir . &#8220;/&#8221;. $_;<br />
	$is_needed |= process_directory($item)	if -d $item &#038;&#038; ! -l $item;<br />
	$is_needed |= process_file($item)	if -f $item;<br />
	$is_needed |= process_symlink($item)	if -l $item;<br />
    }<br />
    closedir $dir_h;<br />
    push @rm_dirs, $dir unless $is_needed;<br />
    return $is_needed;<br />
}</p>
<p>chdir get_variable(&#8220;mirror_path&#8221;) or die(&#8220;apt-mirror: can&#8217;t chdir to mirror&#8221;);</p>
<p>foreach (keys %clean_directory) {<br />
    process_directory($_) if -d $_ &#038;&#038; ! -l $_;<br />
}</p>
<p>open CLEAN, &#8220;>&#8221; . get_variable(&#8220;cleanscript&#8221;) or die(&#8220;apt-mirror: can&#8217;t open clean script file&#8221;);</p>
<p>my ($i, $total) = (0, scalar @rm_files);</p>
<p>if(get_variable(&#8220;_autoclean&#8221;)) {</p>
<p>    my $size_output = format_bytes($unnecessary_bytes);<br />
    print &#8220;$size_output in $total files and &#8221; . scalar(@rm_dirs) . &#8221; directories will be freed&#8230;&#8221;;</p>
<p>    chdir get_variable(&#8220;mirror_path&#8221;) or die(&#8220;apt-mirror: can&#8217;t chdir to mirror&#8221;);</p>
<p>    foreach (@rm_files) { unlink $_; }<br />
    foreach (@rm_dirs) { rmdir $_; }</p>
<p>} else {</p>
<p>    my $size_output = format_bytes($unnecessary_bytes);<br />
    print &#8220;$size_output in $total files and &#8221; . scalar(@rm_dirs) . &#8221; directories can be freed.\n&#8221;;<br />
    print &#8220;Run &#8221; . get_variable(&#8220;cleanscript&#8221;) . &#8221; for this purpose.\n\n&#8221;;</p>
<p>    print CLEAN &#8220;#!/bin/sh\n\n&#8221;;<br />
    print CLEAN &#8220;cd &#8221; . get_variable(&#8220;mirror_path&#8221;) . &#8221; || exit 1\n\n&#8221;;<br />
    print CLEAN &#8220;echo &#8216;Removing $total unnecessary files [$unnecessary_bytes bytes]&#8230;&#8217;\n&#8221;;<br />
    foreach (@rm_files) {<br />
	print CLEAN &#8220;rm -f &#8216;$_&#8217;\n&#8221;;<br />
	print CLEAN &#8220;echo -n &#8216;[" . int(100 * $i/$total) . "\%]&#8216;\n&#8221; unless $i % 500;<br />
	print CLEAN &#8220;echo -n .\n&#8221; unless $i % 10;<br />
        $i ++;<br />
    }<br />
    print CLEAN &#8220;echo &#8216;done.&#8217;\n&#8221;;<br />
    print CLEAN &#8220;echo\n\n&#8221;;</p>
<p>    $i = 0; $total = scalar @rm_dirs;<br />
    print CLEAN &#8220;echo &#8216;Removing $total unnecessary directories&#8230;&#8217;\n&#8221;;<br />
    foreach (@rm_dirs) {<br />
	print CLEAN &#8220;rmdir &#8216;$_&#8217;\n&#8221;;<br />
        print CLEAN &#8220;echo -n &#8216;[" . int(100 * $i/$total) . "\%]&#8216;\n&#8221; unless $i % 50;<br />
        print CLEAN &#8220;echo -n .\n&#8221;;<br />
        $i ++;<br />
    }<br />
    print CLEAN &#8220;echo &#8216;done.&#8217;\n&#8221;;<br />
    print CLEAN &#8220;echo\n&#8221;;</p>
<p>    close CLEAN;</p>
<p>}</p>
<p>if(get_variable(&#8220;run_postmirror&#8221;)) {<br />
    print &#8220;Running the Post Mirror script &#8230;\n&#8221;;<br />
    print &#8220;(&#8221; . get_variable(&#8220;postmirror_script&#8221;) . &#8220;)\n\n&#8221;;<br />
    if(-x get_variable(&#8220;postmirror_script&#8221;)){<br />
        system (get_variable(&#8220;postmirror_script&#8221;));<br />
    } else {<br />
        system (&#8216;/bin/sh &#8216; . get_variable(&#8220;postmirror_script&#8221;));<br />
    }<br />
    print &#8220;\nPost Mirror script has completed. See above output for any possible errors.\n\n&#8221;;<br />
}</p>
<p>unlock_aptmirror();</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javainmind.com/apt-mirror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
