#!/usr/bin/perl
#
# download and install midnight commander

#which version
        $ver="mc-4.8.19.zip";

# file
        $dl="openzfs.hfg-gmuend.de/midnight_commander/$ver";




#run from $HOME
###############
        `cd \$HOME`;
        $t=`pwd`;
        $ant=`echo \$HOME`;
        if ($t ne $ant)  {
                print "\n\n#####################\nYou must call wget from your HOME-directory.\n Please do a cd /\$HOME and try again.\n\n";
                exit;
        }


# opt delete unzipped files
        if (-d "./midnight_commander") {
                $t=`rm -r ./midnight_commander`;
        }


       $zip=$dl; $zip=~s/.*\///;

        if (-f "./$zip") {
                print "\ndeleting old zip-file\n";
                $t=`rm ./$zip`;                                                       # delete opt old version
        }


# download
        print "\nmidnight commander is $ver\nstart download now, please wait...\n";
        # $t=`wget $dl 2>&1`;

        $t=`wget -tries=3 https://www.napp-it.org/doc/downloads/mc-4.8.19.zip -O mc-4.8.19.zip 2>&1`;  #downloadopt1



# unzip
        print "\nunzip -a \$HOME/$zip\n";
        `mkdir ./midnight_commander; cd ./midnight_commander; unzip -a \$HOME/$zip`;

# install midnight commander
        `cp -R \$HOME/midnight_commander/. /`;
        `chmod 755 /usr/bin/mc`;

# check
        if (-f "/usr/bin/mc") {
          print "\nmc is installed, start from console with command mc\n\n";
        } else {
          print "\nmc was not installed!\n";
        }


# delete setup files
        if (-d "./midnight_commander") {
                $t=`rm -r ./midnight_commander`;
        }
        if (-f "./$zip") {
                $t=`rm ./$zip`;                                                       # delete
        }

exit;
