You are not logged in.

#21 2020-11-22 18:32:08

malm
jgmenu developer
Registered: 2016-10-13
Posts: 739
Website

Re: Can you help me make a pipemenu to add to menu?

These two sites by Dylan Araps can be quite useful:

pure bash bible
pure sh bible

Offline

#22 2020-11-22 18:58:19

schwim
Member
From: Coastal VA, Murica
Registered: 2015-09-29
Posts: 342
Website

Re: Can you help me make a pipemenu to add to menu?

Ok, so I've outsmarted myself.  This works conditionally:

#!/bin/bash

for u in $HOME/Remote/SSHFS/*
do
  if [ -d $u ]; then
    basename "$u" >/dev/null
	acct="$(basename -- $u)"
	
	IFS=- read -r left right <<< "$acct"
	if mountpoint "${HOME}/Remote/SSHFS/${acct}" >/dev/null; then
		printf '%b\n' "unmount ${right},fusermount -u /home/schwim/Remote/${right}"
	else
		printf '%b\n' "mount ${right},sshfs -o workaround=rename $left@$right:/home/$left /home/schwim/Remote/SSHFS/${acct}"
	fi

  fi
done

The condition being, as long as the remote mount point is /home/$acctname for:

sshfs -o workaround=rename $left@$right:/home/$left /home/schwim/Remote/SSHFS

The issue is that not all of my mount points follow that logical account path.  Some are /var/www/acct, etc.

So I'm back to hardcoding the entries so I can pass the remote path to the mount command.

I could do this with a config file in the Remote directory that would contain all the necessary information needed for the mount command.  Is there a smoother way of handling this that I'm missing?  If not,  what would be the best way of passing this info to the bash script?


Schw.im! A social site with an identity crisis.

Offline

#23 2020-11-22 19:23:37

malm
jgmenu developer
Registered: 2016-10-13
Posts: 739
Website

Re: Can you help me make a pipemenu to add to menu?

If you’re okay, I’ll step away from this now. It’s starting to get a bit complex smile

You’ll have to strike a balance between how many cases you want to handle vs how much time you spend on it.

Copy+paste the for loop to deal with each case would be dirty, but simple.

Might be able to wrap current for loop in an another for loop which covers the different paths/accounts.

Or write all paths/accounts to a cache file and the read it line by line.

Try to really thing it through and aim for a simple solution. Clean and simple code where you can.

Offline

#24 2020-11-22 19:26:51

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,755

Re: Can you help me make a pipemenu to add to menu?

malm wrote:

Or write all paths/accounts to a cache file and the read it line by line.

example reader

#!/bin/bash

while read -r p; do
  echo "$p"
done <data.txt

example data.txt

some/info/here
some other info here
and here

Last edited by brontosaurusrex (2020-11-22 19:27:21)

Offline

#25 2020-11-22 20:21:13

schwim
Member
From: Coastal VA, Murica
Registered: 2015-09-29
Posts: 342
Website

Re: Can you help me make a pipemenu to add to menu?

brontosaurusrex wrote:
malm wrote:

Or write all paths/accounts to a cache file and the read it line by line.

example reader

#!/bin/bash

while read -r p; do
  echo "$p"
done <data.txt

example data.txt

some/info/here
some other info here
and here

I apologize for my density but could you explain how this would pertain to my needs?  I don't quite understand how I would make this example work for me.

{EDIT}

It seems it would make some sense to have the bash script read a file with the important information for each file system, then apply those variables during the menu entry and mount command building.

Should I be creating a single file with each domain's information in it as variables inside an array of some sort?

Last edited by schwim (2020-11-22 21:34:30)


Schw.im! A social site with an identity crisis.

Offline

#26 2020-11-23 09:35:17

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,755

Re: Can you help me make a pipemenu to add to menu?

What exactly is a data needed for single connection? An example?

Offline

#27 2020-11-23 15:04:00

schwim
Member
From: Coastal VA, Murica
Registered: 2015-09-29
Posts: 342
Website

Re: Can you help me make a pipemenu to add to menu?

brontosaurusrex wrote:

What exactly is a data needed for single connection? An example?

So far as I can tell, these are the only variables that I need to use.

host: schwim.net
user: schwim
local dir: /home/schwim/schwim.net
remote dir: /var/www/client1

Last edited by schwim (2020-11-23 15:08:31)


Schw.im! A social site with an identity crisis.

Offline

#28 2020-11-23 16:55:29

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,755

Re: Can you help me make a pipemenu to add to menu?

I'd probably try with an associative array, where key would be your label (server1) and value would be the entire command needed (sshfs + all the data needed) - unlike variables one should be able to expand an array value directly (without any evals).

In this direction

#!/bin/bash

# an array here
declare -A exe
exe=(
["serverOne"]="echo woot" 
["job"]="sleep 3" 
["myserv"]="neofetch" 
)

# this is the exe
${exe[serverOne]} 
${exe[job]} 
${exe[myserv]} 

p.s. Arrays in bash are a world of pain (only my experience), so be prepared to suffer.

Last edited by brontosaurusrex (2020-11-23 17:54:42)

Offline

#29 2020-11-24 01:17:05

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,666
Website

Re: Can you help me make a pipemenu to add to menu?

damo wrote:

"menuItem" is a variable used by BL and sourced from /usr/lib/bunsen/common/bl-includes.

You should have seen this in the existing BL pipemenus.

There are also some functions for jgmenu in the same file:
jgmenuItem
jgmenuSeparator
jgmenuSubmenu
jgmenuEnd

If you're creating a jgmenu pipe menu from scratch they can save you some work (but you seem to be there already).
You can see some examples of usage in /usr/bin/bl-scrot-pipemenu


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Online

#30 2020-11-24 01:32:00

schwim
Member
From: Coastal VA, Murica
Registered: 2015-09-29
Posts: 342
Website

Re: Can you help me make a pipemenu to add to menu?

Would something like this make sense?

# an array here
declare -A loop
loop=(
    ["serverOne"][domain]="domain.com"
    ["serverOne"][user]="bobthebuilder"
    ["serverOne"]["local"]="/home/schwim/Remote/SSHFS/domain.com" 
    ["serverOne"]["remote"]="/var/www/client1" 

    ["serverTwo"][domain]="anotherdomain.com"
    ["serverTwo"][user]="dougthedestroyer"
    ["serverTwo"]["local"]="/home/schwim/Remote/SSHFS/anotherdomain.com" 
    ["serverTwo"]["remote"]="/home/doug/www" 
)

?  Does bash work this way?  If this is feasible, how might I go about looping through that array in the script to get to the important bits?


Schw.im! A social site with an identity crisis.

Offline

#31 2020-11-24 10:50:54

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,755

Re: Can you help me make a pipemenu to add to menu?

^Not a valid bash array of any sort. https://www.shellcheck.net/
I'am out as well.

Last edited by brontosaurusrex (2020-11-24 10:52:09)

Offline

#32 2020-11-24 14:49:35

schwim
Member
From: Coastal VA, Murica
Registered: 2015-09-29
Posts: 342
Website

Re: Can you help me make a pipemenu to add to menu?

Thanks guys, I'll continue my quest for help elsewhere.  Take care and thanks again!


Schw.im! A social site with an identity crisis.

Offline

Board footer

Powered by FluxBB