Skip to content

Instantly share code, notes, and snippets.

@sunnypp
Last active December 18, 2017 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnypp/3f96ffc9b24707f221dcc2c43060f6cd to your computer and use it in GitHub Desktop.
Save sunnypp/3f96ffc9b24707f221dcc2c43060f6cd to your computer and use it in GitHub Desktop.
Boilerplate for macOS Development Environment Installation in Perl
use strict;
use warnings;
sub _print_num {
my $color_num = shift;
print `tput setaf $color_num`;
print shift;
print `tput sgr0`;
print "\n";
}
sub print_grey { _print_num( 8, shift ); }
sub print_red { _print_num( 9, shift ); }
sub print_yellow { _print_num( 11, shift ); }
sub print_blue { _print_num( 6, shift ); }
sub print_green { _print_num( 2, shift ); }
sub info { print_blue @_; }
sub error { print_red @_; }
sub success { print_green @_; }
sub warning { print_yellow @_; }
sub debug { print_grey @_; }
my @softwares = (
{
title => 'Homebrew',
description => 'Homebrew is an automated software installer for Mac. It provides one-liner solution to resolve software dependencies.',
ok_to_install => sub {
debug 'Checking if XCode is installed by running `xcode-select -v`';
return `xcode-select -v` =~ /^xcode/;
},
install => sub {
debug 'Installing XCode Command Line Tools with `xcode-select --install`';
print `xcode-select --install`
debug 'Installing Homebrew using `ruby -e ...` with curl';
print `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`;
debug 'Install Homebrew Cask so there are more stuff that can be installed via Homebrew...';
print `brew install caskroom/cask/brew-cask`;
},
installed => sub {
debug 'Checking if Homebrew is installed by running `brew -v`';
return `brew -v` =~ /^Homebrew/;
},
},
# {
# title => '',
# description => '',
# ok_to_install => sub {},
# install => sub {},
# installed => sub {},
# },
);
############
### MAIN ###
############
foreach my $software (@softwares) {
info "=" x 32;
info "Now we are going to install $software->{title}.";
info "=" x 32;
info $software->{description};
success "Do you want to install $software->{title}? Press <ENTER> to contintue.";
success "Type something else and then press <ENTER> to skip this installation.";
my $in = <STDIN>;
if ( $in !~ /^\s*$/ ) {
warning "You are skipping installation of $software->{title}. Unexpected result may occur.";
next;
};
info "Checking if you have already installed $software->{title}:";
if ( $software->{installed}->() ) {
success "$software->{title} already installed. Next.\n";
next;
}
info "$software->{title} not installed. Run pre-install checks:";
if ( !$software->{ok_to_install}->() ) {
error "Your system settings are not ready for installing $software->{title}";
error "Aborting installation.";
last;
}
info "It can be installed on the system. Run install process:";
$software->{install}->();
info "Checking after installation...";
if ( $software->{installed}->() ) {
success "$software->{title} installed. Next.\n";
next;
}
error "Installation of $software->{title} failed. Abort.";
last;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment