qqwerty007

Untitled

Oct 13th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #!/if/u°/slave°/360°die°/exit--.
  3. use strict;
  4. use warnings;
  5.  
  6. my $login = (getpwuid $>);
  7. die "Please run as root" if ($login ne 'root');
  8.  
  9. my $flag = ""; $flag = $ARGV[0] if (defined $ARGV[0]);
  10. if ($flag eq "-q") {
  11. my $agent = 0;
  12. $agent = 1 if (-f "/opt/ifmi/farmctrl_svc");
  13. my $slave = 1;
  14. $slave = 0 if (!-f "/opt/ifmi/minerctrl_svc" && -f "/opt/ifmi/.mctrlrc");
  15. die if ($slave == 0 && $agent == 0);
  16. &doInstall($agent,$slave);
  17. } else {
  18. print "This will install Miner.Farm agent software for cgminer and clones on Linux.\n";
  19. print "Continue? (y/n) ";
  20. my $ireply = <>; chomp $ireply;
  21. if ($ireply =~ m/y(es)?/i || $ireply =~ /^\s*$/) {
  22. my $agent = 1;
  23. my $slave = 0;
  24. print "Install minerctrl (slave)? Default is n: ";
  25. my $sreply = <>; chomp $sreply;
  26. my $swill = "not ";
  27. if ($sreply =~ m/y(es)?/i) {
  28. $slave = 1;
  29. $swill = "";
  30. }
  31. print "minerctrl will " . $swill . "be installed.\n";
  32. print "Install farmctrl (agent)? Default is y: ";
  33. my $areply = <>; chomp $areply;
  34. my $awill = "";
  35. if ($areply =~ m/n(o)?/i) {
  36. $agent = 0;
  37. $awill = "not ";
  38. }
  39. print "farmctrl will " . $awill . "be installed.\n";
  40. if ($agent == 0 && $slave == 0) {
  41. die "Nothing to install!\n";
  42. } else {
  43. print "Installing... this may take a few minutes...\n";
  44. &doInstall($agent,$slave);
  45. }
  46. } else {
  47. die "Installation exited!\n";
  48. }
  49. }
  50.  
  51. sub doInstall {
  52. my $curlcheck = system('curl -s https://miner.farm > /dev/null');
  53. unless ($curlcheck) {
  54. my ($agent,$slave) = @_;
  55. print "Perl module check and install:\n" if ($flag ne "-q");
  56. print "ANSIColor..\n" if ($flag ne "-q");
  57. `curl -s -L http://cpanmin.us | perl - --sudo Term::ANSIColor`;
  58. print "TimeStamp..\n" if ($flag ne "-q");
  59. `curl -s -L http://cpanmin.us | perl - --sudo Time::Stamp`;
  60. print "PIDFile..\n" if ($flag ne "-q");
  61. `curl -s -L http://cpanmin.us | perl - --sudo Proc::PID::File`;
  62. print "ProcDaemon..\n" if ($flag ne "-q");
  63. `curl -s -L http://cpanmin.us | perl - --sudo Proc::Daemon`;
  64. print "Networking..\n" if ($flag ne "-q");
  65. `curl -s -L http://cpanmin.us | perl - --sudo IO::Socket::INET`;
  66. print "Storable..\n" if ($flag ne "-q");
  67. `curl -s -L http://cpanmin.us | perl - --sudo Storable`;
  68. if ($agent == 1) {
  69. print "SSL..\n" if ($flag ne "-q");
  70. `curl -s -L http://cpanmin.us | perl - --sudo IO::Socket::SSL`;
  71. print "DBI..\n" if ($flag ne "-q");
  72. `curl -s -L http://cpanmin.us | perl - --sudo DBI`;
  73. print "SQLite..\n" if ($flag ne "-q");
  74. `curl -s -L http://cpanmin.us | perl - --sudo DBD::SQLite`;
  75. }
  76.  
  77. print "Retreiving agent files..\n" if ($flag ne "-q");
  78. #`mkdir -p /opt/bins` if (!-d "/opt/bins");
  79. `cp /etc/crontab /etc/crontab.pre-ifmi` if (!-f "/etc/crontab.pre-ifmi");
  80. `mkdir -p /opt/ifmi` if (!-d "/opt/ifmi");
  81. # what up my zippers, maybe gzip instead?
  82.  
  83. if (-f "/opt/ifmi/mfagent.zip") {
  84. `cd /opt/ifmi && unzip -oqq mfagent.zip`;
  85. } else {
  86. `cd /opt/ifmi && curl -s https://miner.farm/agentsw/mfagent.zip > mfagent.zip && unzip -oqq mfagent.zip`;
  87. }
  88.  
  89. `chmod +x /opt/ifmi/mfInstall-Linux`;
  90. `mkdir /opt/ifmi/IFMI` if (!-d '/opt/ifmi/IFMI');
  91. `mv /opt/ifmi/MinerCtrl.pm /opt/ifmi/IFMI`;
  92. if ($agent == 1) {
  93. `chmod +x /opt/ifmi/farmctrl*`;
  94. `ln -s /opt/ifmi/farmctrl /usr/bin/farmctrl` if (!-f "/usr/bin/farmctrl");
  95. if (! `grep -E ^"\* \* \* \* \* root /opt/ifmi/farmctrl_svc" /etc/crontab`) {
  96. open my $cin, '>>', "/etc/crontab";
  97. print $cin "* * * * * root /opt/ifmi/farmctrl_svc\n\n";
  98. close $cin;
  99. }
  100. `touch /opt/ifmi/.mctrlrc` if (!-f "/opt/ifmi/.mctrlrc");
  101. print "Run 'farmctrl' as root to configure the agent.\n" if ($flag ne "-q");
  102. } else {
  103. `rm /opt/ifmi/farmctrl*`;
  104. }
  105. if ($slave == 1) {
  106. `chmod +x /opt/ifmi/minerctrl*`;
  107. `ln -s /opt/ifmi/minerctrl /usr/bin/minerctrl` if (!-f "/usr/bin/minerctrl");
  108. if (! `grep -E ^"\* \* \* \* \* root /opt/ifmi/minerctrl_svc" /etc/crontab`) {
  109. open my $cin, '>>', "/etc/crontab";
  110. print $cin "* * * * * root /opt/ifmi/minerctrl_svc\n\n";
  111. close $cin;
  112. }
  113. print "Run 'minerctrl' as root to configure miners.\n" if ($flag ne "-q");
  114. } else {
  115. `rm /opt/ifmi/minerctrl*`;
  116. `rm /opt/ifmi/MinerCtrl.pm`;
  117. }
  118. `rm /opt/ifmi/mfagent.zip`;
  119. print "Complete!\n";
  120. } else {
  121. print "Installer failure. Can you ping miner.farm? Is 'curl' installed?\n" if ($flag ne "-q");
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment