Compare commits
2 Commits
04c430efc6
...
ae5de98e46
Author | SHA1 | Date |
---|---|---|
Nathan Dwarshuis | ae5de98e46 | |
Nathan Dwarshuis | a963be1421 |
17
app/rofi.hs
17
app/rofi.hs
|
@ -34,14 +34,18 @@ import UnliftIO.Environment
|
|||
|
||||
main :: IO ()
|
||||
main = runSimpleApp $ do
|
||||
r <- getMonitorName
|
||||
args <- getArgs
|
||||
pre <- maybe [] (\n -> ["-m", T.unpack n]) <$> getMonitorName
|
||||
exitWith =<< proc "/usr/bin/rofi" (pre ++ args) runProcess
|
||||
let allArgs = maybe [] (\n -> ["-m", T.unpack n] ++ args) r
|
||||
c <- proc "/usr/bin/rofi" allArgs runProcess
|
||||
exitWith c
|
||||
|
||||
data Coord = Coord Int Int deriving (Eq, Show)
|
||||
|
||||
-- TODO bracket this
|
||||
getMonitorName :: MonadIO m => m (Maybe T.Text)
|
||||
getMonitorName = liftIO $ withOpenDisplay $ \dpy -> do
|
||||
getMonitorName = liftIO $ do
|
||||
dpy <- openDisplay ""
|
||||
root <- rootWindow dpy $ defaultScreen dpy
|
||||
index <- getCurrentDesktopIndex dpy root
|
||||
viewports <- getDesktopViewports dpy root
|
||||
|
@ -93,10 +97,3 @@ getAtom32 dpy root str = do
|
|||
a <- internAtom dpy (T.unpack str) False
|
||||
p <- getWindowProperty32 dpy a root
|
||||
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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[Unit]
|
||||
Description=Mount veracrypt volume for %i
|
||||
|
||||
# TODO these scripts moved
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=%h/.bin/mount.veracrypt ${BW_NAME} ${VOLUME} ${MOUNTPOINT}
|
|
@ -0,0 +1,5 @@
|
|||
#! /bin/bash
|
||||
|
||||
## gpg (override): mount GNUPGHOME before executing
|
||||
|
||||
with_gpg_mount /usr/bin/gpg "$@"
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
#! /bin/bash
|
||||
|
||||
## pass (override): mount $GNUPGHOME before executing
|
||||
|
||||
with_gpg_mount /usr/bin/pass "$@"
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue