| Current Path : /home/hotlineuser/HotlineManagement/ |
| Current File : //home/hotlineuser/HotlineManagement/checkmobiusversion |
#!/usr/bin/perl
use warnings;
use strict;
my $VERSIONURL = "https://hotline.retro-os.live/mobiusversion.txt";
my $VERSION = "1.2.1";
my $GETCMD = "/usr/bin/wget --no-check-certificate";
my $LOCALMOBIUS = "/home/hotlineuser/mobius/mobius-hotline-server";
my $SOURCEVERSION = "";
my $LOCALVERSION = "";
my $SendNoticeAddr = "";
my $SendFromAddr = "";
my $Subject = "Update to mobius needed";
my $PrefsFile = "/home/hotlineuser/.chkmobprefs";
my $EDITCMD = "nano";
my $DEBUG = "";
sub debugprint
{
if ($DEBUG ne "")
{
print "$_[0]\n";
}
}
if (! -f $PrefsFile)
{
# Prefs file not found, create it
print "Prefs not found, creating it\n";
my $BlankPrefs = <<"END_PREFS";
# Recipient
someuser\@somehost.com
# Sender
somesender\@somehost.com
# Subject
Update to mobius needed
END_PREFS
open(FH, '>', $PrefsFile) or die $!;
print FH "$BlankPrefs\n";
close(FH);
system ("$EDITCMD $PrefsFile");
exit 0;
}
my ($arg1) = @ARGV;
if (defined($arg1))
{
if ($arg1 eq "prefs")
{
system ("$EDITCMD $PrefsFile");
exit 0;
}
}
my $SawLine = 0;
open(FH, '<', "$PrefsFile") or die $!;
while(<FH>){
chop;
if (substr($_, 0, 1) eq "#")
{
debugprint("Skipping comment");
next;
}
if ($SawLine == 0)
{
$SendNoticeAddr = $_;
}
elsif ($SawLine == 1)
{
$SendFromAddr = $_;
}
elsif ($SawLine == 2)
{
$Subject = $_;
}
$SawLine ++;
}
close(FH);
chdir ("/tmp");
system ("$GETCMD $VERSIONURL >/dev/null 2>&1");
system ("$LOCALMOBIUS --version > /tmp/localmobiusversion.txt");
open(FH, '<', "mobiusversion.txt") or die $!;
while(<FH>){
chop;
$SOURCEVERSION = $_;
}
close(FH);
open(FH, '<', "localmobiusversion.txt") or die $!;
while(<FH>){
chop;
$LOCALVERSION = $_;
}
close(FH);
debugprint("Source version = $SOURCEVERSION");
my @splitData = split(/ /, $LOCALVERSION);
my $tempver = $splitData[2];
chop ($tempver);
debugprint("Local version = $tempver");
# Remove temp files if they exist
if (-f "/tmp/mobiusversion.txt")
{
unlink("/tmp/mobiusversion.txt");
}
if (-f "/tmp/localmobiusversion.txt")
{
unlink("/tmp/localmobiusversion.txt");
}
if ($tempver eq $SOURCEVERSION)
{
# Already at the latest version
debugprint "Up to date";
exit 0;
}
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL "To: $SendNoticeAddr\n";
print MAIL "From: $SendFromAddr\n";
print MAIL "Subject: $Subject\n\n";
print MAIL "CheckMobiusVersion v$VERSION\n";
print MAIL "===========================\n";
print MAIL "Source version = $SOURCEVERSION\n";
print MAIL "Local version = $tempver\n";
my $result = close(MAIL);
if($result)
{
debugprint "Email Sent\n";
}
else
{
debugprint "Error sending email\n";
}
exit 0;