Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# THIS IS A RAKEFILE
# NOTE: See .encfs6.xml file in this directory!
plaintext_dir = "/Volumes/FD Disk/"
filtered_dir = "/Volumes/FD Disk/FILTERED NOSYNC/"
ciphertext_dir = "/tmp/fd-disk-encrypted/"
backup_location = "root@camera.phor.net:/root/fd-disk-encrypted/"
backup_location_tmp = "root@camera.phor.net:/root/fd-disk-encrypted-tmpdelete/"
photo_dir = "/Volumes/FD Disk/media/my photos/"
cameralife_location = "root@camera.phor.net:/home/cameralife-photos/"
rsync_command = "/usr/local/bin/rsync"
extpass = "security find-generic-password -gwl encfs 2>&1"
excludes_file = "/tmp/rsync-excludes"
require "tmpdir"
# http://stackoverflow.com/a/11320444/300224
Rake::TaskManager.record_task_metadata = true
desc "Show all the tasks"
task :default do
Rake::application.options.show_tasks = :tasks # this solves sidewaysmilk problem
Rake::application.options.show_task_pattern = //
Rake::application.display_tasks_and_comments
end
desc "Install excludes file locally"
task :install_excludes do
next if File.exists?(excludes_file)
puts 'Installing excludes file locally'.yellow
file = <<-eos
.Spotlight-V100
/.fseventsd
/.hotfiles.btree
/.vol/*
/Auth.bak
/Cleanup At Startup
/TheVolumeSettingsFolder
.Trash
.Trashes
/TheFindByContentFolder
/Shutdown Check
/OpenFolderListDF
/.com.apple.NetBootX
.VolumeIcon.icns
._*
/.TemporaryItems
.DS_Store
.ds_store
.AppleDouble
home/phor
.directory
.DocumentRevisions-V100
*NOSYNC*
*DONT SYNC*
/.*
eos
File.write(excludes_file, file)
puts ('Installed to '+excludes_file).green
end
desc "Filter files for syncing"
task :filter => [:install_excludes] do
print "Filtering files from ".yellow, plaintext_dir.pink, " to ".yellow, filtered_dir.pink, " using ".yellow, excludes_file.pink, "\n"
sh rsync_command, '--info=progress2', '--exclude-from', excludes_file, '--archive', '--xattrs', '--delete', '--link-dest', plaintext_dir, plaintext_dir, filtered_dir
cp plaintext_dir + '.encfs6.xml', filtered_dir + '.encfs6.xml' # BECAUSE THIS IS BLOCKED BY EXCLUDES ABOVE!
puts 'Done'.green
end
desc "Encrypt and mount filesystem"
task :encrypt => [:filter] do
# next if File.exists?(ciphertext_dir)
require 'shellwords'
print "Encrypting from ".yellow, filtered_dir.pink, " to ".yellow, ciphertext_dir.pink, "\n"
sh "umount #{ciphertext_dir.shellescape} > /dev/null 2> /dev/null || :" # ignore retval
sh "yes | encfs -i 30 --reverse #{filtered_dir.shellescape} #{ciphertext_dir.shellescape} --extpass=#{extpass.shellescape}"
# sh "yes | encfs -i 30 --reverse #{plaintext_dir.shellescape} /tmp/fd-disk-encrypted2 --extpass=#{extpass.shellescape}"
puts "Encrypted".green
end
desc "Sync encrypted files to backup server (dry run)"
task :backup_dry => [:encrypt] do
print "Backing up from ".yellow, ciphertext_dir.pink, " to ".yellow, backup_location.pink, "\n"
sh 'caffeinate', rsync_command, '--dry-run', '-irlt', '--delete', '--info', 'progress2', '--stats', ciphertext_dir, backup_location
puts "Backup complete".green
end
desc "Sync encrypted files to backup server (dry run)"
task :backup => [:encrypt] do
print "Backing up from ".yellow, ciphertext_dir.pink, " to ".yellow, backup_location.pink, "\n"
sh 'caffeinate', rsync_command, '-irlt', '--delete', '--info', 'progress', '--stats', ciphertext_dir, backup_location
puts "Backup complete".green
end
desc "Sync photos to Camera Life server"
task :publish_photos => [:install_excludes] do
puts 'Syncing photos (DRY RUN)'.yellow
sh 'caffeinate', rsync_command, '-nrlt', '--stats', '--delete', '--exclude', '*NOCL*', '--exclude-from', '/tmp/rsync-excludes', '--info', 'progress', photo_dir, cameralife_location
puts 'Push any key to continue [or Ctrl-C to back out]'.pink
system 'read continue'
puts 'Syncing photos (DRY RUN)'.yellow
sh 'caffeinate', rsync_command, '-rlt', '--delete', '--info', 'progress', '--exclude', '*NOCL*', '--exclude-from', '/tmp/rsync-excludes', '--info', 'progress', photo_dir, cameralife_location
end
desc "Clean up all temporary files"
task :clean do
puts 'Deleting all temporary and intermediate files'.yellow
File.unlink(excludes_file)
FileUtils.remove_dir(filtered_dir)
puts 'Done'.green
end
# http://stackoverflow.com/questions/1489183/colorized-ruby-output
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
def green
colorize(32)
end
def yellow
colorize(33)
end
def pink
colorize(35)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment