Instantly share code, notes, and snippets.

Embed
What would you like to do?
Julia script for mass production of USB sticks (e.g. for conference proceedings)
#!/usr/bin/env julia
# configuration
source_dir = "proceedings/" # trailing slash is important
volumes_dir = "/Volumes"
exclude_volumes = [".DS_Store", "Macintosh HD", "Work TM"]
exclude_disks = ["/dev/disk0", "/dev/disk1"]
tic()
# disks to format
disks = ASCIIString[]
for disk_str in readlines(`diskutil list` |> `grep /dev/disk`)
disk = rstrip(disk_str)
if !in(disk, exclude_disks)
push!(disks, disk)
end
end
println("### Formatting ###")
format_cmd = ``
for (idx, disk) in enumerate(disks)
if idx == 1
format_cmd = `diskutil quiet eraseDisk fat32 SPAWC2015 MBR $disk`
else
format_cmd = format_cmd & `diskutil quiet eraseDisk fat32 SPAWC2015 MBR $disk`
end
end
run(format_cmd)
# volumes after formatting
volumes = ASCIIString[]
for vol in readdir(volumes_dir)
if !in(vol, exclude_volumes)
push!(volumes, vol)
end
end
sleep(5)
println("### Copying ###")
copy_cmd = ``
for (idx, vol) in enumerate(volumes)
output_dir = joinpath(volumes_dir, vol)
if idx == 1
copy_cmd = `cp -R -X $source_dir $output_dir`
else
copy_cmd = copy_cmd & `cp -R -X $source_dir $output_dir`
end
end
run(copy_cmd)
sleep(5)
println("### Clearing Mac OS X dot files ###")
for vol in volumes
output_dir = joinpath(volumes_dir, vol)
run(`rm -rf $output_dir/.DS_Store $output_dir/.fseventsd $output_dir/.Spotlight-V100 $output_dir/.Trashes`)
end
sleep(5)
println("### Unmounting ###")
for disk in disks
run(`diskutil quiet unmountDisk $disk`)
end
toc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment