Getting mega-cmd to work (custom jail, pkg app and user permissions)

maehsi

Cadet
Joined
Oct 15, 2023
Messages
6
Hello everyone,
I hope I searched enough, but so far I have not found a solution to my issue. I am trying to get my most important files synced to MEGA cloud. I hoped to use the cmd tool provided by MEGA for this, as it works fine on my GhostBSD laptop. However, I am not getting anywhere because of users and permissions and possibly the megacmd package not being the best piece of software. It doesn't create a user when installed, I think it's not even set up as a service. Just an application with a command.
What I did so far was creating the jail, getting megacmd to install, even getting it to work. But the user executing the command is root, and I don't think I can let the jail-root user have access to my TrueNAS storage. So I made a "mega" user, added that one to operator and wheel groups. Now I can do:
Code:
su -m mega -c mega-sync

and am getting
Code:
root@megasyncjail:~ # su -m mega -c mega-sync
[Initiating MEGAcmd server in background. Log: /root/.megaCmd/megacmdserver.log]
Another instance of MEGAcmd Server is running. Execute with --skip-lock-check to force running (NOT RECOMMENDED)
Unable to connect to service: error=2
Please ensure MEGAcmdServer is running
Failed to create socket for registering for state changes

Any ideas? Am I approaching my goal from the overall wrong direction or is this feasible?
Just FYI on my GhostBSD I run
Code:
mega-sync
every startup without root privileges or anything and it just works.
 
Joined
Oct 22, 2019
Messages
3,641
Just FYI on my GhostBSD I run
What about testing if it works by first switching users, and then running it the same?

Code:
su - mega
mega-sync


Where did you find it for FreeBSD? There is no port of it, nor does MEGA's website have any such download.

Nevermind. My eyes suck.
 
Last edited:

maehsi

Cadet
Joined
Oct 15, 2023
Messages
6
What about testing if it works by first switching users, and then running it the same?
how do I switch the user in a Truenas jail? To be honest, I have never done this with the command line, is it just the same as in FreeBSD?
Where did you find it for FreeBSD? There is no port of it, nor does MEGA's website have any such download.
Code:
pkg install megacmd

just worked. Not sure if I found it in the GhostBSD package manager UI or somewhere on the internet. Not the package itself but the fact it's just in the repositories.
 

maehsi

Cadet
Joined
Oct 15, 2023
Messages
6
how do I switch the user in a Truenas jail? To be honest, I have never done this with the command line, is it just the same as in FreeBSD?
alright, I found out how to do that and it even works. Now my only problem seems to be that my in-jail "mega" user has UID GID 1001, which is already used
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
You can use vipw and vi /etc/group to change the UID and GID.
 
Joined
Oct 22, 2019
Messages
3,641
how do I switch the user in a Truenas jail?
It was in my codeblock example. :wink:



Now my only problem seems to be that my in-jail "mega" user has UID GID 1001, which is already used
What are you trying to accomplish? Is that necessarily bad for your use of MEGAsync in the jail? Do you want the user "mega" in the jail to match the UID of a different TrueNAS host user, such as "1000"?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
@winnielinnie


Interesting ... seems to be a "Linux" project and source, yet compile with minimal changes on FreeBSD, too. Good work!

 
Joined
Oct 22, 2019
Messages
3,641

I searched for "mega", and my eyes skipped over "megacmd".

You know why? Because TO THIS DAY they still have that stupid insect crawling at the top of the screen, which gives me massive anxiety. I. HATE. BUGS. :mad::mad::mad: (And I'm not referring to the software kind...)

notbug.gif
 

maehsi

Cadet
Joined
Oct 15, 2023
Messages
6
What are you trying to accomplish? Is that necessarily bad for your use of MEGAsync in the jail? Do you want the user "mega" in the jail to match the UID of a different TrueNAS host user, such as "1000"?
I'd like it to work similarly to syncthing. This means I need to set up a mountpoint for the jail and have a user with fitting UID that has at least read, maybe write permissions to some of my storage. For the syncthing jail this was done fairly easy by entering the jail shell, typing
Code:
id syncthing

and thus getting the UID of the syncthing user that was automatically created when installing that plugin/jail. Afterwards I could add that user with the correct UID in the Truenas Accounts / Users UI.

So this morning I couldn't get into the shell of the jail anymore anyway, so I decided to start again. This is what I did so far:
  • Create Jail
  • Create mountpoint for jail
  • in jail:
    Code:
    pkg install sudo
  • create 'mega' user with UID not already used in TrueNAS
  • out of jail: create 'mega' user with the same UID in TrueNAS, manage permissions where I want them
  • in jail again: add that user to sudoers file
  • switch to mega user
  • install megacmd as mega user
  • start megacmd
  • try to sync, get error 'invalid argument'
  • Code:
    pkg install dbus
  • do
    Code:
    dbus-uuidgen > /etc/machine-id
  • try to sync again --> it works
Now all that's left is:
  1. Getting the jail to autostart with TrueNAS
  2. Getting the
    Code:
    mega-sync
    command to execute as 'mega' user upon jail startup
 

maehsi

Cadet
Joined
Oct 15, 2023
Messages
6
So far I could only achieve this last part by scheduling
Code:
iocage exec -U <jail-username> <jailname> mega-sync

to run daily. I would have preferred an init command but even the 'Post init' setting is before the services start so I expect mega-cmd to just hit an error.
 

maehsi

Cadet
Joined
Oct 15, 2023
Messages
6
I seem to have achieved everything I wanted to. The sync initiation upon Truenas boot is implemented by "Init Script" (Set to Command, Timeout=500, Post Init) with the following command:
Code:
iocage exec -f -U <jailuser> <jail> mega-sync
 
Top