You are not logged in.
Hello there everyone!
I mount client web sites via SSHFS. I use two simple bash files to mount and dismount these filesystems. I do this for quite a few domains and I mount and dismount in the terminal.
cd .scripts
./mount_website1.com
unmount_website2.com
What I started thinking after playing around in /usr/bin, however, is that I might be able to do this via a pipemenu file for jgmenu. What I'm hoping is that the pipemenu can detect whether a file system is mounted, if it isn't, offer me the mount option for that website and if it is, offer the unmount option. I would like to do this for all required websites.
My thinking is that I might be able to look into a /home/schwim/remote/website1.com and if there are no files, the remote filesystem has not been mounted and should show the menu option to run /home/schwim/.scripts/mount_website1.com. If files are found, show the menu option to unmount it.
I figured I could just duplicate these ifs from website1.com and ctrl+v them for each additional website.
The menu entries I'd like added would be:
- Remote FS
----Website1.com - Mount
----Website2.com - Unmount
----Website3.com - Mount
ETC.
Could someone help me with this? I know nearly nothing about bash and the pipemenu files I'm looking at are a bit confusing to me, I'm unable to decipher anything to a point to be able to muddle my way through this on my own.
Thanks for your time!
Schw.im! A social site with an identity crisis.
Offline
An example test.csv could be
woot, geany
waat, thunar
weet, galculator
and one could run this as
cat test.csv | jgmenu --simple
In your case you would replace geany and thunar and galculator with links to your scripts.
/me is by no means jgmenu expert, but this example^ should be simple enough to construct furter built upon with some additional reading.
Last edited by brontosaurusrex (2020-11-21 16:08:49)
Offline
Is there a command to test if a website is mounted?
If so, writing a shell script for a menu will be easy.
Offline
Is there a command to test if a website is mounted?
If so, writing a shell script for a menu will be easy.
Would this be sufficient to work in the script?
schwim@schwim-vm-bll:~/Remote$ mountpoint ~/Remote/bhmbackflow.com ; echo $?
/home/schwim/Remote/bhmbackflow.com is not a mountpoint
1schwim@schwim-vm-bll:~$ cd .scripts
schwim@schwim-vm-bll:~/.scripts$ ./bhm_mountschwim@schwim-vm-bll:~/Remote$ mountpoint ~/Remote/bhmbackflow.com ; echo $?
/home/schwim/Remote/bhmbackflow.com is a mountpoint
0
schwim@schwim-vm-bll:~/Remote$
Schw.im! A social site with an identity crisis.
Offline
Would this work?
#!/bin/sh
urls="foo.com bar.com"
for u in ${urls}; do
if mountpoint "${HOME}/Remote/${u}"; then
printf '%b\n' "unmount ${u}"
elif
printf '%b\n' "mount ${u}"
fi
done
Just run it in the terminal first to check the output.
When happy do
./script.sh | jgmenu --simple
As a final step, you could wrap it like this to avoid having to do the piping in the terminal
#!/bin/sh
(
<code>
) | jgmenu --simple
Offline
Ok, so I've got the following in sshfs-pipemenu which is saved in ~/bin/X11:
#!/bin/bash
urls="air@aircooledaddiction.com bhm@bhmbackflow.com"
for u in ${urls}; do
IFS=@ read -r left right <<< "$u"
if mountpoint "${HOME}/Remote/${right}"; then
#printf '%b\n' "unmount ${u}"
menuItem "Unmount $right" "fusermount -u /home/schwim/Remote/$right"
else
#printf '%b\n' "mount ${u}"
menuItem "Mount $right" "sshfs -o workaround=rename $u:/home/bhm /home/schwim/Remote/$right"
fi
done
Then have called it in jgmenu:
Remote File Systems,^pipe(jgmenu_run ob --cmd="sshfs-pipemenu" --tag="bl-sshfs-pipemenu")
I can see remote file systems in jgmenu now but nothing shows when hovering over it. Can I save the file in ~/bin/Xll and have it picked up or do I need to save it to /usr/bin/X11 to get it to work? If I run the script in the terminal, although it doesn't understand the menuitem line, it does work properly in reading the directories and telling whether a filesystem is mounted or not.
Last edited by schwim (2020-11-22 13:45:27)
Schw.im! A social site with an identity crisis.
Offline
Ah. No need to produce XML output only to convert it back using "jgmenu_run ob". Just stick with the much simpler jgmenu CSV syntax.
So, there is no need to use 'menuItem'
Also, when you call the pipemenu, just do "Remote File Systems,^pipe(sshfs-pipemenu)"
Offline
Ah. No need to produce XML output only to convert it back using "jgmenu_run ob". Just stick with the much simpler jgmenu CSV syntax.
So, there is no need to use 'menuItem'
I don't understand what you mean by this, I'm looking at the existing bl pipe files and borrowing from that code for my needs. Could you provide an example based off of my attempt at this?
Current code:
#!/bin/bash
urls="air@aircooledaddiction.com bhm@bhmbackflow.com"
for u in ${urls}; do
IFS=@ read -r left right <<< "$u"
if mountpoint "${HOME}/Remote/${right}"; then
#printf '%b\n' "unmount ${u}"
menuItem "Unmount ${right}" "fusermount -u /home/schwim/Remote/${right}"
else
#printf '%b\n' "mount ${u}"
menuItem "Mount ${right}" "sshfs -o workaround=rename $u:/home/bhm /home/schwim/Remote/${right}"
fi
done
Schw.im! A social site with an identity crisis.
Offline
I think it would be like this.
Before running it as a pipemenu, just run "sshfs-pipemenu" from the terminal and make sure the output looks okay (paste here if unsure).
#!/bin/bash
urls="air@aircooledaddiction.com bhm@bhmbackflow.com"
for u in ${urls}; do
IFS=@ read -r left right <<< "$u"
if mountpoint "${HOME}/Remote/${right}"; then
printf '%b\n' "unmount ${right},fusermount -u /home/schwim/Remote/${right}"
else
printf '%b\n' "mount ${right},sshfs -o workaround=rename $u:/home/bhm /home/schwim/Remote/${right}"
fi
done
Offline
PS. Have a look at https://jgmenu.github.io/jgmenututorial.7.html#lesson4 to get your head around the jgmenu syntax. Lesson 4 should explain the printf lines in the script above.
Offline
{EDIT}
Ok, got the file working in jgmenu via the following entry:
Remote File Systems,^pipe(/home/schwim/bin/X11/sshfs-pipemenu)
But there's a problem:
Is there a way for me to suppress the output of mountpoint "${HOME}/Remote/${right} so that it doesn't show in the menu? If not, si there another way for me to check that won't provide an output?
Last edited by schwim (2020-11-22 15:36:03)
Schw.im! A social site with an identity crisis.
Offline
"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.
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
You should have seen this in the existing BL pipemenus.
I did, which was why I was trying to use it. The printf method is working for me as well, however.
The only issue I'm experiencing right now, however is that mountpoint is providing text that is showing up in the menu. The mount and unmount portion is working correctly, I just need to find a way to get the mountpoint check to not provide any text in the menu:
Schw.im! A social site with an identity crisis.
Offline
Add >/dev/null after the mountpoint command (just before the semicolon)
Offline
ok, everything's working fantastic so i'd like to make some changes
The way it's set up right now, I'll have to edit the script to reflect changes in the mounts I've got set up. I'm wondering if I can handle this automatically by the script.
If I named the directories in the Remote dir like air-aircooledaddiction.com which is the mount user and url separated by a dash then split that in the script, I would have all the info necessary to mount the drive.
To make it work though, I'd need to scan the Remote directory and have it build an array of existing directories found inside. Is there a way for me to do this in the bash script? Can I have it scan the remote dir and build an array of the dirs found inside?
Schw.im! A social site with an identity crisis.
Offline
Ok, I found this but it prints the entire path and not just the directory name and it also includes the parent dir with no subdir. Will continue googling:
for d in $(find /home/schwim/Remote -maxdepth 1 -type d)
do
#Do something, the directory is accessible with $d:
echo $d
done
schwim@schwim-vm-bll:~/bin/X11$ ./sshfs-pipemenu
/home/schwim/Remote
/home/schwim/Remote/bhmbackflow.com
/home/schwim/Remote/schwimserver3.com
/home/schwim/Remote/MEGA
/home/schwim/Remote/aircooledaddiction.com
/home/schwim/Remote/schwimserver2.com
schwim@schwim-vm-bll:~/bin/X11$
Last edited by schwim (2020-11-22 16:56:32)
Schw.im! A social site with an identity crisis.
Offline
The best shell approach is
for u in $HOME/Remote/*
do
# do stuff
done
If you only want to process directories, could you do a test like this:
for u in $HOME/Remote/*
do
if [ -d $u ]; then
# do stuff
fi
done
See `man test` for other options
Last edited by malm (2020-11-22 17:59:32)
Offline
The [ ] construct is just short hand for the command test. So you could do `test -d $u` instead.
You could also avoid the if-then-fi by simply doing
[ -d $u ] || continue
`A && B` means if command A is successful, execute command B
`A || B` means if command A is NOT successful, then do B
Offline
The best shell approach is
If you only want to process directories, could you do a test like this:
for u in $HOME/Remote/* do if [ -d $u ]; then # do stuff fi done
Is there a way to get $u to only contain the dir name and not the path to the directory?
For instance, aircooledaddiction.com instead of /home/schwim/remote/aircooledaddiction.com?
Schw.im! A social site with an identity crisis.
Offline
Use the command basename
Offline