# About porting MEGASync



## shuryanc (Apr 7, 2021)

Hi Community,

I want to try porting the latest version of MEGASync to FreeBSD (I know kqueue is needed).
So I start from compiling the source code but stucked in some steps.








						GitHub - shuryanc/MEGAsync-For-FreeBSD: Easy automated syncing between your computers and your MEGA Cloud Drive
					

Easy automated syncing between your computers and your MEGA Cloud Drive - GitHub - shuryanc/MEGAsync-For-FreeBSD: Easy automated syncing between your computers and your MEGA Cloud Drive




					github.com
				



My question is, may I know if anyone had successfully compiled the latest version of MEGASync?


----------



## eternal_noob (Apr 7, 2021)

shuryanc said:


> I want to try porting the latest version of MEGASync to FreeBSD


But the shell prompt suggests you are using GhostBSD.









						GhostBSD, pfSense, TrueNAS, and all other FreeBSD Derivatives
					

Questions about 'derivative FreeBSDs', like  GhostBSD DesktopBSD TrueNAS XigmaNAS OPNsense pfSense PacBSD BSD Router Project NomadBSD helloSystem  should be asked on the forums and/or mailing lists for these specific products. See below for links.  If you still think your questions should be...




					forums.freebsd.org


----------



## shuryanc (Apr 7, 2021)

eternal_noob said:


> But the shell prompt suggests you are using GhostBSD.
> 
> 
> 
> ...


From what I know, their base is the same (e.g. GhostBSD is adopting the Kernel from FreeBSD). GhostBSD tries to make FreeBSD to be easy to use. Could you provide some advise based on FreeBSD?


----------



## zirias@ (Apr 7, 2021)

There's an error in the configure script. Assuming this is generated by GNU autotools, you could try `autoreconf` from devel/autoconf-wrapper.


----------



## shuryanc (Apr 7, 2021)

Zirias said:


> There's an error in the configure script. Assuming this is generated by GNU autotools, you could try `autoreconf` from devel/autoconf-wrapper.


Thanks Zirias. Let me try and check which configure script causes the issue.


----------



## Menelkir (Apr 7, 2021)

Maybe creating a port for that will be better? Since you can deal with patches, path and all the stuff directly into the port Makefile instead of modifying megasync source tree.


----------



## zirias@ (Apr 7, 2021)

`autoreconf` will just attempt to re-generate the configure script from configure.ac, assuming this code _indeed_ uses GNU autotools.

But I agree, it's probably easier to start with creating a port right away. There's a helpful `USES=autoreconf` to handle that kind of breakage automatically.


----------



## richardtoohey2 (Apr 7, 2021)

You might find help here: https://docs.freebsd.org/en/books/porters-handbook/

There's also make versus gmake (it's all at that link, as is autoreconf).


----------



## Menelkir (Apr 8, 2021)

Here´s a Makefile that I´ve started, but I had too many chimichangas that i´ve stopped worked on it. At last you have the deps and everything else. It´ll need more things to be done (in the case of megasync, you´ll need the Makefile.freebsd) Change it to suit your needs.


```
# $FreeBSD$

PORTNAME=    megasync
DISTVERSION=    v4.4.0.0
DISTVERSIONSUFFIX=    _Linux
CATEGORIES=    net

MAINTAINER=    menelkir@itroll.org
COMMENT=    MEGA Cloud Drive client

LICENSE=    MEGA
LICENSE_NAME=   MEGA
LICENSE_FILE=    ${WRKSRC}/LICENCE.md
LICENSE_PERMS=  no-dist-sell

LIB_DEPENDS=    libcares.so:dns/c-ares \
        libcryptopp.so:security/cryptopp \
        libsodium.so:security/libsodium \
        libuv.so:devel/libuv \
        libQt5Svg.so:graphics/qt5-svg \
        libQt5X11Extras.so:x11/qt5-x11extras \
        libmediainfo.so:multimedia/libmediainfo \
        libraw.so:graphics/libraw \
        libpcre.so:devel/pcre

USES=        libtool sqlite:3 readline shebangfix ssl qmake qt:5

NO_CDROM=       Commercial users must seek permission from copyright holders.

USE_GITHUB=    yes
GH_ACCOUNT=    meganz
GH_PROJECT=    MEGAsync sdk:sdk
GH_SUBDIR=    sdk:sdk
GH_TAGNAME=    v3.7.3c:sdk

USE_LDCONFIG=    yes

MAKEFILE=    Makefile.freebsd

INSTALL_TARGET=    install-strip

SHEBANG_FILES=    src/configure

CXXFLAGS+=    `pkgconf --cflags-only-other libcryptopp`

.include <bsd.port.mk>
```


----------



## Misirca (Apr 8, 2021)

Unless you want some specific functionality with MEGAsync, remember `rclone` can mount and sync MEGA folders as well


----------



## Menelkir (Apr 8, 2021)

Misirca said:


> Unless you want some specific functionality with MEGAsync, remember `rclone` can mount and sync MEGA folders as well


Doesn´t work as expected for mega, it works at some point but there´s many other issues like timeout, lag, etc. Being there, done that.
Actually the best choices for sync with mega is:
net/megatools : Works fine, but have some issues like lag and you don´t have a proper daemon for that (you can use a cron and a script, of course).
net/megacmd : It´s the official mega solution, works exactly the same but without a fancy GUI like megasync. There´s a daemon that runs in background. Have is own issues like lag in different scenarios, etc.


----------



## Menelkir (Apr 20, 2021)

Any update on this? Maybe I can help if you're stuck in something.


----------



## shuryanc (Apr 26, 2021)

Menelkir said:


> Any update on this? Maybe I can help if you're stuck in something.


Was in some projects and only have time to check the code. But currently still find nothing that would cause the "configure" error on line 18231 (the configure files seems to be auto created by autoconf from the configure.ac file). My target is to get the source code to be complied, then should be able to make it in to ports.


----------



## shuryanc (Jan 9, 2022)

Stuck at this step during make -f Makefile, they are in some header files in /usr/local/include. But I am not sure how to continue.

```
ld: error: undefined symbol: av_log_set_level(int)
>>> referenced by freeimage.cpp:183 (mega/src/gfx/freeimage.cpp:183)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avformat_open_input
>>> referenced by freeimage.cpp:188 (mega/src/gfx/freeimage.cpp:188)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avformat_find_stream_info
>>> referenced by freeimage.cpp:197 (mega/src/gfx/freeimage.cpp:197)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avcodec_find_decoder
>>> referenced by freeimage.cpp:241 (mega/src/gfx/freeimage.cpp:241)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avcodec_alloc_context3
>>> referenced by freeimage.cpp:248 (mega/src/gfx/freeimage.cpp:248)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avcodec_parameters_to_context
>>> referenced by freeimage.cpp:250 (mega/src/gfx/freeimage.cpp:250)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: sws_getContext
>>> referenced by freeimage.cpp:265 (mega/src/gfx/freeimage.cpp:265)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avcodec_open2
>>> referenced by freeimage.cpp:276 (mega/src/gfx/freeimage.cpp:276)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_frame_alloc
>>> referenced by freeimage.cpp:283 (mega/src/gfx/freeimage.cpp:283)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))
>>> referenced by freeimage.cpp:286 (mega/src/gfx/freeimage.cpp:286)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_image_alloc
>>> referenced by freeimage.cpp:298 (mega/src/gfx/freeimage.cpp:298)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_get_time_base_q()
>>> referenced by freeimage.cpp:317 (mega/src/gfx/freeimage.cpp:317)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_rescale_q(long, AVRational, AVRational)
>>> referenced by freeimage.cpp:317 (mega/src/gfx/freeimage.cpp:317)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avformat_close_input
>>> referenced by freeimage.cpp:171 (mega/src/gfx/freeimage.cpp:171)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))
>>> referenced by freeimage.cpp:171 (mega/src/gfx/freeimage.cpp:171)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_seek_frame
>>> referenced by freeimage.cpp:323 (mega/src/gfx/freeimage.cpp:323)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_init_packet
>>> referenced by freeimage.cpp:330 (mega/src/gfx/freeimage.cpp:330)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_read_frame
>>> referenced by freeimage.cpp:339 (mega/src/gfx/freeimage.cpp:339)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avcodec_send_packet
>>> referenced by freeimage.cpp:343 (mega/src/gfx/freeimage.cpp:343)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: avcodec_receive_frame
>>> referenced by freeimage.cpp:349 (mega/src/gfx/freeimage.cpp:349)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: sws_scale
>>> referenced by freeimage.cpp:357 (mega/src/gfx/freeimage.cpp:357)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: undefined symbol: av_image_get_buffer_size
>>> referenced by freeimage.cpp:363 (mega/src/gfx/freeimage.cpp:363)
>>>               freeimage.o:(mega::GfxProcFreeImage::readbitmapFfmpeg(mega::FileAccess*, mega::LocalPath const&, int))

ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1
```


----------



## covacat (Jan 9, 2022)

looks like you need to link libavcodec (ffmpeg)


----------



## grahamperrin@ (Jan 9, 2022)

shuryanc said:


> … (I know kqueue is needed) …



Incidentally, are you aware of eventfd(2)?


----------



## shuryanc (Jan 10, 2022)

The problem is here. If I removed #include <libavutil/imgutils.h> or #include <libswscale/swscale.h>, a complaint of undeclared identifier related to these 2 headers will be displayed. But if I add them back, ld: error: undefined symbol appears despite the headers are already included. Any idea?


```
extern "C" {
#ifdef _WIN32
#pragma warning(disable:4996)
#pragma warning(push)
#pragma warning(disable:4242)
#pragma warning(disable:4244)
#endif
#include <libavutil/imgutils.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>
#include <libavutil/mathematics.h>
#include <libavutil/display.h>
#ifdef _WIN32
#pragma warning(pop)
#endif
}
```


----------



## covacat (Jan 10, 2022)

adding the #include is not sufficient, you have to add the library to the Makefile
-lavcodec and maybe others


----------



## shuryanc (Jan 10, 2022)

Thanks. Get it complied but with segmentation fault.
Will need to check the code again when I am available.


----------



## Menelkir (Jan 10, 2022)

shuryanc said:


> Thanks. Get it complied but with segmentation fault.
> Will need to check the code again when I am available.


Paste the error, maybe we can help with that.


----------



## shuryanc (Jan 10, 2022)

From the log, its most likely caused by the required library files are not in the path that the complied megasync needs. But despite this, the complied megasync is still strange since its size is 176MB.


----------



## Menelkir (Jan 10, 2022)

shuryanc said:


> From the log, its most likely caused by the required library files are not in the path that the complied megasync needs. But despite this, the complied megasync is still strange since its size is 176MB.


As far I've see the log, there's lots of dependencies missing such as multimedia/libmediainfo, devel/libuv, multimedia/libzen, and the list goes on. Are you sure all deps are there? Maybe the Arch Linux's AUR can help with that (configure options and dependencies). AUR also have a version without pdfium, which is probably the best option.


----------



## shuryanc (Jan 10, 2022)

Menelkir said:


> As far I've see the log, there's lots of dependencies missing such as multimedia/libmediainfo, devel/libuv, multimedia/libzen, and the list goes on. Are you sure all deps are there? Maybe the Arch Linux's AUR can help with that (configure options and dependencies). AUR also have a version without pdfium, which is probably the best option.


All dependencies are in the system, but the path are different.


----------



## Menelkir (Jan 10, 2022)

shuryanc said:


> All dependencies are in the system, but the path are different.


Are you using USES=localbase?


----------



## reddy (Jan 10, 2022)

Misirca said:


> Unless you want some specific functionality with MEGAsync, remember `rclone` can mount and sync MEGA folders as well





Menelkir said:


> Doesn´t work as expected for mega, it works at some point but there´s many other issues like timeout, lag, etc. Being there, done that.
> Actually the best choices for sync with mega is:
> net/megatools : Works fine, but have some issues like lag and you don´t have a proper daemon for that (you can use a cron and a script, of course).
> net/megacmd : It´s the official mega solution, works exactly the same but without a fancy GUI like megasync. There´s a daemon that runs in background. Have is own issues like lag in different scenarios, etc.



Another problem with using rclone with the MEGA backend is that it fails to login if your MEGA password contains special characters.


----------



## Menelkir (Jan 10, 2022)

reddy said:


> Another problem with using rclone with the MEGA backend is that it fails to login if your MEGA password contains special characters.


Yeah and also doesn't work if you have 2FA, I think the culprit is go-mega library used.


----------



## shuryanc (Jan 11, 2022)

Menelkir said:


> Are you using USES=localbase?


I think no.
I tried to check the code again, this time with-lmediainfo. But the configure file returns that "configure: error: Could not find libmediainfo" despite mediainfo is installed and I can see the library files in /usr/local/lib. Tried to add LDFLAGS="-L/usr/local/lib" to the configure line but doesn't work. Any suggestion?

From the code, it relies on MediaInfo_Info_Version() to confirm the existence of libmediainfo

```
extern "C"
#endif
char MediaInfo_Info_Version ();
int
main ()
{
return MediaInfo_Info_Version ();
  ;
  return 0;
}
```

But I can confirm /usr/local/lib/libmediainfo.so contains MediaInfo_Info_Version ()

```
[pc ~/megasync3/MEGAsync/src/MEGASync/mega]$ nm -D /usr/local/lib/libmediainfo.so | grep MediaInfo_Info_Version
000000000072e520 T MediaInfo_Info_Version
```


```
[shuryanc@shuryanc-ghostbsd-pc ~/megasync3/MEGAsync/src/MEGASync/mega]$ ld -lmediainfo
ld: error: unable to find library -lmediainfo
[shuryanc@shuryanc-ghostbsd-pc ~/megasync3/MEGAsync/src/MEGASync/mega]$ ld -L/usr/lib -lmediainfo
ld: warning: cannot find entry symbol _start; not setting start address
```


----------



## covacat (Jan 11, 2022)

tell configure to look in /usr/local/lib 
maybe
--with-mediainfo=/something/to/lookinto


----------



## Menelkir (Jan 11, 2022)

shuryanc said:


> I think no.


If you try to make a port of the thing, it'll do some fixes to you. USES=localbase will automatically point to /usr/local so the port will find the libraries instead of searching in /usr/lib or whatever place the developer decided it.


----------



## shuryanc (Jan 14, 2022)

Just an update.
The megasync can be complied in FreeBSD but with strange size.
It can find all the need library files but ran with segmentation fault.
I have pushed the code with test.log to github.








						GitHub - shuryanc/MEGAsync-For-FreeBSD: Easy automated syncing between your computers and your MEGA Cloud Drive
					

Easy automated syncing between your computers and your MEGA Cloud Drive - GitHub - shuryanc/MEGAsync-For-FreeBSD: Easy automated syncing between your computers and your MEGA Cloud Drive




					github.com


----------



## shuryanc (Jan 16, 2022)

```
Reading symbols from megasync...
(gdb) run
Starting program: /usr/bin/megasync
[Detaching after fork from child process 3841]
[New LWP 355996 of process 3840]
[New LWP 355999 of process 3840]
[LWP 355996 of process 3840 exited]
[New LWP 356002 of process 3840]
[New LWP 356003 of process 3840]
[New LWP 356004 of process 3840]
[New LWP 356013 of process 3840]

Thread 1 received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
0x0000000802acf9c5 in ?? () from /usr/local/lib/libcryptopp.so.8
```
Actually, this also happens on mega-cmd-server in megacmd package.


----------



## Menelkir (Jan 16, 2022)

shuryanc said:


> Actually, this also happens on mega-cmd-server in megacmd package.


API is probably borked at some degree... again.


----------



## shuryanc (Feb 6, 2022)

With addition of `pkgconf --cflags-only-other libcryptopp` to CXXFLAGS, I got megasync ran and synced on FreeBSD


----------



## grahamperrin@ (Feb 6, 2022)

Thanks,



shuryanc said:


> … addition of `pkgconf --cflags-only-other libcryptopp` to `CXXFLAGS`,



Does the success above mean that it's ready to be port-able by someone? (Not necessarily you.)


----------



## john_rambo (Feb 6, 2022)

I need megaSYNC client badly. At the moment I have installed Arch inside Virtualbox with a shared folder from GUEST to HOST and and using megaSYNC installed under Arch to backup data to mega .


----------



## Snubbi (Jun 11, 2022)

How far has gone with graphic Mega. I'm in the process of switching to Freebsd after 23 years with Linux. I have been using Mega on Linux for several years, and will miss it terribly in FreeBSD


----------



## j77h (Sep 22, 2022)

Haven't tried MEGA*tools* yet, but will do so asap.
(on a small remote VPS.)



			https://freebsd.pkgs.org/13/freebsd-amd64/megatools-1.10.3.pkg.html
		

Download size     172.64 KB
Note the small size and few dependencies.



			Megatools - command line client for Mega.nz
		


MEGA*cmd* is a lot bigger, but is still CLI.
MEGA*sync* is enormous, and is GUI.


----------



## Snubbi (Sep 23, 2022)

j77h said:


> MEGA*cmd* is a lot bigger, but is still CLI.
> MEGA*sync* is enormous, and is GUI.


Thanks


----------



## j77h (Oct 3, 2022)

Have tried MEGA*tools* on my home pc (Manjaro) and mega.*py* on my remote FreeBSD VPS.

They both work fine and easily for what I want to do (I don't do automated backups or sync-ing).
Except that they do *not* set the original file's *modified-time* (mtime) on the copy at MEGA.

Couldn't get MEGA*cmd* to run on FreeBSD; see details here:
https://forums.freebsd.org/threads/cannot-get-megacmd-to-run.86644/#post-583208


----------



## j77h (Oct 4, 2022)

Last week I asked Mega Support a question.
The reply has just arrived, and in it they say:


> Third-party tools are insecure and do not fully implement our cryptographic protocols, so we advise you not to use them.
> 
> ... 'mega.py' is buggy.
> 
> Megatools ... is NOT safe to use as it doesn't do crypto correctly. It is not based on our official SDK, so it does not operate correctly in all circumstances (e.g. when shared folders are involved).



MEGA*cmd* (provided by and recommended by Mega Ltd) is not so big,
the commands are straightforward,
and it covers all MEGA features such as auto-sync and auto-backup.


```
# pkg install megacmd
...
New packages to be INSTALLED:
        c-ares: 1.18.1
        cryptopp: 8.6.0
        libsodium: 1.0.18
        libuv: 1.42.0
        megacmd: 1.5.0
        sqlite3: 3.39.2,1
...
The process will require 45 MiB more space.
8 MiB to be downloaded.
```

But it doesn't run for me --
`mega-cmd-server` gets "Segmentation fault".


----------



## j77h (Oct 4, 2022)

shuryanc said:


> ```
> Thread 1 received signal SIGSEGV, Segmentation fault.
> ```
> 
> Actually, this also happens on mega-cmd-server in *megacmd* package.





shuryanc said:


> With addition of `pkgconf --cflags-only-other libcryptopp` to CXXFLAGS, I got megasync ran





grahamperrin@ said:


> Does the success above mean that it's ready to be port-able by someone?



And could it also be fixed in the *megacmd* pkg?

EDIT, UTC 22-10-06 03:20 :
Seems like megacmd 1.5.0_1 does not resolve this issue.
Have done a `pkg upgrade` which included
cryptopp: 8.6.0 -> 8.7.0
megacmd: 1.5.0 -> 1.5.0_1
and `mega-cmd-server` still gets `Segmentation fault (core dumped)`.


----------



## ArgentoSoma (Oct 18, 2022)

j77h said:


> And could it also be fixed in the *megacmd* pkg?
> 
> EDIT, UTC 22-10-06 03:20 :
> Seems like megacmd 1.5.0_1 does not resolve this issue.
> ...


I'm using a VM (Ubuntu server) using bhyve and sshfs for this issue. When I need sync my folders, run VM and mount my folders using SSHFS, and problem solved. It's a bazooka for a little problem, but work like a charm!


----------

