-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrmnt
executable file
·60 lines (53 loc) · 1.57 KB
/
scrmnt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/zsh
CRYPTSETUP="/usr/sbin/cryptsetup"
ACTIONS=(open close)
ACTION=
DEVICES=(int ext flash)
DEVICE="int"
REMOVE=
help() {
echo
echo "Mounts secret device. Needs to be ran as user."
echo
echo "Options:"
echo "-a <action> 'open' or 'close' the device."
echo "-d <device> Select device: ext, flash, or internal if not specified."
echo "-t <target> Set mount point. Default: /mnt/\$DEVICE"
echo "-r Remove target after closing the device."
echo
}
[[ -z $1 ]] && help && exit 1
[[ $1 == '--help' ]] && help && exit
[[ $(whoami) != 'tampakrap' ]] && help && exit 1
while getopts a:d:t:rh arg; do
case ${arg} in
a) ACTION=${OPTARG}
[[ ${ACTIONS[(r)${ACTION}]} != ${ACTION} ]] && help && exit 1
;;
d) DEVICE=${OPTARG}
[[ ${DEVICES[(r)${DEVICE}]} != ${DEVICE} ]] && help && exit 1
;;
m) TARGET=${OPTARG} ;;
r) REMOVE=1 ;;
h) help && exit ;;
*) help && exit 1 ;;
esac
done
case $DEVICE in
ext) BLOCK="/dev/vg_ext/usr" ;;
flash) BLOCK="/dev/sdb1" ;;
int) BLOCK="/dev/vg/usr" ;;
esac
[[ -n $TARGET ]] || TARGET="/mnt/prv${DEVICE}"
case $ACTION in
open)
[[ -d $TARGET ]] || sudo mkdir $TARGET
echo -n $(pass forkbomb.gr/$HOSTNAME/scrmnt/$DEVICE) | sudo $CRYPTSETUP luksOpen $BLOCK prv$DEVICE -d -
sudo mount /dev/mapper/prv$DEVICE $TARGET
;;
close)
sudo umount $TARGET
sudo $CRYPTSETUP luksClose /dev/mapper/prv$DEVICE
[[ -n $REMOVE ]] && sudo rmdir $TARGET
;;
esac