Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl
- use HTTP::Tiny;
- use Term::ANSIColor;
- our $delaytime = "1"; #delay time(minutes) between checking github for new version
- our $waittime = "3"; #wait time(minutes) after new version found
- our $projectName="Balanced-Annihilation"; #github
- our $branchName="master"; #github
- our $writepath="/home/msi/SPADS/resources/"; #pr-downloader
- our $downloadcode="ba:test"; #pr-downloader
- our $precmds="cpulimit -l 60";
- our $cmd=$precmds . " " . "pr-downloader --filesystem-writepath=" . $writepath . " " . $downloadcode;
- our $delaytimesec = ($delaytime*60);
- our $waittimesec = ($waittime*60);
- getLatest($latest);getCurrent($current);updateFiles();
- $|++;
- while (1) {
- getCurrent($latest,$current); #print("$timestamp current: $current\n");
- getLatest($latest); #print "$timestamp latest: $latest\n";
- if($current ne $latest){
- getTimestamp($timestamp); print "$timestamp detected $latest\n";
- getTimestamp($timestamp); print "$timestamp please wait..\n";
- sleep($waittimesec);
- updateFiles($projectName,$branchName,$latest);
- }
- sleep($delaytimesec);
- }
- sub getLatest{
- my $httpTinyCanSsl=HTTP::Tiny->can_ssl();
- my $http = HTTP::Tiny->new;
- my $url1="https://github.com/" . $projectName . "/" . $projectName . "/commits/" . $branchName;
- $response = $http->get($url1);
- die "Failed!\n" unless $response->{success};
- my $content = $response->{content};
- my $url2 = "https:\/\/github.com\/" . $projectName . "\/" . $projectName . "\/commit\/";
- if ($content =~ /(.*)($url2)(.*)(.*" class)/) {$latest = $3;}else{$latest='Error!';}
- return($latest);
- }
- sub getCurrent{
- our $current = $latest;
- return($current);
- }
- sub updateFiles{
- getTimestamp($timestamp); print "$timestamp updating files..\n";
- print color('red');system ($cmd);print color('reset');
- getTimestamp($timestamp); print "$timestamp update complete\n";
- getTimestamp($timestamp); print("$timestamp waiting for new release\n");
- }
- sub getTimestamp{
- our ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
- our $datestamp = sprintf ( "%04d-%02d-%02d",
- $year+1900,$mon+1,$mday);
- our $timestamp = sprintf ( "<%02d:%02d:%02d>",
- $hour,$min,$sec);
- return ($timestamp,$datestamp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement