镜像自地址
https://github.com/JGZYES/ParlzPackageManger.git
已同步 2026-09-11 05:42:44 +08:00
feat(pdm): InstallScript — run a script from the package after install
pdm-control optional 'InstallScript: <path-in-pkg>' runs a script shipped in the package once the files are installed (like a Debian postinst). The script is chmod +x and executed with PMM_ROOT=<install dir>; its exit code is reported. Added i18n keys (zh/en builtin + packs) and docs.
这个提交包含在:
+2
-2
文件差异因一行或多行过长而隐藏
@@ -668,6 +668,37 @@ int pdm_install_file(const char *pdmfile) {
|
||||
pmm_sync_self(nb);
|
||||
}
|
||||
|
||||
/* InstallScript: run a script shipped in the package after install (like a
|
||||
* Debian postinst). The script path is relative to the package's install
|
||||
* dir (root, or root/<InstallDir>). */
|
||||
char *post = control_get(ctl, "InstallScript");
|
||||
if (post && *post) {
|
||||
char sroot[1500];
|
||||
if (flat) snprintf(sroot, sizeof(sroot), "%s", home);
|
||||
else if (pmm_install_subdir[0]) snprintf(sroot, sizeof(sroot), "%s/%s", root, pmm_install_subdir);
|
||||
else snprintf(sroot, sizeof(sroot), "%s", root);
|
||||
char spath[1700];
|
||||
snprintf(spath, sizeof(spath), "%s/%s", sroot, post);
|
||||
char cx[1800];
|
||||
snprintf(cx, sizeof(cx), "chmod +x \"%s\" 2>/dev/null || true", spath);
|
||||
system(cx);
|
||||
FILE *xf = fopen(spath, "rb");
|
||||
if (xf) {
|
||||
fclose(xf);
|
||||
#ifdef _WIN32
|
||||
_putenv_s("PMM_ROOT", sroot);
|
||||
#else
|
||||
setenv("PMM_ROOT", sroot, 1); /* give the script its install dir */
|
||||
#endif
|
||||
int src = system(spath);
|
||||
if (src == 0) pmm_success("%s", pmm_tr_fmt("msg.postinst-ok", spath));
|
||||
else pmm_warn("%s", pmm_tr_fmt("msg.warn.postinst", spath));
|
||||
} else {
|
||||
pmm_warn("%s", pmm_tr_fmt("msg.warn.postinst-missing", spath));
|
||||
}
|
||||
free(post);
|
||||
}
|
||||
|
||||
free(pkg); if (ver) free(ver);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -81,10 +81,12 @@ Maintainer: you@mail.com
|
||||
# 可选:
|
||||
# LibraryPath: true # 装到 ~/.pmm/root 后,自动把本包 lib/ 加入 LD_LIBRARY_PATH(新 shell 生效)
|
||||
# InstallDir: tools/myapp # 把本包装到 ~/.pmm/root/tools/myapp (bin -> .../bin, lib -> .../lib)
|
||||
# InstallScript: bin/postinst.sh # 安装后自动运行包内脚本(可访问 $PMM_ROOT 环境变量)
|
||||
```
|
||||
|
||||
> `LibraryPath` 默认 `false`(不加);`true` 时 pmm 会在 `~/.bashrc` 写入本包 lib 目录的
|
||||
> `LD_LIBRARY_PATH`。`InstallDir` 可把包装到 `~/.pmm/root/<子目录>`,该目录下的 `bin` 也会进 PATH。
|
||||
> `InstallScript` 指向包内脚本路径,安装后执行(环境变量 `$PMM_ROOT` = 本包安装目录)。
|
||||
|
||||
打包:
|
||||
|
||||
|
||||
@@ -134,5 +134,8 @@
|
||||
"desc.cache": "manage download cache",
|
||||
"desc.fetch": "predownload to cache",
|
||||
"msg.offline-using-cache": "offline: using cached %s",
|
||||
"msg.err.not-cached": "%s not in cache (run pmm fetch)"
|
||||
"msg.err.not-cached": "%s not in cache (run pmm fetch)",
|
||||
"msg.postinst-ok": "post-install script ran OK: %s",
|
||||
"msg.warn.postinst": "post-install script returned non-zero: %s",
|
||||
"msg.warn.postinst-missing": "post-install script missing: %s"
|
||||
}
|
||||
|
||||
@@ -134,5 +134,8 @@
|
||||
"desc.cache": "管理缓存",
|
||||
"desc.fetch": "预下载到缓存",
|
||||
"msg.offline-using-cache": "离线: 使用缓存 %s",
|
||||
"msg.err.not-cached": "%s 未在缓存中(先运行 pmm fetch)"
|
||||
"msg.err.not-cached": "%s 未在缓存中(先运行 pmm fetch)",
|
||||
"msg.postinst-ok": "安装后脚本执行成功: %s",
|
||||
"msg.warn.postinst": "安装后脚本返回非 0: %s",
|
||||
"msg.warn.postinst-missing": "安装后脚本缺失: %s"
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户