#!/usr/bin/perl -w
use strict;

use WRT54G;
use Util;

$|++;

my %config = Util::parse_config('wrt54g.cfg');

my $router = WRT54G->new(%config);

print("Pushing busybox .");
my $remote_busybox = $router->send_file(filename => $config{mips_busybox_binary},
					subdir   => "bin"
				       );
print(".");

$router->exec_command("chmod a+x $remote_busybox");

print(" done\n");

print "Configuring busybox ";

foreach my $busybox_bin (qw(
			     tar test
			    )
			 ){
  print(".");
  $router->exec_command("ln $remote_busybox /tmp/dist/bin/$busybox_bin")
}

print(" done\n");

print "Configuring NoCatSplash .";

my $remote_archive = $router->send_file(filename => "nocatsplash/splash54g");

print ".";
$router->send_file( filename => "nocatsplash/nocat.conf",
		    subdir => "splash/etc/"
		  );

print ".";
$router->send_file( filename => "nocatsplash/splash.html",
		    subdir => "splash/htdocs/"
		  );

foreach my $command ("/tmp/dist/bin/tar zxC /tmp -f $remote_archive",
		     "/tmp/splash/sbin/splashd &",
		     "rm -f $remote_archive",
		    ){
  print ".";
  $router->exec_command($command);
}

print " done\n";
