Compare commits
1 Commits
9cad6fc050
...
dbus
| Author | SHA1 | Date | |
|---|---|---|---|
|
920eb49941
|
16
lib/args.nim
16
lib/args.nim
@@ -4,11 +4,11 @@ import os
|
|||||||
|
|
||||||
type Args* = object
|
type Args* = object
|
||||||
name*: Option[string]
|
name*: Option[string]
|
||||||
cmd*: Option[seq[string]]
|
cmd*: Option[string]
|
||||||
profile*: Option[string]
|
profile*: Option[string]
|
||||||
|
|
||||||
proc getCmd*(args: Args): seq[string] =
|
proc getCmd*(args: Args): string =
|
||||||
return args.cmd.get(@[getEnv("SHELL", "/bin/bash")])
|
return args.cmd.get(getEnv("SHELL", "/bin/bash"))
|
||||||
|
|
||||||
proc getProfile*(args: Args): string =
|
proc getProfile*(args: Args): string =
|
||||||
if args.profile.isSome:
|
if args.profile.isSome:
|
||||||
@@ -18,8 +18,8 @@ proc getProfile*(args: Args): string =
|
|||||||
|
|
||||||
proc parseOpt(args: var Args, key: string, value: string): bool =
|
proc parseOpt(args: var Args, key: string, value: string): bool =
|
||||||
case key
|
case key
|
||||||
of "name", "n":
|
of "command", "c":
|
||||||
args.name = some(value)
|
args.cmd = some(value)
|
||||||
of "profile", "p":
|
of "profile", "p":
|
||||||
args.profile = some(value)
|
args.profile = some(value)
|
||||||
else:
|
else:
|
||||||
@@ -30,7 +30,6 @@ proc parseOpt(args: var Args, key: string, value: string): bool =
|
|||||||
proc parseArgs*(): Option[Args] =
|
proc parseArgs*(): Option[Args] =
|
||||||
var p = initOptParser()
|
var p = initOptParser()
|
||||||
var args = Args()
|
var args = Args()
|
||||||
var command = newSeq[string]()
|
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
p.next()
|
p.next()
|
||||||
@@ -41,9 +40,6 @@ proc parseArgs*(): Option[Args] =
|
|||||||
echo "Invalid argument ", p.val
|
echo "Invalid argument ", p.val
|
||||||
return
|
return
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
command.add(p.key.string)
|
args.name = some(p.key.string)
|
||||||
|
|
||||||
if command.len > 0:
|
|
||||||
args.cmd = some(command)
|
|
||||||
|
|
||||||
return some(args)
|
return some(args)
|
||||||
@@ -10,10 +10,10 @@ type DbusProxy* = object
|
|||||||
socket*: string
|
socket*: string
|
||||||
args: seq[string]
|
args: seq[string]
|
||||||
|
|
||||||
proc exec*(proxy: DbusProxy): Process =
|
proc exec*(proxy: var DbusProxy) =
|
||||||
# todo: start dbus proxy in bwrap
|
# todo: start dbus proxy in bwrap
|
||||||
# todo: pass arguments as fd
|
# todo: pass arguments as fd
|
||||||
startProcess("xdg-dbus-proxy", args = proxy.args,
|
proxy.process = startProcess("xdg-dbus-proxy", args = proxy.args,
|
||||||
options = {poEchoCmd, poParentStreams, poUsePath})
|
options = {poEchoCmd, poParentStreams, poUsePath})
|
||||||
|
|
||||||
proc startDBusProxy*(config: Config, hostname: string): DbusProxy =
|
proc startDBusProxy*(config: Config, hostname: string): DbusProxy =
|
||||||
@@ -49,6 +49,6 @@ proc startDBusProxy*(config: Config, hostname: string): DbusProxy =
|
|||||||
|
|
||||||
proxy.args.add("--filter")
|
proxy.args.add("--filter")
|
||||||
proxy.args.add("--log")
|
proxy.args.add("--log")
|
||||||
proxy.process = proxy.exec()
|
proxy.exec()
|
||||||
|
|
||||||
proxy
|
proxy
|
||||||
3
main.nim
3
main.nim
@@ -5,10 +5,9 @@ import random
|
|||||||
|
|
||||||
proc main(): int =
|
proc main(): int =
|
||||||
let args = parseArgs()
|
let args = parseArgs()
|
||||||
echo args
|
|
||||||
|
|
||||||
if args.isNone:
|
if args.isNone:
|
||||||
echo "Usage: bwshell --name=sandbox_name --profile=profile <sandbox_cmd>"
|
echo "Usage: bwshell --command=cmd --profile=profile <sandbox_name>"
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
randomize()
|
randomize()
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "Usage: $0 <target_dir>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
check_dir() {
|
|
||||||
local dir=$1
|
|
||||||
local file
|
|
||||||
|
|
||||||
for application in "$dir/"*; do
|
|
||||||
file="$(basename "$application")"
|
|
||||||
|
|
||||||
sed "s/Exec=/Exec=bwrap --name='$file' --profile=gui /gi" "$application" > "$target/$file"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
dirs=("/usr/share/applications" "$HOME/.local/share/applications")
|
|
||||||
target="$1"
|
|
||||||
|
|
||||||
for dir in "${dirs[@]}"; do
|
|
||||||
check_dir "$dir"
|
|
||||||
done
|
|
||||||
Reference in New Issue
Block a user