Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Better ramdisk sizing and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed Oct 16, 2017
1 parent 8fb5313 commit 809ea67
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions create-secure-dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ if [[ $(id -u) != 0 || -z $SUDO_USER || -z $SUDO_UID || -z $SUDO_GID ]]; then
fi

function log {
local msg="\e[34m${1}%s\e[0m\n"
local msg="\e[34m${1}\e[0m\n"
shift
# shellcheck disable=SC2059
printf "$msg" "$@"
}

undo=""
trap 'eval "$undo"' ERR EXIT
trap 'printf "\e[31mAn error occurred. Press <ENTER> to undo previous operations\e[0m"
read -r
eval "$undo"' ERR

volname=${1:-secure}
mountpoint="$PWD/$volname"
size=$((16*2096))

log "Creating ramdisk"
ramdisk_path=$(hdik -nomount ram://2048)
ramdisk_path=$(hdik -nomount "ram://$size")
# hdik outputs trailing spaces and tabs for some reason
ramdisk_path=${ramdisk_path//[[:space:]]}

Expand Down Expand Up @@ -88,6 +91,6 @@ rmdir '$mountpoint' && \\
diskutil eject '$ramdisk_path'
EOF

undo=""
trap "" ERR
log "\nSecure directory created at \`%s'." "$mountpoint"
log "The directory can be destroyed with ./destroy-secure-dir.sh"

0 comments on commit 809ea67

Please sign in to comment.