Skip to content

Instantly share code, notes, and snippets.

@mmb
Last active August 29, 2015 14:03
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 mmb/a63781752286f431d079 to your computer and use it in GitHub Desktop.
Save mmb/a63781752286f431d079 to your computer and use it in GitHub Desktop.
When USB drives are mounted, check them for a script called plz_verify.sh and run it if found.
#!/usr/bin/env ruby
# When USB drives are mounted, check them for a script called plz_verify.sh
# and run it if found.
#
# symlink all USB volumes you want to check into ~/usb
# ln -s /Volumes/mmb ~/usb/mmb
require 'logger'
require 'set'
logger = Logger.new(STDOUT)
state = Set.new
while true do
# the extra stars are for symlinks
current = Set.new(Dir.glob("#{Dir.home}/usb/**/*/**/plz_verify.sh"))
gone = state - current
new = current - state
state = current
gone.each do |script|
logger.info("#{script} unmounted")
end
new.each do |script|
logger.info("running #{script}")
script_contents = File.read(script)
IO.popen('sh', 'w') do |io|
io.write(script_contents)
end
end
sleep 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment