The officially official Devuan Forum!

You are not logged in.

#1 2021-02-01 13:07:52

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

easy script to mount luks encrypted drives, usb etc.

This something to make my life easier, it just basically opens and mounts/unmounts a luke encrypted usb drive, could be any sort of pluggable drive i suppose. Thinking of adding some options to easily create full disk encryption to go along with these options as well.

Just thought i would share.

all that needs to be done is to have a usb or disk with a partuuid and a label and those are the parameters it opens and mounts by. But these parameters need to be added to the script manually.

so usage is as root cryptmount -m to open and mount

and cryptmount -u to unmount and close

#!/bin/sh

u=$(logname)

crypt_mount () {
        cryptsetup luksOpen "/dev/disk/by-partuuid/00000-1" usb;
        mount -L "BACKUPS" /media/"${u}"
}

crypt_umount () {
        umount -R /media/"${u}";
        cryptsetup close usb
}

while getopts ":mu" opt; do
  case "${opt}" in
        m ) crypt_mount
        ;;
        u ) crypt_umount
        ;;
        *)
        ;;
  esac
done

I would like to explore how to make this a kind of menu where you could pick available devices to encrypt and mount

Last edited by dice (2021-02-01 23:05:40)

Offline

#2 2021-02-01 19:15:59

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,409  

Re: easy script to mount luks encrypted drives, usb etc.

Maybe you can do something with these.

From refractainstaller. This lists partitions. It does not differentiate between encrypted and non-encrypted. Using blkid would be one way to find the encrypted partitions.

find /dev -mindepth 1 -maxdepth 1  | egrep  "*[shv]d[a-z][1-99]|*nvme[0-9]n[0-9]p[1-99]|*mmcblk[0-9]p[1-99]"   | sort | awk '{print "\n" $0 }'

Same thing with a graphical interface (yad)

device=$(find /dev -mindepth 1 -maxdepth 1  | egrep  "*[shv]d[a-z][1-99]|*nvme[0-9]n[0-9]p[1-99]|*mmcblk[0-9]p[1-99]" \
  | sort | awk '{print "\n" $0 }' \
  | yad --list   --title="Select device" --center --borders=10 --text="Select a device." \
  --separator="" --column ' ' --column$'Partitions' --height=380 --width=200 --button="OK":0)

From refracta2usb. These list usb devices.

usbdevlist=$(/usr/sbin/hwinfo --usb --short|grep "/dev/sd"|awk '{print $1}')
usbdevfulllist=$(/usr/sbin/hwinfo --usb --short|grep "/dev/sd"|awk '{print $0}')

And used with yad.

device=$(yad --width=400 --height=200 --center --title="$TITLE" --list --separator="" --column="" --text=$"Detected USB devices:\n\n$usbdevfulllist\n\nSelect the target device you want to copy the live image to." $usbdevlist \
	--button="OK":0 --button="Exit":1

I had to alter some of these so they would make sense. I hope I didn't break anything.

Offline

#3 2021-02-01 20:31:22

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: easy script to mount luks encrypted drives, usb etc.

dice wrote:
        m ) crypt_mount "$@"
        ;;
        u ) crypt_umount "$@"

Why are you passing the arguments applied to the script to those functions? They don't appear to do anything with them unless I'm missing something obvious.

fsmithred wrote:

From refracta2usb. These list usb devices.

usbdevlist=$(/usr/sbin/hwinfo --usb --short|grep "/dev/sd"|awk '{print $1}')
usbdevfulllist=$(/usr/sbin/hwinfo --usb --short|grep "/dev/sd"|awk '{print $0}')

No need for grep:

usbdevlist=$(/usr/sbin/hwinfo --usb --short|awk '/\/dev\/sd/{print $1}')
usbdevfulllist=$(/usr/sbin/hwinfo --usb --short|awk '/\/dev\/sd/{print $0}')

And here's a whiptail alternative for the yad dialogue:

usbdevlist() {
   /usr/sbin/hwinfo --usb --short|awk '/\/dev\/sd/{print $1,$1}'
}
device=$(whiptail --notags --menu "Please select the target device to which you want to copy the live image:" 0 0 0 $(usbdevlist) 3>&2 2>&1 1>&3)

Last edited by Head_on_a_Stick (2021-02-01 20:44:11)


Brianna Ghey — Rest In Power

Offline

#4 2021-02-01 23:05:01

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: easy script to mount luks encrypted drives, usb etc.

thanks fsmithred i will look into those today.

head on a stick, yes i forgot to remove those. I copied over that part of the script from anther script which is using them. Thanks for pointing that out and cheers for the whiptail reference.

Offline

#5 2021-02-02 09:57:52

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: easy script to mount luks encrypted drives, usb etc.

I just found out that pmount does what i want as far as mounting luks encrypted usb drives.

edited out script. Im just not getting it !

Last edited by dice (2021-02-02 10:26:03)

Offline

#6 2021-02-02 10:56:25

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,409  

Re: easy script to mount luks encrypted drives, usb etc.

Oh yeah, pmount. Try this -
https://sourceforge.net/projects/refrac … nt-1.2.deb

It works for removable USB, CD and mmc devices. Add any fixed drives to /etc/pmount.allow.

Offline

#7 2021-02-02 11:09:25

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: easy script to mount luks encrypted drives, usb etc.

thats excellent fsmithred, even opens spacefm in the required directory. I dont use gvfs or polkits so this is why im doing this. Will stop work on my script now, seems to redundant lol. Thanks again

Last edited by dice (2021-02-02 11:11:09)

Offline

Board footer