-
-
Save pencil/4041618 to your computer and use it in GitHub Desktop.
HSR Syncscript (Ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'optparse' | |
SOURCEDIR='/Volumes/root/skripte' | |
DESTDIR="/Users/#{ENV['USER']}/Dropbox/Documents/HSR/Semester5/skripte" | |
MAX_SIZE='20m' | |
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}/... // Destination: #{DESTDIR}/..." | |
SUBJECTS.each do |subject| | |
puts "> #{subject.destination}" | |
destination = "#{DESTDIR}/#{subject.destination}" | |
unless File.exists? destination | |
Dir.mkdir destination | |
end | |
system("rsync #{('--max-size=' + MAX_SIZE) if MAX_SIZE} --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