Skip to content

Instantly share code, notes, and snippets.

@inokii
Last active April 25, 2018 19:53
Show Gist options
  • Save inokii/76f21b4dd6b7d76db096 to your computer and use it in GitHub Desktop.
Save inokii/76f21b4dd6b7d76db096 to your computer and use it in GitHub Desktop.
Simple demonstration of automated EncFS creation using the expect program.
#!/usr/bin/env expect
# Simple demonstration of automated EncFS creation using the expect program.
# EncFS: an Encrypted Filesystem for FUSE. https://vgough.github.io/encfs/
if {[llength $argv] < 2} {
send_user "Usage: auto_encfs_creation.exp rootDir mountPoint\n"
exit 1
}
set ROOT_DIR [lindex $argv 0]
set MOUNT_POINT [lindex $argv 1]
set CIPHER 1
set KEY_SIZE 256
set BLOCK_SIZE 4096
set FILENAME_ENCODING_ALGORITHM 3
#set PASSWORD "password"
# prompt user for password if you don't want it stored in the script
stty -echo
send_user -- "Encfs Password: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set PASSWORD $expect_out(1,string)
# create encfs process
spawn encfs $ROOT_DIR $MOUNT_POINT
# send expert configuration mode
expect "Please choose from one of the following options:"
expect "?>"
send "x\n"
# send cipher algorithm
expect "Enter the number corresponding to your choice: "
send "$CIPHER\n"
# send key size
expect "Selected key size: "
send "$KEY_SIZE\n"
# send block size
expect "filesystem block size: "
send "$BLOCK_SIZE\n"
# send filename encoding algorithm
expect "Enter the number corresponding to your choice: "
send "$FILENAME_ENCODING_ALGORITHM\n"
# select default setting for filename initialization vector chaining
expect "Any response that does not begin with 'n' will mean Yes: "
send "\n"
# select default setting for per-file initialization vectors
expect "Any response that does not begin with 'n' will mean Yes: "
send "\n"
# select default setting for filename to IV header chaining
expect "Any response that does not begin with 'y' will mean No: "
send "\n"
# select default setting for block authentication code headers
expect "Any response that does not begin with 'y' will mean No: "
send "\n"
# select default setting for adding random bytes to each block header
expect "Select a number of bytes, from 0 (no random bytes) to 8: "
send "\n"
# select default setting for file-hole pass-through
expect "Any response that does not begin with 'n' will mean Yes: "
send "\n"
# send password
expect "New Encfs Password: "
send "$PASSWORD\n"
# send password confirmation
expect "Verify Encfs Password: "
send "$PASSWORD\n"
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment