Compare commits

..

No commits in common. "ae5de98e46d63560afd791ca855232023801177f" and "04c430efc67623acce847874754bd0035cbb19a5" have entirely different histories.

9 changed files with 10 additions and 76 deletions

View File

@ -34,18 +34,14 @@ import UnliftIO.Environment
main :: IO () main :: IO ()
main = runSimpleApp $ do main = runSimpleApp $ do
r <- getMonitorName
args <- getArgs args <- getArgs
let allArgs = maybe [] (\n -> ["-m", T.unpack n] ++ args) r pre <- maybe [] (\n -> ["-m", T.unpack n]) <$> getMonitorName
c <- proc "/usr/bin/rofi" allArgs runProcess exitWith =<< proc "/usr/bin/rofi" (pre ++ args) runProcess
exitWith c
data Coord = Coord Int Int deriving (Eq, Show) data Coord = Coord Int Int deriving (Eq, Show)
-- TODO bracket this
getMonitorName :: MonadIO m => m (Maybe T.Text) getMonitorName :: MonadIO m => m (Maybe T.Text)
getMonitorName = liftIO $ do getMonitorName = liftIO $ withOpenDisplay $ \dpy -> do
dpy <- openDisplay ""
root <- rootWindow dpy $ defaultScreen dpy root <- rootWindow dpy $ defaultScreen dpy
index <- getCurrentDesktopIndex dpy root index <- getCurrentDesktopIndex dpy root
viewports <- getDesktopViewports dpy root viewports <- getDesktopViewports dpy root
@ -97,3 +93,10 @@ getAtom32 dpy root str = do
a <- internAtom dpy (T.unpack str) False a <- internAtom dpy (T.unpack str) False
p <- getWindowProperty32 dpy a root p <- getWindowProperty32 dpy a root
return $ maybe [] (fmap fromIntegral) p return $ maybe [] (fmap fromIntegral) p
withOpenDisplay :: MonadUnliftIO m => (Display -> m a) -> m a
withOpenDisplay = bracket (liftIO $ openDisplay "") cleanup
where
cleanup dpy = liftIO $ do
flush dpy
closeDisplay dpy

View File

@ -1,5 +0,0 @@
#! /bin/bash
## gpg (override): mount GNUPGHOME before executing
with_gpg_mount /usr/bin/gpg "$@"

View File

@ -1,7 +1,6 @@
[Unit] [Unit]
Description=Mount veracrypt volume for %i Description=Mount veracrypt volume for %i
# TODO these scripts moved
[Service] [Service]
Type=forking Type=forking
ExecStart=%h/.bin/mount.veracrypt ${BW_NAME} ${VOLUME} ${MOUNTPOINT} ExecStart=%h/.bin/mount.veracrypt ${BW_NAME} ${VOLUME} ${MOUNTPOINT}

View File

@ -1,30 +0,0 @@
#! /bin/bash
## mount a veracrypt volume
## NOTE this will need the DISPLAY variable in order to prompt for the bitwarden
## password
pwd=$(dbus-send --print-reply=literal --session \
--dest=org.rofi.bitwarden \
/bitwarden org.rofi.bitwarden.session.GetPassword \
string:"$1" | \
sed -e 's/^ *//g')
## the funny evals are here to expand any literal env variables that may be
## passed because systemd didn't expand them (yuck)
volume="$(eval echo "$2")"
mountpoint="$(eval echo "$3")"
if [[ "$pwd" == "" ]]; then
echo "Could not get bitwarden password"
exit 1
else
if /usr/bin/sudo /usr/bin/veracrypt \
--text --non-interactive --stdin \
"$volume" "$mountpoint" <<< "$pwd"; then
echo "Mounted $1"
else
echo "Failed to mount $1"
exit 1
fi
fi

View File

@ -1,5 +0,0 @@
#! /bin/bash
## pass (override): mount $GNUPGHOME before executing
with_gpg_mount /usr/bin/pass "$@"

View File

@ -1,14 +0,0 @@
#! /bin/bash
## unmount a veracrypt volume
## the funny evals are here to expand any literal env variables that may be
## passed because systemd didn't expand them (yuck)
mountpoint="$(eval echo "$1")"
if /usr/bin/sudo /usr/bin/veracrypt -d "$mountpoint"; then
echo "Unmounted $1"
else
echo "Failed to unmount $1"
exit 1
fi

View File

@ -1,14 +0,0 @@
#! /bin/bash
## with_gpg_mount: call a program after mounting GNUPGHOME using rofi
bin="$1"
shift
alias="gnupg"
if rofi-dev -c "$XDG_CONFIG_HOME/rofi/devices.dhall" -m "$alias"; then
"$bin" "$@"
else
echo "Could not mount $alias"
fi