Skip to content

Instantly share code, notes, and snippets.

@lukaselmer
Forked from pencil/syncscript.rb
Created December 5, 2012 13:21
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 lukaselmer/4215465 to your computer and use it in GitHub Desktop.
Save lukaselmer/4215465 to your computer and use it in GitHub Desktop.
HSR Syncscript (Ruby)
#!/usr/bin/env ruby
require 'fileutils'
require 'optparse'
SOURCEDIR='/Volumes/root/skripte'
DESTDIR="/Users/#{ENV['USER']}/Dropbox/Documents/HSR/Semester5/skripte"
Subject = Struct.new :source, :destination, :parameters
SUBJECTS = [
Subject.new('Informatik/Fachbereich/Computernetze_1/CN1/', 'CN1', '--exclude *.pcap --exclude Videos'),
Subject.new('Mathematik_Naturwissenschaften/Physik_1/Ph1Mech/', 'Ph1Mech'),
Subject.new('Informatik/Fachbereich/Informations-_und_Codierungstheorie/ICTh/', 'ICTh', '--exclude Signal-Videos/*.exe'),
Subject.new('Informatik/Fachbereich/Microsoft-Technologien/MsTe/', 'MsTe'),
Subject.new('Informatik/Fachbereich/Betriebssysteme_1/Bsys1/', 'Bsys1'),
Subject.new('Informatik/Fachbereich/Enterprise_Computing/EnCom/', 'EnCom')
]
verbose = false
OptionParser.new do |opts|
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
verbose = v
end
end.parse!
unless File.exists? SOURCEDIR
puts "Source directory #{SOURCEDIR} does not exist!"
exit 1
end
unless File.exists? DESTDIR
puts "Destination directory #{DESTDIR} does not exist!"
exit 1
end
FileUtils.chmod_R('u+w', DESTDIR)
start = Time.now
puts "Syncing files with Dropbox (#{start.inspect})..."
puts "Source: #{SOURCEDIR}/... // Destiniation: #{DESTDIR}/..."
SUBJECTS.each do |subject|
puts "> #{subject.destination}"
destination = "#{DESTDIR}/#{subject.destination}"
unless File.exists? destination
Dir.mkdir destination
end
system("rsync --delete -a#{'v' if verbose} #{subject.parameters || ''} '#{SOURCEDIR}/#{subject.source}' '#{destination}'")
end
puts "Syncing finished. It took #{Time.now - start} seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment