add initial version
This commit is contained in:
commit
b825ff7a6c
93
mk-usb-car-music.rb
Executable file
93
mk-usb-car-music.rb
Executable file
@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
|
MUSIC_DIR = "/pegasus/pub/music/artists"
|
||||||
|
ARTISTS = <<EOS.split("\n").map(&:strip).sort
|
||||||
|
All That Remains
|
||||||
|
Avenged Sevenfold
|
||||||
|
Falling in Reverse
|
||||||
|
Fear Factory
|
||||||
|
Five Finger Death Punch
|
||||||
|
Godsmack
|
||||||
|
In Flames
|
||||||
|
Korn
|
||||||
|
Lamb of God
|
||||||
|
Linkin Park
|
||||||
|
Machine Head
|
||||||
|
Mudvayne
|
||||||
|
POD
|
||||||
|
Slipknot
|
||||||
|
Staind
|
||||||
|
Static-X
|
||||||
|
System of a Down
|
||||||
|
The Goo Goo Dolls
|
||||||
|
The Offspring
|
||||||
|
Tool
|
||||||
|
Trivium
|
||||||
|
EOS
|
||||||
|
MOUNT_DIR = "/tmp/mk-usb-car-music"
|
||||||
|
|
||||||
|
def run(*cmd)
|
||||||
|
puts cmd.map {|p| "'#{p}'"}.join(" ")
|
||||||
|
system(*cmd) or raise
|
||||||
|
end
|
||||||
|
|
||||||
|
def main(args)
|
||||||
|
if args.find {|a| %w[-h --help].include?(a)}
|
||||||
|
puts <<EOS
|
||||||
|
Usage: #{$0}
|
||||||
|
-h, --help Show this help and exit
|
||||||
|
-s Show folder sizes and exit
|
||||||
|
-d DEV Set USB device
|
||||||
|
EOS
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
if args.find {|a| a == "-s"}
|
||||||
|
run("du", "-shc", *ARTISTS.map {|a| "#{MUSIC_DIR}/#{a}"})
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
device = ""
|
||||||
|
args.each_with_index do |arg, i|
|
||||||
|
if arg =~ /^-d(.*)$/
|
||||||
|
device = $1
|
||||||
|
if device == "" and args.length > (i + 1)
|
||||||
|
device = args[i + 1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if device == ""
|
||||||
|
$stderr.puts "Specify device."
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
run(*%W[sudo mkfs.vfat -n JOSHMUSIC #{device}]) or raise
|
||||||
|
FileUtils.rm_rf(MOUNT_DIR)
|
||||||
|
FileUtils.mkdir(MOUNT_DIR)
|
||||||
|
run(*%W[sudo mount #{device} #{MOUNT_DIR} -o uid=#{`whoami`.chomp}]) or raise
|
||||||
|
begin
|
||||||
|
ARTISTS.each do |artist|
|
||||||
|
src = "#{MUSIC_DIR}/#{artist}"
|
||||||
|
dest = "#{MOUNT_DIR}/#{artist}"
|
||||||
|
src_folders = Dir["#{src}/*"].select do |path|
|
||||||
|
File.directory?(path)
|
||||||
|
end.sort
|
||||||
|
FileUtils.mkdir(dest)
|
||||||
|
src_folders.each do |src_folder|
|
||||||
|
puts "Copying #{src_folder}..."
|
||||||
|
dest_folder = "#{dest}/#{File.basename(src_folder)}"
|
||||||
|
FileUtils.mkdir(dest_folder)
|
||||||
|
src_files = Dir["#{src_folder}/*"].select do |path|
|
||||||
|
File.file?(path)
|
||||||
|
end.sort
|
||||||
|
src_files.each do |src_file|
|
||||||
|
FileUtils.cp(src_file, dest_folder)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
run(*%W[sudo umount #{MOUNT_DIR}]) or raise
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
exit(main(ARGV))
|
Loading…
x
Reference in New Issue
Block a user