log_info "starting bitcoin core..."
mkdir -p "$DATA_DIRECTORY"
- bitcoind -daemonwait -datadir="$DATA_DIRECTORY" -chain=regtest &> /dev/null
+ bitcoind -daemonwait -datadir="$DATA_DIRECTORY" &> /dev/null
log_info "bitcoin core started"
}
usb_crypt_open() {
log_info "usb encrypted... opening..."
- cryptsetup luksOpen "$USB_PATH" "$USB_DECRYPT_NAME"
+ sudo cryptsetup luksOpen "$USB_PATH" "$USB_DECRYPT_NAME"
USB_PATH_PRE_DECRYPT="$USB_PATH"
USB_PATH="/dev/mapper/$USB_DECRYPT_NAME"
}
usb_crypt_close() {
log_info "closing encrypted usb..."
- cryptsetup luksClose "$USB_DECRYPT_NAME"
+ sudo cryptsetup luksClose "$USB_DECRYPT_NAME"
USB_PATH="$USB_PATH_PRE_DECRYPT"
USB_PATH_PRE_DECRYPT=""
}
usb_encrypt() {
log_info "encrypting $USB_PATH..."
- cryptsetup luksFormat --type luks2 "$USB_PATH"
+ sudo cryptsetup luksFormat --type luks2 "$USB_PATH"
}
usb_eject() {
log_info "ejecting $USB_PATH..."
- eject "$USB_PATH"
+ sudo eject "$USB_PATH"
log_info "ejected $USB_PATH"
}
}
usb_mount() {
- if [[ -n "$ENCRYPTION" ]]; then
- usb_decrypt
- fi
-
mkdir -p "$USB_DIRECTORY"
log_info "mounting $USB_PATH at $USB_DIRECTORY"
- mount "$USB_PATH" "$USB_DIRECTORY"
+ sudo mount "$USB_PATH" "$USB_DIRECTORY"
+ local USERNAME="`whoami`"
+ sudo chown "$USERNAME:$USERNAME" "$USB_DIRECTORY"
}
usb_setup() {
- wipefs -a "$USB_PATH"
+ sudo wipefs -af "$USB_PATH"
log_info "filesystem wiped from $USB_PATH"
if [[ -n "$ENCRYPTION" ]]; then
usb_encrypt
+ usb_crypt_open
fi
log_info "zero'ing $USB_PATH"
- dd if=/dev/zero of="$USB_PATH"
+
+ # this is necessary because dd will write until
+ # no space left on device and then error out. We
+ # wish to ignore this error.
+ set +e
+ sudo dd if=/dev/zero of="$USB_PATH"
+ set -e
+
log_info "$USB_PATH filled with zeroes"
- mkfs.ext4 "$USB_PATH"
+ sudo mkfs.ext4 "$USB_PATH"
log_info "created new filesystem on $USB_PATH"
}
usb_unmount() {
log_info "unmounting $USB_DIRECTORY..."
- umount "$USB_DIRECTORY"
+ sudo umount "$USB_DIRECTORY"
if [[ -n "$ENCRYPTION" ]]; then
usb_crypt_close
log_msg "found usb stick $USB_PATH"
usb_setup
+ usb_mount
usb_load "$i"
usb_unmount
usb_eject
log_msg "found usb stick $USB_PATH"
usb_setup
+ usb_mount
usb_load "$i"
usb_unmount
usb_eject