Created
September 29, 2019 17:06
-
-
Save bessarabov/c7e466d2506a224d7e01b03e4e29b317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature qw(say); | |
use Hash::Util qw(lock_keys); | |
my %DISTRIBUTION_ID2SITE = ( | |
Debian => 'https://www.debian.org', | |
Ubuntu => 'https://www.ubuntu.com', | |
Arch => 'https://www.archlinux.org', | |
Gentoo => 'https://www.gentoo.com', | |
Fedora => 'https://www.fedoraproject.org', | |
); | |
lock_keys(%DISTRIBUTION_ID2SITE); | |
sub read_file { | |
my ($file_name) = @_; | |
my $content = do { | |
open my $fh, '<', $file_name; | |
local $/; | |
<$fh>; | |
}; | |
return $content; | |
} | |
=head2 get_distribution_info | |
Return hashref: | |
{ | |
'description' => '"Ubuntu 14.04.5 LTS"', | |
'id' => 'Ubuntu', | |
'codename' => 'trusty', | |
'release' => '14.04' | |
}; | |
Or undef if can't find out distr info. | |
=cut | |
sub get_distribution_info { | |
my $file_name = '/etc/lsb-release'; | |
if (-e $file_name) { | |
my %info; | |
my $content = read_file('/etc/lsb-release'); | |
my @lines = split /\n/, $content; | |
foreach my $line (@lines) { | |
$line =~ /^DISTRIB_(.*)=(.*)\z/; | |
$info{lc($1)} = $2; | |
} | |
return \%info; | |
} else { | |
return undef; | |
} | |
} | |
sub get_user_input { | |
my ($message) = @_; | |
if ($message) { | |
print $message . ' '; | |
} | |
my $input = <>; | |
chomp $input; | |
return $input; | |
} | |
my $distr = get_distribution_info(); | |
if ($distr) { | |
say "Your Operation System is $distr->{id}"; | |
say "Official $distr->{id} site: $DISTRIBUTION_ID2SITE{$distr->{id}}"; | |
} else { | |
say 'Do you use another Operation System?'; | |
} | |
#Q&A for configuration and manage of obcperl in future. | |
if ( get_user_input('Part-I: 2 questions. Do you ready? [y/n]:') eq 'y' ) { | |
if (get_user_input('Q1: Do you want to use obcperl on one machine or more? [Use number]:') eq '1') { | |
# nothing | |
} else { | |
say "I'am pre-alfa. I can't do it right now"; | |
exit 1; | |
} | |
if (get_user_input('Q2: Do you want to use GUI for installation and settings? [y/n]:') eq 'y') { | |
say "Terrible sorry, but GUI not support. Please try again after update."; | |
} else { | |
say "Part-I has been completed"; | |
} | |
} else { | |
exit 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment