]> infiniteadaptability.org Git - cold/commitdiff
...
authoralex <[email protected]>
Tue, 28 Jun 2022 20:17:21 +0000 (13:17 -0700)
committeralex <[email protected]>
Tue, 5 Jul 2022 15:05:17 +0000 (16:05 +0100)
cold-setup

index 81127a7b56dac29264249f54c2f6ace48230dbe2..4d72ca41ec83df09ab31603851643162200c53a2 100755 (executable)
@@ -30,7 +30,7 @@ bitcoin_core_start() {
 
        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"
 }
 
@@ -273,14 +273,14 @@ usage() {
 
 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=""
 }
@@ -312,12 +312,12 @@ usb_detect() {
 
 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"
 }
 
@@ -342,34 +342,40 @@ usb_load() {
 }
 
 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
@@ -384,6 +390,7 @@ usbs() {
                log_msg "found usb stick $USB_PATH"
 
                usb_setup
+               usb_mount
                usb_load "$i"
                usb_unmount
                usb_eject
@@ -396,6 +403,7 @@ usbs() {
                log_msg "found usb stick $USB_PATH"
 
                usb_setup
+               usb_mount
                usb_load "$i"
                usb_unmount
                usb_eject