Skip to content

Instantly share code, notes, and snippets.

@tabletick
Last active October 12, 2015 03:38
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 tabletick/3965260 to your computer and use it in GitHub Desktop.
Save tabletick/3965260 to your computer and use it in GitHub Desktop.
Upload-script for octopress-deployment within a git-repository
#!/usr/bin/perl
# Deploying the Octopress Blogg via FTP
# Questions
#
# The script runs only inside the octopress folder structure and will abort if being run outside.
# Depends on File::chdir, File::Find::Rule, Net::FTP:Recursive, IO::Prompt, Timer::Runtime
use 5.10.1;
use strict;
use warnings;
use LWP::Simple;
use File::chdir;
use File::Find::Rule;
use Net::FTP::Recursive;
use IO::Prompt;
use Timer::Runtime;
#######################################
# Setting your parameters
my $FTPhost = "ftphost.com";
my $FTPuser = "yourftpuserg";
my $FTPRemoteFolder = "/blog";
my $OctopressPublicFolder = "public/blog";
#######################################
# There should be no changes needed after this point.
# Find the deployment folder and change to the Git Toplevel dir
my $PathGitToplevel = `git rev-parse --show-toplevel 2>/dev/null`;
die("Not a git repository. Abort.") if !$PathGitToplevel;
chomp($PathGitToplevel);
$CWD = "$PathGitToplevel";
# Try to find the deployment directory.
my @GitRepSubdirs = File::Find::Rule->directory->in('.');
foreach (@GitRepSubdirs) {
( $_ =~ m#$OctopressPublicFolder$# ) && ( $CWD = $_ );
}
( $CWD eq $PathGitToplevel ) && ( die "Can't find deploy-directory. Abort." );
# Try to connect to the FTP-Host
my $FTPpass = prompt(
-clear,
-echo => '*',
"\nUploading to $FTPhost\nPlease enter password: "
);
my $FTPconnection = Net::FTP::Recursive->new( $FTPhost, Debug => 0 )
or die "Could not connect to '$FTPhost': $@";
$FTPconnection->login( $FTPuser, $FTPpass )
or die "Could not login.", $FTPconnection->message;
$FTPconnection->cwd($FTPRemoteFolder)
or die "Could not find destination folder.", $FTPconnection->message;
# Show plan and ask for permission
say "Source: " . $CWD . "\nDestionation: " . $FTPconnection->pwd();
my $answer = prompt "Continue [y/n] [y]? : ", -d => 'y', -one_char;
( $answer eq 'n' ) && ( die "script aborted." )
|| ( say "\nStarting to upload..." );
$FTPconnection->rput('.');
$FTPconnection->quit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment