因為 Synology 官網的 Synology DSM 6.0 Developer Guide 問題很多,照著走根本不可能把 Package 建立起來,所以怒寫這篇文章。
首先從安裝環境開始,Developer Guide 的 2.1.1. Install Toolkit 就有問題,可以正常運作的指令如下:
mkdir -p /toolkit
git clone https://github.com/SynologyOpenSource/pkgscripts-ng.git
接著 2.1.2 Prepare Build Enviroment 也要修改:
cd /toolkit/pkgscripts-ng
./EnvDeploy -v 6.1 -p x64 # for example
再來 2.1.3 Prepare GPG Key 也有個要修改的地方:
mkdir -p /toolkit/build_env/ds.x64-6.1/root/.gnupg/
cp ~/.gnupg/* /toolkit/build_env/ds.x64-6.1/root/.gnupg/
同時也要注意不要設定密碼,還有 GNU PG 產生今鑰需要亂數。呆翰是遠端到另一台乾淨的 Linux 執行,一開始打鍵盤打個很開心才想起這是遠端。後來直接 sftp 丟了 BanG Dream 的 Android Backup 檔案上去提供了足夠的亂數讓 GNU PG 產生公鑰與私鑰。
接著後面的說明超亂,我建議直接跳到 2.2.5. Summary 直接看結論,了解重要結構。
了解結構後,我們知道原始碼要放在 /toolkit/source 底下,接著我們用 Synology 官方提供的 minialPkg 先試著打包 spk 出來
mkdir -p /toolkit/source
cd /toolkit/source
git clone https://github.com/SynologyOpenSource/minimalPkg.git
接著按照 minialPkg 上的說明建置 package
cd /toolkit
pkgscripts-ng/PkgCreate.py -c minimalPkg
一次成功,打開群輝上傳,安裝,也沒有問題。
一開始在 clone pkgscripts-ng 時,如果後面加上 pkgscripts 讓 script 安裝在 /toolkit/pkgscripts 的話,執行過程會出現以下錯誤:
============================================================
Parse argument result
env_section : default
only_install : False
suffix :
env_version : None
build : True
print_log : False
branch : master
update : True
sign : True
dep_level : 1
install : True
platforms : None
link : True
build_opt :
sdk_ver : 6.0
package : minimalPkg
collect : True
install_opt :
Processing [6.1-15152]: x64
============================================================
Start to run "Traverse project"
[INFO] Branch projects: minimalPkg
[INFO] Tag projects:
[INFO] Reference projects:
[INFO] Reference tag projects:
============================================================
Start to run "Link Project"
Link /toolkit/pkgscripts -> /toolkit/build_env/ds.x64-6.1/pkgscripts
cp: 不可以將目錄 '/toolkit/pkgscripts' 覆寫非目錄 '/toolkit/build_env/ds.x64-6.1/pkgscripts'
Traceback (most recent call last):
File "pkgscripts/PkgCreate.py", line 722, in
main(sys.argv[1:])
File "pkgscripts/PkgCreate.py", line 716, in main
packer.pack_package()
File "pkgscripts/PkgCreate.py", line 663, in pack_package
worker.execute()
File "pkgscripts/PkgCreate.py", line 158, in execute
self._process_output(self._run(*argv))
File "pkgscripts/PkgCreate.py", line 195, in _run
worker.execute(version, update_hook, depends_cache)
File "pkgscripts/PkgCreate.py", line 158, in execute
self._process_output(self._run(*argv))
File "pkgscripts/PkgCreate.py", line 241, in _run
link_scripts(chroot)
File "/toolkit/pkgscripts/include/python/link_project.py", line 34, in link_scripts
link(BuildEnv.ScriptDir, dest_path)
File "/toolkit/pkgscripts/include/python/link_project.py", line 27, in link
subprocess.check_call(['cp', '-al', source, dest])
File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cp', '-al', '/toolkit/pkgscripts', '/toolkit/build_env/ds.x64-6.1/pkgscripts']' returned non-zero exit status 1
呆翰一開始進去 /toolkit/build_env/ds.x64-6.1/ 看看有沒有什麼問題,結果發現 pkgscripts 指向 pkgscripts-ng ,而 pkgscripts-ng 不存在,呆翰還手動建立 pkgscripts-ng 資料夾,結果只是變成下面的錯誤:
============================================================
Parse argument result
suffix :
env_version : None
platforms : None
install : True
build : True
package : minimalPkg
dep_level : 1
sign : True
collect : True
install_opt :
update : True
only_install : False
branch : master
sdk_ver : 6.0
build_opt :
link : True
print_log : False
env_section : default
Processing [6.1-15152]: x64
============================================================
Start to run "Traverse project"
[INFO] Branch projects: minimalPkg
[INFO] Tag projects:
[INFO] Reference projects:
[INFO] Reference tag projects:
============================================================
Start to run "Link Project"
Traceback (most recent call last):
File "pkgscripts/PkgCreate.py", line 722, in
main(sys.argv[1:])
File "pkgscripts/PkgCreate.py", line 716, in main
packer.pack_package()
File "pkgscripts/PkgCreate.py", line 663, in pack_package
worker.execute()
File "pkgscripts/PkgCreate.py", line 158, in execute
self._process_output(self._run(*argv))
File "pkgscripts/PkgCreate.py", line 195, in _run
worker.execute(version, update_hook, depends_cache)
File "pkgscripts/PkgCreate.py", line 158, in execute
self._process_output(self._run(*argv))
File "pkgscripts/PkgCreate.py", line 241, in _run
link_scripts(chroot)
File "/toolkit/pkgscripts/include/python/link_project.py", line 33, in link_scripts
shutil.rmtree(dest_path)
File "/usr/lib/python3.5/shutil.py", line 484, in rmtree
onerror(os.path.islink, path, sys.exc_info())
File "/usr/lib/python3.5/shutil.py", line 482, in rmtree
raise OSError("Cannot call rmtree on a symbolic link")
OSError: Cannot call rmtree on a symbolic link
可見得這文件應該失修一陣子了,而且 6.0 也會有類似的錯誤。
如果已經按照 Developer Guide 建立環境而且出錯,以下的指令可以協助修正那些奇怪的問題:
cd /toolkit/
mv pkgscripts pkgscripts-ng
別浪費時間重建環境了,浪費兩個小時重建又多方測試,已經確定這樣就可以了。
spk 包起來確定環境沒問題後,再回頭詳讀 Developer Guide 把需要的東西改一改開始打包自己的 App 吧。