背景

有份图包在meganz的网盘上,大小36G,又不想用自己的电脑下载,想在群晖上下载。

虽然最后探索失败了,但是我觉得有必要记录一下
最后使用第三方工具成功

我的设备

黑群晖,主板J3160,架构i386(64位)。

cloudsync

群晖自带的cloudsync虽然有很多网盘,比如百度云盘、google drive、onedrive等,就是没有mega。

megacmd

查看meganz的官网,发现了个shell版本的客户端,megacmd。

https://mega.nz/cmd

编译好的有:

  • openSUSE
  • Elementary OS
  • Ubuntu
  • redhat
  • Raspbian (连树莓派都有,贴心
  • mint
  • fedora
  • debian

  • CentOS

  • arch linux

我凑合选了个debian8给群晖

1
2
3
4
5
6
7
8
[email protected]> dpkg -i megacmd-Debian_8.0_i386.deb
Authenticating megacmd-Debian_8.0_i386.deb ...
debsig: Origin Signature check failed. This deb might not be signed.

dpkg: error processing megacmd-Debian_8.0_amd64.deb (--install):
verification on package megacmd-Debian_8.0_amd64.deb failed!
Errors were encountered while processing:
megacmd-Debian_8.0_amd64.deb

签名验证失败,应该可以关闭签名验证。

(ref:http://ubuntu-users.narkive.com/OxlNy1NC/debsig-origin-signature-check-failed)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[email protected]> wget https://mega.nz/linux/MEGAsync/Debian_8.0/i386/megacmd-Deb
ian_8.0_i3
[email protected]> dpkg --force-bad-verify -i megacmd-Debian_8.0_i386.deb
Authenticating megacmd-Debian_8.0_i386.deb ...
debsig: Origin Signature check failed. This deb might not be signed.

dpkg: verification on package megacmd-Debian_8.0_i386.deb failed; but installing anyway as you requested
Selecting previously unselected package megacmd.
(Reading database ... 0 files and directories currently installed.)
Unpacking megacmd (from megacmd-Debian_8.0_i386.deb) ...
dpkg: dependency problems prevent configuration of megacmd:
megacmd depends on libc-ares2 (>= 1.7.4); however:
Package libc-ares2 is not installed.
megacmd depends on libc6 (>= 2.9); however:
Package libc6 is not installed.
megacmd depends on libcrypto++9; however:
Package libcrypto++9 is not installed.
megacmd depends on libgcc1 (>= 1:4.1.1); however:
Package libgcc1 is not installed.
megacmd depends on libmediainfo0 (>= 0.7.52); however:
Package libmediainfo0 is not installed.
megacmd depends on libpcre3 (>= 1:8.35); however:
Package libpcre3 is not installed.
megacmd depends on libpcrecpp0 (>= 7.7); however:
Package libpcrecpp0 is not installed.
megacmd depends on libssl1.0.0 (>= 1.0.1); however:
Package libssl1.0.0 is not installed.
megacmd depends on libstdc++6 (>= 4.9); however:
Package libstdc++6 is not installed.
megacmd depends on libzen0 (>= 0.4.23); however:
Package libzen0 is not installed.
megacmd depends on zlib1g (>= 1:1.2.0.2); however:
Package zlib1g is not install
dpkg: error processing megacmd (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
megacmd

诶,需要依赖一堆库,群晖这个系统又不是标准的Linux发行版。只能手动编译了。

在megacmd的github仓库下搜issue,看到了个pr

https://github.com/meganz/MEGAcmd/pull/24/files/de54ed19e276cb2148168ba4bdfe6319a0227a19

原来教程在这里,How to build MEGAcmd for Synology NAS drives.

里面提到的链接失效了,新的链接为

https://originhelp.synology.com/developer-guide/getting_started/index.html

以及开发者工具toolkits

https://sourceforge.net/projects/dsgpl/files/?source=navbar

尝试交叉编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[[email protected] ~]# mkdir /toolkit
[[email protected] ~]# cp -r MEGAcmd/build/SynologyNAS/toolkit/ /
[[email protected] ~]# cd /toolkit/
[[email protected] toolkit]# ls
build_all_synology_packages source
[[email protected] toolkit]# cd
[[email protected] ~]# cp -r MEGAcmd/ /toolkit/source/megacmdpkg/
[[email protected] ~]# cd /toolkit/
[[email protected] toolkit]# ls
build_all_synology_packages source
[[email protected] toolkit]# git clone git clone https://github.com/SynologyOpenSource/pkgscripts-ng^C
[[email protected] toolkit]# git clone https://github.com/SynologyOpenSource/pkgscripts-ng
正克隆到 'pkgscripts-ng'...
remote: Enumerating objects: 195, done.
remote: Total 195 (delta 0), reused 0 (delta 0), pack-reused 195
接收对象中: 100% (195/195), 97.93 KiB | 0 bytes/s, done.
处理 delta 中: 100% (113/113), done.

尝试直接执行EnvDeploy,看看help option

1
2
[[email protected] toolkit]# ./pkgscripts-ng/EnvDeploy
/usr/bin/env: python3: 没有那个文件或目录

好吧,原来是python3写的

centos7安装python3

1
yum install python34

装好后,再次执行./pkgscripts-ng/EnvDeploy,直接报错了

1
2
3
4
5
6
7
8
9
10
11
[[email protected] toolkit]# ./pkgscripts-ng/EnvDeploy
Traceback (most recent call last):
File "./pkgscripts-ng/EnvDeploy", line 335, in <module>
main(sys.argv[1:])
File "./pkgscripts-ng/EnvDeploy", line 313, in main
platforms = get_platforms(dsm_ver, build_num, args.platforms)
File "./pkgscripts-ng/EnvDeploy", line 277, in get_platforms
all_platforms = get_all_platforms(dsm_ver, build_num)
File "./pkgscripts-ng/EnvDeploy", line 256, in get_all_platforms
pattern = 'AvailablePlatform_%s_%s' % (dsm_ver.split('.')[0], dsm_ver.split('.')[1])
IndexError: list index out of range

emmm???

并没有help菜单

算了,按照教程走吧

我的主板是J3160,架构是i386,DSM版本5.2

1
2
3
4
5
6
[[email protected] toolkit]# ./pkgscripts-ng/EnvDeploy -v 5.2 -p i386

PlatformNotAvailableError:
[i386] is not available platform.

[ERROR] ./pkgscripts-ng/EnvDeploy -v 5.2 -p i386 failed!

既然没有help菜单,参考readme,查看可用的platform

1
./EnvDeploy -v 6.1 --list

返回是空。

喵喵喵???

抬头一看,仓库的描述:

Synology DSM6.0 package toolkit framework

不支持DSM5.x啊。。

直接编译

尴尬,看来只能直接编译了。

developer_guide.pdf:https://global.download.synology.com/download/Document/DeveloperGuide/DSM_Developer_Guide.pdf

或者:https://originhelp.synology.com/developer-guide/getting_started/index.html

刚刚群晖的官网提到的工具包。

1
2
[email protected]> uname -a
Linux NAS 3.10.35 #1 SMP Tue Feb 2 17:44:24 CET 2016 x86_64 GNU/Linux synology_bromolow_3615xs

内核版本 3.10.35,参考https://originhelp.synology.com/developer-guide/compile_applications/download_dsm_tool_chain.html找到对应的toolkit

下载这个

https://sourceforge.net/projects/dsgpl/files/DSM%205.2%20Tool%20Chains/Intel%20x86%20Linux%203.2.40%20%28Bromolow%29/

guide里面有提如何编译开源项目

编译三步走:configure,make,make install

tool chain提供了configure、make等指令,但是megacmd的项目没有configure文件,需要用autoreconf生成对应的configure。

因为之前装aria2,安装了ipkg,安装的步骤见https://post.smzdm.com/p/49402/

ipkg的软件源只有autoconf,没有autoreconf。。

峰回路转

后来发现toolkit-env包中提供了autoreconf
可是解压出来的 /usr都有1.9G了,我的系统盘才8G,除了loader和dsm只有3G,除了装的套件之类的,现在只有1.2G了。。

既然是提供了DSM5.2版本、架构为bromolow的toolit
再看https://github.com/meganz/MEGAcmd/tree/master/build/SynologyNAS 最后一行

1
rm -rf /toolkit/build_env/ds.armada38x-6.1

所以,当执行

1
./pkgscripts-ng/EnvDeploy -v 6.1 -p armada38x

其实是去匹配对应的toolkit,自动下载,配置好env。
文件源码也印证了我的想法

其他方案

  1. 凑合能用的 golang版 (no longer fully maintained

google搜到的

https://forum.synology.com/enu/viewtopic.php?t=63386

https://github.com/t3rm1n4l/megacmd

似乎有点问题

https://github.com/SynoCommunity/spksrc/issues/625

  1. docker版本

https://www.reddit.com/r/synology/comments/7ngdki/mega_on_synology/

https://github.com/john-shine/mega.syno

  1. 去其他服务器上用megacmd下载

比如,在centos7上安装megacmd

CentOS7,mega是提供了预编译的rpm包

https://mega.nz/linux/MEGAsync/CentOS_7/x86_64/megacmd-CentOS_7.x86_64.rpm

1
rpm -i megacmd-CentOS_7.x86_64.rpm

警告:megacmd-CentOS_7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 7f068e5d: NOKEY
错误:依赖检测失败:
​ libcares.so.2()(64bit) 被 megacmd-0.9.9-8.1.x86_64 需要

所需的libcares.so

https://centos.pkgs.org/7/centos-x86_64/c-ares-1.10.0-3.el7.i686.rpm.html

1
yum install c-ares

再次

1
rpm -i megacmd-CentOS_7.x86_64.rpm

即可安装

megacmd使用手册见https://github.com/meganz/MEGAcmd/blob/master/UserGuide.md

update:
free account 的bandwith limit 是3G,每6小时刷新

1
2
[[email protected] mega]# du -s
3463020

约等于3G

  1. rclone

rclone是一个golang开发的同步软件,支持多种网盘同步和备份,其中就有mega。
这样我们在本机上交叉编译好适用于群晖架构的rclone,就可以同步mega了。

交叉编译可以参考:https://www.faun.me/2015/02/17/cross-compiling-golang-applications-for-synology-1513.html
如果是白裙,可以在 http://forum.synology.com/wiki/index.php/What_kind_of_CPU_does_my_NAS_have 查看处理器架构
黑裙的话,可以在intel官网查看类型
https://ark.intel.com/zh-cn/products/91533/Intel-Celeron-Processor-J3160-2M-Cache-up-to-2_24-GHz

或者uname查看

1
2
[email protected]> uname -m
x86_64

获取源码

1
go get github.com/ncw/rclone

开始交叉编译

1
2
cd go/src/github.com/ncw/rclone
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build

新生成的二进制可执行文件rclone

1
2
> ls -lh rclone
-rwxr-xr-x 1 meoww staff 32M 10 6 21:08 rclone

scp传到群晖的任意目录即可,当然也可以传到系统的环境变量下。
rclone的使用可以参考:https://blog.liyuans.com/archives/rclone-config.html
使用前需要运行./rclone config配置网盘的类型和账号,按照提示输入即可

从远程同步到本地
假设远程配置名字是remote
同步远程的目录youmu
到本地的/root/youmu/
命令如下

1
rclone copy remote:youmu /root/youmu/

实际使用的时候,家里群晖登陆不上mega,因为mega在国内是被墙的状态。只需要找到登陆的api地址,在路由器上加上规则即可。
在国外的vps上登陆mega,并使用tcpdump抓包:

1
tcpdump -w rclone.cap

scp拖回本地 wireshark打开分析
本来准备用过滤器(filter),过滤掉我的ip和无用icmp等协议,并且ip源是那台机器的,这样就能得到可能的mega 通信目的的ip地址

1
ip.dst != 110.184.218.203 & ip.src == 185.230.162.187

得到疑似ip,31.216.147.136,而且目的端口是443,也有服务器发往这个IP,协议为TLSv1.2的包
但是,我注意到,抓包记录内有目的ip是8.8.8.8的包,8.8.8.8是google的DNS服务器ip,mega的网盘登陆地址在rclone内应该不是hard code的,所以会做DNS query(其实也可以看rclone源码来确定

DNS主要在查询以下两个域名的ipv4和ipv6地址

1
2
w.api.mega.co.nz
g.api.mega.co.nz

dig查询一下

1
2
3
4
5
6
7
8
└─[$] <> dig {w,g}.api.mega.co.nz +short
31.216.147.156
31.216.147.161
lu.api.mega.co.nz.
31.216.147.133
31.216.147.135
31.216.147.134
31.216.147.136

如果不看short精简的结果,w开头的api地址是有两个不同ip的A记录,g开头的是一个到lu.api.mega.co.nz的cname记录。
所以最好直接在路由器的代理名单中加上这两个域名。