Advertisement
Guest User

Untitled

a guest
May 16th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #!/usr/local/bin/perl
  2. use HTTP::Tiny;
  3. use Term::ANSIColor;
  4.  
  5. our $delaytime = "1"; #delay time(minutes) between checking github for new version
  6. our $waittime = "3"; #wait time(minutes) after new version found
  7. our $projectName="Balanced-Annihilation"; #github
  8. our $branchName="master"; #github
  9. our $writepath="/home/msi/SPADS/resources/"; #pr-downloader
  10. our $downloadcode="ba:test"; #pr-downloader
  11. our $precmds="cpulimit -l 60";
  12. our $cmd=$precmds . " " . "pr-downloader --filesystem-writepath=" . $writepath . " " . $downloadcode;
  13. our $delaytimesec = ($delaytime*60);
  14. our $waittimesec = ($waittime*60);
  15.  
  16. getLatest($latest);getCurrent($current);updateFiles();
  17.  
  18. $|++;
  19. while (1) {
  20. getCurrent($latest,$current); #print("$timestamp current: $current\n");
  21. getLatest($latest); #print "$timestamp latest: $latest\n";
  22. if($current ne $latest){
  23. getTimestamp($timestamp); print "$timestamp detected $latest\n";
  24. getTimestamp($timestamp); print "$timestamp please wait..\n";
  25. sleep($waittimesec);
  26. updateFiles($projectName,$branchName,$latest);
  27. }
  28. sleep($delaytimesec);
  29. }
  30.  
  31. sub getLatest{
  32. my $httpTinyCanSsl=HTTP::Tiny->can_ssl();
  33. my $http = HTTP::Tiny->new;
  34. my $url1="https://github.com/" . $projectName . "/" . $projectName . "/commits/" . $branchName;
  35. $response = $http->get($url1);
  36. die "Failed!\n" unless $response->{success};
  37. my $content = $response->{content};
  38. my $url2 = "https:\/\/github.com\/" . $projectName . "\/" . $projectName . "\/commit\/";
  39. if ($content =~ /(.*)($url2)(.*)(.*" class)/) {$latest = $3;}else{$latest='Error!';}
  40. return($latest);
  41. }
  42.  
  43. sub getCurrent{
  44. our $current = $latest;
  45. return($current);
  46. }
  47.  
  48. sub updateFiles{
  49. getTimestamp($timestamp); print "$timestamp updating files..\n";
  50. print color('red');system ($cmd);print color('reset');
  51. getTimestamp($timestamp); print "$timestamp update complete\n";
  52. getTimestamp($timestamp); print("$timestamp waiting for new release\n");
  53. }
  54.  
  55. sub getTimestamp{
  56. our ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
  57. our $datestamp = sprintf ( "%04d-%02d-%02d",
  58. $year+1900,$mon+1,$mday);
  59. our $timestamp = sprintf ( "<%02d:%02d:%02d>",
  60. $hour,$min,$sec);
  61. return ($timestamp,$datestamp);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement