Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #!/if/u°/slave°/360°die°/exit--.
- use strict;
- use warnings;
- my $login = (getpwuid $>);
- die "Please run as root" if ($login ne 'root');
- my $flag = ""; $flag = $ARGV[0] if (defined $ARGV[0]);
- if ($flag eq "-q") {
- my $agent = 0;
- $agent = 1 if (-f "/opt/ifmi/farmctrl_svc");
- my $slave = 1;
- $slave = 0 if (!-f "/opt/ifmi/minerctrl_svc" && -f "/opt/ifmi/.mctrlrc");
- die if ($slave == 0 && $agent == 0);
- &doInstall($agent,$slave);
- } else {
- print "This will install Miner.Farm agent software for cgminer and clones on Linux.\n";
- print "Continue? (y/n) ";
- my $ireply = <>; chomp $ireply;
- if ($ireply =~ m/y(es)?/i || $ireply =~ /^\s*$/) {
- my $agent = 1;
- my $slave = 0;
- print "Install minerctrl (slave)? Default is n: ";
- my $sreply = <>; chomp $sreply;
- my $swill = "not ";
- if ($sreply =~ m/y(es)?/i) {
- $slave = 1;
- $swill = "";
- }
- print "minerctrl will " . $swill . "be installed.\n";
- print "Install farmctrl (agent)? Default is y: ";
- my $areply = <>; chomp $areply;
- my $awill = "";
- if ($areply =~ m/n(o)?/i) {
- $agent = 0;
- $awill = "not ";
- }
- print "farmctrl will " . $awill . "be installed.\n";
- if ($agent == 0 && $slave == 0) {
- die "Nothing to install!\n";
- } else {
- print "Installing... this may take a few minutes...\n";
- &doInstall($agent,$slave);
- }
- } else {
- die "Installation exited!\n";
- }
- }
- sub doInstall {
- my $curlcheck = system('curl -s https://miner.farm > /dev/null');
- unless ($curlcheck) {
- my ($agent,$slave) = @_;
- print "Perl module check and install:\n" if ($flag ne "-q");
- print "ANSIColor..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo Term::ANSIColor`;
- print "TimeStamp..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo Time::Stamp`;
- print "PIDFile..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo Proc::PID::File`;
- print "ProcDaemon..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo Proc::Daemon`;
- print "Networking..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo IO::Socket::INET`;
- print "Storable..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo Storable`;
- if ($agent == 1) {
- print "SSL..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo IO::Socket::SSL`;
- print "DBI..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo DBI`;
- print "SQLite..\n" if ($flag ne "-q");
- `curl -s -L http://cpanmin.us | perl - --sudo DBD::SQLite`;
- }
- print "Retreiving agent files..\n" if ($flag ne "-q");
- #`mkdir -p /opt/bins` if (!-d "/opt/bins");
- `cp /etc/crontab /etc/crontab.pre-ifmi` if (!-f "/etc/crontab.pre-ifmi");
- `mkdir -p /opt/ifmi` if (!-d "/opt/ifmi");
- # what up my zippers, maybe gzip instead?
- if (-f "/opt/ifmi/mfagent.zip") {
- `cd /opt/ifmi && unzip -oqq mfagent.zip`;
- } else {
- `cd /opt/ifmi && curl -s https://miner.farm/agentsw/mfagent.zip > mfagent.zip && unzip -oqq mfagent.zip`;
- }
- `chmod +x /opt/ifmi/mfInstall-Linux`;
- `mkdir /opt/ifmi/IFMI` if (!-d '/opt/ifmi/IFMI');
- `mv /opt/ifmi/MinerCtrl.pm /opt/ifmi/IFMI`;
- if ($agent == 1) {
- `chmod +x /opt/ifmi/farmctrl*`;
- `ln -s /opt/ifmi/farmctrl /usr/bin/farmctrl` if (!-f "/usr/bin/farmctrl");
- if (! `grep -E ^"\* \* \* \* \* root /opt/ifmi/farmctrl_svc" /etc/crontab`) {
- open my $cin, '>>', "/etc/crontab";
- print $cin "* * * * * root /opt/ifmi/farmctrl_svc\n\n";
- close $cin;
- }
- `touch /opt/ifmi/.mctrlrc` if (!-f "/opt/ifmi/.mctrlrc");
- print "Run 'farmctrl' as root to configure the agent.\n" if ($flag ne "-q");
- } else {
- `rm /opt/ifmi/farmctrl*`;
- }
- if ($slave == 1) {
- `chmod +x /opt/ifmi/minerctrl*`;
- `ln -s /opt/ifmi/minerctrl /usr/bin/minerctrl` if (!-f "/usr/bin/minerctrl");
- if (! `grep -E ^"\* \* \* \* \* root /opt/ifmi/minerctrl_svc" /etc/crontab`) {
- open my $cin, '>>', "/etc/crontab";
- print $cin "* * * * * root /opt/ifmi/minerctrl_svc\n\n";
- close $cin;
- }
- print "Run 'minerctrl' as root to configure miners.\n" if ($flag ne "-q");
- } else {
- `rm /opt/ifmi/minerctrl*`;
- `rm /opt/ifmi/MinerCtrl.pm`;
- }
- `rm /opt/ifmi/mfagent.zip`;
- print "Complete!\n";
- } else {
- print "Installer failure. Can you ping miner.farm? Is 'curl' installed?\n" if ($flag ne "-q");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment