Skip to content

Instantly share code, notes, and snippets.

@marhan
Created January 4, 2011 20:38
Show Gist options
  • Save marhan/765376 to your computer and use it in GitHub Desktop.
Save marhan/765376 to your computer and use it in GitHub Desktop.
Groovy Script for mounts with TrueCrypt
// List of mounts
List<Mount> mounts = [new Mount("/PATH/TO/image.tc", "/PATH/TO/MOUNT")];
// Invocation of routines
TCAutoMounter mounter = new TCAutoMounter(mounts, args[0]);
mounter.mount();
// OOP
/**
* Mounts automatically all defined sources to destinations.
* @author markus
**/
class TCAutoMounter {
private String TRUE_CRYPT = "/Applications/TrueCrypt.app/Contents/MacOS/TrueCrypt";
private String OPTIONS = "--non-interactive --mount --password=";
private String SHELL = "/bin/bash -c ";
private String password;
private List<Mount> mounts;
public TCAutoMounter(List<Mount> mounts, String password) {
this.password = password;
this.mounts = mounts;
}
/**
* Mount automatically with password.
**/
public void mount() {
if (password == null || password.length() == 0) {
println "No password was given!";
} else if(mounts == null || mounts.size() == 0) {
println "No mounts defined!";
} else {
//int size = mounts.size();
//println size + " mounts defined";
for (item in mounts) {
execute(item.source, item.destination);
}
}
}
/**
* Executes the mounts within the command line.
* @param source The source file.
* @param dest The destination folder of mount.
*/
private void execute(String source, String dest) {
String command = TRUE_CRYPT + " " + OPTIONS + password + " " + source + " " + dest;
//println "Command will be executed: " + command
def proc = command.execute();
proc.waitFor();
if (proc.exitValue() == 0) {
println "Mount of " + dest + " to " + source + " successful.";
} else {
println "";
println "Mount of " + dest + " to " + source + " FAILED!";
println "";
println "Error text => ${proc.err.text}";
}
}
}
/**
* Bean for definition of mounts.
* @author markus
**/
class Mount {
String source;
String destination
public Mount(String source, String destination) {
this.source = source;
this.destination = destination;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment