_checkinit helper
This commit is contained in:
parent
ef14d2f0a9
commit
c7238bec91
1 changed files with 15 additions and 11 deletions
26
gpgtool
26
gpgtool
|
@ -86,16 +86,13 @@ EOF
|
||||||
|
|
||||||
# Cleans up GPGtool. Clears the temp directory and closes the mounted volume.
|
# Cleans up GPGtool. Clears the temp directory and closes the mounted volume.
|
||||||
clear () {
|
clear () {
|
||||||
# Abort if not currently initialized:
|
_checkinit
|
||||||
[[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1
|
|
||||||
|
|
||||||
local tempdir="$(cat /tmp/gpgtool.tempdir)"
|
|
||||||
source "${tempdir}/env"
|
|
||||||
|
|
||||||
# Unmount device:
|
# Unmount device:
|
||||||
if [[ ! -z "${mountdev}" ]]; then
|
if [[ ! -z "${mountdev}" ]]; then
|
||||||
echo "Unmounting ${mountdev} …"
|
echo "Unmounting ${mountdev} …"
|
||||||
udisksctl unmount -b "${mountdev}"
|
udisksctl unmount -b "${mountdev}"
|
||||||
|
[[ $? != 0 ]] && echo "Error unmounting ${mountdev}, aborting …" && exit 1
|
||||||
fi
|
fi
|
||||||
# Lock device:
|
# Lock device:
|
||||||
if [[ "${dev}" != "${mountdev}" ]]; then
|
if [[ "${dev}" != "${mountdev}" ]]; then
|
||||||
|
@ -111,11 +108,7 @@ clear () {
|
||||||
|
|
||||||
# Lists all keys stored in the key path.
|
# Lists all keys stored in the key path.
|
||||||
list () {
|
list () {
|
||||||
# Abort if not currently initialized:
|
_checkinit
|
||||||
[[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1
|
|
||||||
|
|
||||||
local tempdir="$(cat /tmp/gpgtool.tempdir)"
|
|
||||||
source "${tempdir}/env"
|
|
||||||
|
|
||||||
# Abort if no keys found:
|
# Abort if no keys found:
|
||||||
[[ -z "$(ls ${keypath})" ]] &&
|
[[ -z "$(ls ${keypath})" ]] &&
|
||||||
|
@ -131,7 +124,7 @@ list () {
|
||||||
|
|
||||||
if [[ -z "$(ls -l ${_pkdir} | grep ^l)" ]]
|
if [[ -z "$(ls -l ${_pkdir} | grep ^l)" ]]
|
||||||
then
|
then
|
||||||
echo "No open keys. Try \`gpgtool open FINGERPRINT\`."
|
echo "No open keys. Try \`gpgtool open FINGERPRINT [FINGERPRINT …]\`."
|
||||||
else
|
else
|
||||||
echo "Currently Opened Keys:"
|
echo "Currently Opened Keys:"
|
||||||
ls -l ${_pkdir} | grep ^l | awk {'print $NF'}
|
ls -l ${_pkdir} | grep ^l | awk {'print $NF'}
|
||||||
|
@ -143,6 +136,17 @@ usage () {
|
||||||
echo FIXXME
|
echo FIXXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Abort if not currently initialized, otherwise load state.
|
||||||
|
_checkinit () {
|
||||||
|
[[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1
|
||||||
|
|
||||||
|
tempdir="$(cat /tmp/gpgtool.tempdir)"
|
||||||
|
|
||||||
|
[[ ! -f "${tempdir}/env" ]] && \
|
||||||
|
echo "State information missing. Try \`gpgtool clear && gpgtool init\`. Aborting …" && exit 1
|
||||||
|
source "${tempdir}/env"
|
||||||
|
}
|
||||||
|
|
||||||
# Abort for missing dependencies:
|
# Abort for missing dependencies:
|
||||||
for dep in ${_dependencies}; do
|
for dep in ${_dependencies}; do
|
||||||
if ! command -v ${dep} >/dev/null 2>&1; then
|
if ! command -v ${dep} >/dev/null 2>&1; then
|
||||||
|
|
Loading…
Reference in a new issue