-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssys5
executable file
·130 lines (115 loc) · 3.97 KB
/
ssys5
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env bash
#-------------------------------------------------------------------------#
# ssys5 #
# #
# Author: Nic H. #
# Date: 2016-Mar-31 #
# #
# A more general-purpose alternative to ssys4 which allows multiple #
# secure stores with different passwords to be chosen by the user. #
# Intelligently detects if the tag-base should also be run. #
# #
# Usage: #
# ssys5 [-c] <path> #
# mounts the directory at <path> as the secure directory #
# #
# Options: #
# -c create mode, create a new secure directory #
# -h print this help message #
# -k kill an improperly closed session #
# -t force the directory to run as a TagBase #
# -w force the directory to run in wait mode #
#-------------------------------------------------------------------------#
set -e
set -u
function usage(){
grep "^#.*#$" $0
}
function clean(){
rm -rf ~/Private/.Trash*
ecryptfs-umount-private
rm ~/.Private
rm -r ~/.ecryptfs
rmdir ~/Private
}
CREATE=false
TAG=unknown
TAG_BASE=`readlink -m ~/project/computing/TagBase`
while getopts "chktw" opt; do
case $opt in
c)
CREATE=true
;;
h)
usage
exit 0
;;
k)
clean
exit 0
;;
t)
TAG=true
;;
w)
TAG=false
;;
\?)
usage
exit 1
;;
esac
done
shift $(($OPTIND -1))
# make sure everything is fine
[ $# == 1 ] || (usage >&2; exit 1)
[ -e ~/.Private ] && (echo "~/.Private already exists" >&2; exit 1)
[ -e ~/Private ] && (echo "~/Private already exists" >&2; exit 1)
[ -e ~/.ecryptfs ] && (echo "~/.ecryptfs already exists" >&2; exit 1)
# create the directory when necessary
if [ $CREATE == "true" ]; then
[ -e "$1" ] && (echo "$1 already exists" >&2; exit 1)
mkdir -p "$1"
ecryptfs-setup-private -w --noautomount
mv ~/.Private "$1/ssys_data"
mv ~/.ecryptfs/* "$1/"
rmdir ~/.ecryptfs
chmod a+w ~/Private
rm -r ~/Private
fi
# exit if the user gave a non-directory
[ -d "$1/ssys_data/" ] || (echo "$1 is not a ssys directory" >&2; exit 1)
# Make ~/Private and symlink ~/.Private to the required directory
mkdir ~/Private
ln -s $(readlink -f "$1/ssys_data") ~/.Private
# make .ecryptfs and symlink all the metadata
mkdir ~/.ecryptfs
for FI in `ls "$1" | grep -v "^ssys_data$"`; do
ln -s $(readlink -f "$1/$FI") ~/.ecryptfs/$FI
done
# Mount the directory
ecryptfs-mount-private
xdg-open ~/Private
echo
# determine if we are in tag mode
if [ -f ~/Private/zzList.txt ]; then
if [ $TAG == false ]; then
echo "Ignoring the TagBase meta-file"
else
TAG=true
fi
fi
if [ ! -f $TAG_BASE/Main.class ]; then
[ $TAG == true ] && echo "Disabling the TagBase, you must compile it into $TAG_BASE"
TAG=false
fi
# in tag mode, wait until the tagbase is closed, otherwise wait until the user hits return
if [ $TAG == true ]; then
java -cp $TAG_BASE Main ~/Private
else
echo "+-------------------------------------------+"
echo "| Directory unlocked, press <enter> to lock |"
echo "+-------------------------------------------+"
read line
fi
clean