LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Bedrock Linux
User Name
Password
Bedrock Linux This forum is for the discussion of Bedrock Linux.

Notices


Reply
  Search this Thread
Old 11-06-2022, 03:03 AM   #1
ParzivalWolfram
LQ Newbie
 
Registered: Nov 2022
Posts: 3

Rep: Reputation: 0
Preferred/best method of interacting with Bedrock from other programs?


I'm looking to write some scripts to handle various situations I keep finding myself in (Steam/Proton/Wine issues, recursive path issues with bedrock, etc) and was wondering if there was a preferred method of interacting with Bedrock so I can write my scripts. Generally speaking, parsing human-readable program output isn't a good way to do things, but is that the only option I would have in this situation for things like strata and program detection?

Last edited by ParzivalWolfram; 11-06-2022 at 03:20 AM.
 
Old 11-06-2022, 04:23 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,923

Rep: Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319
Hi. I don't really understand what do you mean by that. You can use any text editor (your preferred one) to modify config files and write scripts.
 
Old 11-06-2022, 05:12 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,137

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
Bedrock is a special case. Better to have left the thread on the zero reply auto-bump list.
 
1 members found this post helpful.
Old 11-06-2022, 06:52 AM   #4
ParadigmComplex
Bedrock Linux Founder
 
Registered: Feb 2016
Distribution: Bedrock Linux
Posts: 179

Rep: Reputation: Disabled
Quote:
Originally Posted by ParzivalWolfram View Post
I'm looking to write some scripts to handle various situations I keep finding myself in (Steam/Proton/Wine issues, recursive path issues with bedrock, etc) and was wondering if there was a preferred method of interacting with Bedrock so I can write my scripts.
Can you give a more concrete, detailed list of what you're after? It's not obvious to me what you interactions you'd automate with Bedrock for Steam/Proton/WINE issues, and recursive path issues sound like a user error.

Quote:
Originally Posted by ParzivalWolfram View Post
Generally speaking, parsing human-readable program output isn't a good way to do things, but is that the only option I would have in this situation for things like strata and program detection?
I can imagine non-Bedrock cases where this is an issue, but with the Bedrock context it's again not obvious to me what you're referring to here. Most Bedrock command output are written explicitly with automation in mind. They either return non-zero on error or terse, structured, trivially machine parseable output on success.

Last edited by ParadigmComplex; 11-06-2022 at 07:22 AM.
 
Old 11-06-2022, 12:47 PM   #5
ParzivalWolfram
LQ Newbie
 
Registered: Nov 2022
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ParadigmComplex View Post
Can you give a more concrete, detailed list of what you're after? It's not obvious to me what you interactions you'd automate with Bedrock for Steam/Proton/WINE issues, and recursive path issues sound like a user error.
Apologies, I should've explained better. I'm looking to be able to detect what strata are installed and enabled, and search those strata for programs as needed (at current, mainly Wine and/or Steam, but this may change in future.)

Additionally, the /bedrock folder presents a small issue with trying to search for things from the root of a stratum, as things like Python's `os.walk` will get stuck due to how it's structured, and `find` will continuously complain about the folder as well for minutes at a time before continuing.

Last edited by ParzivalWolfram; 11-06-2022 at 01:13 PM.
 
Old 11-06-2022, 06:59 PM   #6
ParadigmComplex
Bedrock Linux Founder
 
Registered: Feb 2016
Distribution: Bedrock Linux
Posts: 179

Rep: Reputation: Disabled
asdfasdf
Quote:
Originally Posted by ParzivalWolfram View Post
Apologies, I should've explained better.
No worries

Quote:
Originally Posted by ParzivalWolfram View Post
I'm looking to be able to detect what strata are installed and enabled
The expected user-facing solution to this is `brl list`. The output is intended to be easily machine parsable. See `brl list --help`; it has flags for things like enabled vs not enabled vs both. In theory it's possible to bypass it and directly read what `brl` is reading, but there's no guarantee that that will be maintained in future updates; the "stable API" is `brl`.

Quote:
Originally Posted by ParzivalWolfram View Post
and search those strata for programs as needed (at current, mainly Wine and/or Steam, but this may change in future.)
I'm not exactly sure what you're after here, but here's a scattershot attempt that might hit it:
  • If you only care which stratum provides a given command in the current context, `brl which` is what you're interested in. (It can also help with things other than binaries, like `brl which <pid>` will tell you which stratum provides a given running process).
  • If you're interested in not necessarily commands, but rather packages, Bedrock provides a Package Manager Manager (`pmm`) utility. Its user interface is highly configurable and so it's hard to provide a specific recommendation without knowing your preferred setup. See `pmm --help`.
  • If you want a list of all strata that could provide a given command, Bedrock does not currently provide a specific solution, but you could script something like:

    Code:
    #!/bin/sh
    command="${1}"
    echo "Strata which provide ${command}:"
    for stratum in $(brl list); do
    	strat -r "${stratum}" /bedrock/libexec/busybox sh -c "command -v \"${command}\" >/dev/null 2>&1" && echo "${stratum}"
    done
    where:
    • `brl list` lists the currently enabled, non-hidden strata.
    • `strat -r` runs something restricted to that stratum, i.e. it won't see commands available from other strata
    • `/bedrock/libexec/busybox` is Bedrock's provided busybox instance that's available from all strata for automation like this, rather than relying on the assumption a given stratum have things like a shell
    • `/bedrock/libexec/busybox sh` is busybox's shell
    • `command -v` is a way to ask a shell if a command is available in the `$PATH`

    Feel free to tweak as needed for your use case or use it as inspiration for something completely different.

Quote:
Originally Posted by ParzivalWolfram View Post
Additionally, the /bedrock folder presents a small issue with trying to search for things from the root of a stratum, as things like Python's `os.walk` will get stuck due to how it's structured, and `find` will continuously complain about the folder as well for minutes at a time before continuing.
Gotcha. Yes, there is recursion in `/bedrock/strata/<stratum>/bedrock` that could result in a much longer walk than should really be necessary. AFAIK it is limited to one level of recursion and will bottom out; Python's `os.walk` shouldn't get stuck indefinitely, but I certainly understand if you became impatient with it in your tests and ctrl-c'd it out. `find` detects this and will skip some of the redundancy.

In Bedrock Linux 0.7, there isn't a particularly great solution if you need to scan all of `/bedrock/strata` for something. The obvious solutions to me are to just wait it out, or to tell the walking software to skip the redundancy with something like `find`'s `-prune` flag or maybe something like this for os.walk. Another option may be to loop over the strata, `strat`'ing into each, then doing the search operation while pruning `/bedrock`. I recognize none of these are particularly great.

The architecture plans for the future Bedrock Linux 0.8 will probably resolve the recursion concern here such that this won't be an issue then, but it'll be a while before that's available.

Additionally, you may care to note that (in the current Bedrock Linux 0.7) /bedrock/cross is a virtual directory, similar to /proc or /sys. Those files aren't "real" and you may or may not care about them depending on why you're scanning /bedrock.
 
Old 11-07-2022, 05:47 AM   #7
ParzivalWolfram
LQ Newbie
 
Registered: Nov 2022
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ParadigmComplex View Post
In Bedrock Linux 0.7, there isn't a particularly great solution if you need to scan all of `/bedrock/strata` for something. The obvious solutions to me are to just wait it out, or to tell the walking software to skip the redundancy with something like `find`'s `-prune` flag or maybe something like this for os.walk. Another option may be to loop over the strata, `strat`'ing into each, then doing the search operation while pruning `/bedrock`. I recognize none of these are particularly great.
find tends to be rather finicky when using it from any scripts that aren't shell scripts. As an example, this call to subprocess.run:

Code:
find_output = run(['find','/bedrock/strata/'+strataIn,'-name','/bedrock','-prune','-o','-mount','-name',nameIn,extraFlags], capture_output = True)
Per documentation, this should work, however, find fails to parse the command (as returned by subprocess.run, using a stratum on my machine and wine as an example file):

Code:
CompletedProcess(args=['find', '/bedrock/strata/debian-bullseye', '-name', '/bedrock', '-prune', '-o', '-mount', '-name', 'wine', ' '], returncode=1, stdout=b'', stderr=b"find: paths must precede expression: ` '\n")
The Python solution proposed for os.walk cuts down search time by approximately 60 seconds on an NVMe SSD, in my tests.
 
Old 04-20-2023, 01:33 AM   #8
Millie111
LQ Newbie
 
Registered: Apr 2023
Location: Spain
Posts: 2

Rep: Reputation: 0
Thanks for sharing us a piece of great information that is actually helpful
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bedrock: bedrock poki remains on UTC no matter what jr_bob_dobbs Bedrock Linux 5 09-03-2019 05:10 AM
[SOLVED] bedrock not using brsh.conf, dropped to bedrock's /bin/sh Siljrath Linux - Distributions 2 08-25-2014 05:47 AM
Want to know preferred method of Slackware 13 installation, CD or DVD MonkfishAlchemist Slackware - Installation 4 02-16-2010 02:08 PM
Preferred method to deploy RHEL driver for new device nickolais Red Hat 2 01-22-2009 05:15 PM
How does the 64 bit version handle interacting with 32 bit programs? purelithium Mandriva 1 11-13-2005 05:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Bedrock Linux

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration