Compare commits

...

2 Commits

9 changed files with 76 additions and 10 deletions

View File

@ -34,14 +34,18 @@ import UnliftIO.Environment
main :: IO () main :: IO ()
main = runSimpleApp $ do main = runSimpleApp $ do
r <- getMonitorName
args <- getArgs args <- getArgs
pre <- maybe [] (\n -> ["-m", T.unpack n]) <$> getMonitorName let allArgs = maybe [] (\n -> ["-m", T.unpack n] ++ args) r
exitWith =<< proc "/usr/bin/rofi" (pre ++ args) runProcess c <- proc "/usr/bin/rofi" allArgs 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 $ withOpenDisplay $ \dpy -> do getMonitorName = liftIO $ 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
@ -93,10 +97,3 @@ 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,6 +1,7 @@
[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}

5
scripts/gpg Executable file
View File

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

30
scripts/mount.veracrypt Executable file
View File

@ -0,0 +1,30 @@
#! /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

5
scripts/pass Executable file
View File

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

14
scripts/umount.veracrypt Executable file
View File

@ -0,0 +1,14 @@
#! /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

14
scripts/with_gpg_mount Executable file
View File

@ -0,0 +1,14 @@
#! /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