#!/usr/bin/perl -w
# update_boot
# written thogard@abnormal.com
# Copyright 2003. This can be copied under the terms of Perl's
# Artistic License or GNU GPL.
# Sun May  4 00:36:14 EST 2003
# version 1.0
# this will upgrade SM from 3.1.5/09110217 to 3.2.5/09110217

#1st argument is the ip address (or name) of an SU
$host=shift;
$host='169.254.1.5' unless $host;

#which file to transfer
$file="../upgrade-files/Application\ Software\ files/SMboot.bin";

#user name 
$username="root";
#password (Needs to be the Full Access password)
$passwd="PASSWORD";

#$debug=1;	# debug gets set to 1 if you want to see whats going on
use Net::Telnet ();
use Net::FTP ();

#set up telnet object and attempt to login
$t = new Net::Telnet (Timeout => 10, Prompt => '/Telnet\+> $/');
$t->input_log("/dev/tty") if($debug);
$t->open($host);
$t->login(Name => $username, Password => $passwd, Timeout => 2, Errmode => "return");

#this is mostly for logging
@lines = $t->cmd("mac");
print @lines;
@lines = $t->cmd("version");
print @lines;
#The lst 2 char of the $lines[0] should be SM for Subscriber modules

#set up ftp object, login and set to binary mode
$f = Net::FTP->new($host, Debug => $debug);
$f->login($username,$passwd);
$f->binary();

#put the file
$f->put($file);
$f->quit;

@lines = $t->cmd("ls");
print @lines;
print scalar localtime(time());
@lines = $t->cmd(String => "burnfile", Timeout => 600);
print @lines;
print scalar localtime(time());
@lines = $t->cmd(String => "reset", Timeout => 20);
print @lines;


