style fixes

This commit is contained in:
alterNERDtive 2022-07-19 13:05:58 +02:00
parent fe314c0857
commit 4e45959e25
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1

38
gpgtool
View file

@ -11,10 +11,12 @@ init () {
local keypath
# Check if already initialized:
if [[ -f "${_tempdir}" ]]; then
if [[ -f "${_tempdir}" ]]
then
local dir="$(cat ${_tempdir})"
echo "GPGtool already initialized at ${dir}."
if [[ -f "${dir}/env" ]]; then
if [[ -f "${dir}/env" ]]
then
source "${dir}/env"
[[ ! -z "${dev}" ]] && echo -e "\tdevice: ${dev}"
[[ ! -z "${mountdev}" ]] && echo -e "\tmapped device: ${mountdev}"
@ -24,7 +26,8 @@ init () {
fi
zparseopts -A opts -D -E -- d: p: -device: -path:
for opt in "${(@k)opts}"; do
for opt in "${(@k)opts}"
do
case $opt in
-d|--device)
dev=$opts[$opt];
@ -42,7 +45,8 @@ init () {
[[ -z "${keypath}" ]] && keypath=${GPGTOOLKEYPATH}
# Unlock device:
if [[ ! -z "${dev}" ]] && udisksctl info -b ${dev} | grep -q org.freedesktop.UDisks2.Encrypted; then
if [[ ! -z "${dev}" ]] && udisksctl info -b ${dev} | grep -q org.freedesktop.UDisks2.Encrypted
then
echo "Unlocking device ${dev} …"
local mountdev=$(udisksctl unlock -b "${dev}")
[[ $? != 0 ]] && echo "Error unlocking device ${dev}, aborting …" && exit 1
@ -53,10 +57,12 @@ init () {
# Mount device:
[[ -z ${mountdev} ]] && mountdev=${dev}
if [[ ! -z ${mountdev} ]]; then
if [[ ! -z ${mountdev} ]]
then
echo "Mounting device ${mountdev} …"
mountpath=$(udisksctl mount -b "${mountdev}")
if [[ $? != 0 ]]; then
if [[ $? != 0 ]]
then
echo "Error mounting device ${mount}, aborting …"
[[ "${mountdev}" != "${dev}" ]] && udisksctl lock -b ${dev}
exit 1
@ -93,13 +99,15 @@ clear () {
_checkinit
# Unmount device:
if [[ ! -z "${mountdev}" ]]; then
if [[ ! -z "${mountdev}" ]]
then
echo "Unmounting ${mountdev} …"
udisksctl unmount -b "${mountdev}"
[[ $? != 0 ]] && echo "Error unmounting ${mountdev}, aborting …" && exit 1
fi
# Lock device:
if [[ "${dev}" != "${mountdev}" ]]; then
if [[ "${dev}" != "${mountdev}" ]]
then
echo "Locking ${dev} …"
udisksctl lock -b "${dev}"
fi
@ -120,9 +128,10 @@ list () {
echo -e "Key Fingerprint\t\t\t\t\tDescription"
perl -E 'say "-" x 82'
for key in $(ls ${keypath} | sort -k 1.9 | grep -v old)
for key in $(ls ${keypath})
do
echo -e "${key}\t$(cat ${keypath}/${key}/info)"
echo -en "${key}\t"
[[ -f "${keypath}/${key}/info" ]] && echo "$(cat ${keypath}/${key}/info)" || echo ""
done
echo
@ -152,8 +161,10 @@ _checkinit () {
}
# Abort for missing dependencies:
for dep in ${_dependencies}; do
if ! command -v ${dep} >/dev/null 2>&1; then
for dep in ${_dependencies}
do
if ! command -v ${dep} >/dev/null 2>&1
then
[[ -z "${deps}" ]] && deps=${dep} || deps="${deps}, ${dep}"
fi
done
@ -166,7 +177,8 @@ done
[[ "$1" =~ "(-h|--help|help)" ]] && usage && exit 0
# Source config file:
for dir in "$(dirname $0)" "${HOME}/.config/gpgtool" "${XDG_CONFIG_HOME}"; do
for dir in "$(dirname $0)" "${HOME}/.config/gpgtool" "${XDG_CONFIG_HOME}"
do
[[ -f "${dir}/gpgtool.conf" ]] && source "${dir}/gpgtool.conf"
done