800 byte "daemon tools"-like wrapper for luks dm-crypt

Antivirus, forensics, intrusion detection, cryptography, etc.
Post Reply
Message
Author
aaa3
Posts: 15
Joined: Wed 02 Oct 2013, 14:29

800 byte "daemon tools"-like wrapper for luks dm-crypt

#1 Post by aaa3 »

command line script, extremely noob-friendly code text, compared to 4ex. the hyper-complex /usr/sbin/filemnt
takes file with full path as argument, automatically chooses all things and does all 3 commands in forward and reverse order, same action for both directions,
much faster than manually typing everything for every file. this is my first script so may contain bugs; atm very feature-poor but already includes checks for no-loopdev-escalation (as visible just an afterthought - such luxuries can be removed if bothering ur need for clean code... main logic at left, trash is at side; left can (and should at first) be read alone and right only tooken care at second pass read)

cryptmontools.sh - goddam codequoter-font is not monospaced...

Code: Select all

#!/bin/sh
 

dir=$( echo $1 | tr / _ | tr [:space:] . )                      #translate chars in arg

if test "$( cat /proc/mounts | grep $dir )" = ""                ;then mkdir "/mnt/$dir" ; if test "$( losetup | grep "$1" )" = "" ;then    #| chains commands, grep searches for lines
     whichlo=$( losetup -f ) ; loop=$whichlo                    ;else loop=$( losetup | grep "$1" | head -n 1 | cut --delimiter=: --fields=1 ) ;fi    #first free, or used aft faild mnt - take just 1 line; take part of a grep line
     losetup $loop "$1"                                         ;pkill udev
     cryptsetup luksOpen $loop $dir
     mount "/dev/mapper/$dir" "/mnt/$dir"                       ;echo mounted to "/mnt/$dir"
else umount "/mnt/$dir"
     cryptsetup luksClose $dir
     rmdir "/mnt/$dir"                                          ;loop=$( losetup | grep "$1" | tail -n 1 | cut --delimiter=: --fields=1 )
     losetup -d $loop                                           ;echo unmounted ;fi



# (pubdm) by aaa3 @2014-05-30
(copypaste) loot it now! :D












--------

1 day later edit: new version, nothing changes.
read these pasted into a monospace notepad, not here; also with line wrapping temporarily off

Code: Select all

#!/bin/sh


dir=$( echo $1 | tr / _ | tr [:space:] . )                      #translate chars in arg

if test "$( cat /proc/mounts | grep $dir )" = ""                ;then mkdir "/mnt/$dir" ; if test "$( losetup | grep "$1" )" = "" ;then    #| chains commands, grep searches for lines
     whichlo=$( losetup -f ) ; loop=$whichlo                    ;else loop=$( losetup | grep "$1" | head -n 1 | cut --delimiter=: --fields=1 ) ;fi; losetup $loop "$1" ; name=$dir ; pkill udev    #first free, or used aft faild mnt; #take just 1 line; take part of a grep line; #name added just for understanding, it was perfectly fine as dir; just like "loop"&"w" is 2 name for one thing; also, imagine ls syntax as "losetup $1 loop" to align w rest
     #losetup "$1" $loop
     cryptsetup luksOpen $loop $name
     mount "/dev/mapper/$name" "/mnt/$dir"                      ;echo mounted to "/mnt/$dir"
else umount "/mnt/$dir"
     cryptsetup luksClose $name
     rmdir "/mnt/$dir"                                          ;loop=$( losetup | grep "$1" | tail -n 1 | cut --delimiter=: --fields=1 )
     losetup -d $loop                                           ;echo unmounted ;fi



# (pubdm) by me @2014-05-30,31

Post Reply