Skip to content

Instantly share code, notes, and snippets.

@vkgtaro
Created December 15, 2011 19:41
Show Gist options
  • Select an option

  • Save vkgtaro/1482505 to your computer and use it in GitHub Desktop.

Select an option

Save vkgtaro/1482505 to your computer and use it in GitHub Desktop.
tiny deploy tool
use strict;
use warnings;
use utf8;
my $remotes = [
{ user => 'user name', host => 'host name', project_dir => 'project directory' },
];
MAIN: {
for my $remote ( @{$remotes} ) {
eval {
rsync($remote->{user}, $remote->{host}, $remote->{project_dir});
remote_install($remote->{user}, $remote->{host}, $remote->{project_dir});
};
if ( $@ ) {
die sprintf("%s (%s@%s)", $@, $remote->{user}, $remote->{host});
}
}
}
sub rsync {
my ($user, $host, $project_dir) = @_;
my $rsync_to = sprintf "%s@%s:%s", $user, $host, $project_dir;
system('rsync', '-ave', 'ssh', '.', $rsync_to);
}
sub remote_install {
my ($user, $host, $project_dir) = @_;
my $execute_host = sprintf "%s@%s", $user, $host;
my $execute = sprintf "cd %s; perl bin/dev/install.pl", $project_dir;
system('ssh', $execute_host, $execute);
}
use strict;
use warnings;
use utf8;
use Cwd;
my $TMP_DIR = $ARGV[0] || '/tmp';
my $CURRENT_DIR = cwd;
MAIN: {
system('cpanm', 'Module::Install');
install_from_git('git://github.com/tomyhero/p5-App-Home.git', 'p5-App-Home');
chdir $CURRENT_DIR;
system('cpanm', '--installdeps', '.');
};
sub install_from_git {
my ($repository, $dir) = @_;
my $install_dir = join "/", $TMP_DIR, $dir;
if ( -e $install_dir ) {
chdir $install_dir;
system('git', 'pull');
system('cpanm', '.');
}
else {
chdir $TMP_DIR;
system('git', 'clone', $repository, $dir);
system('cpanm', '.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment