@synopackageland/cli 0.52.11 → 0.52.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.52.13
4
+
5
+ - Add `install.min_memory_mb` for dynamic physical RAM admission on install and upgrade, independent of NAS model
6
+ - Integrate localized low-memory pages with the existing install and upgrade wizards and repeat the check in package-account preinst
7
+ - Warn and allow installation when MemTotal cannot be read; keep runtime/start behavior unchanged
8
+ - Inspect packaged requirements, wizard files and preinst checks against the same declaration
9
+
3
10
  ## 0.52.11
4
11
 
5
12
  - Bridge `window-activated` from the injected DSM AppWindow, including switching
@@ -1,9 +1,11 @@
1
+ import { type Locale } from "../standalone/i18n.js";
1
2
  import { type Translate } from "./wizard-i18n.js";
2
3
  /** One step of a DSM install wizard; `items` are rendered verbatim as JSON. */
3
4
  export interface InstallWizardStep {
4
5
  step_title: string;
5
6
  items: Array<Record<string, unknown>>;
6
7
  activeate?: string;
8
+ invalid_next_disabled_v2?: boolean;
7
9
  }
8
10
  /** The static JSON wizard per locale, and the dynamic script per locale. */
9
11
  export interface InstallWizardFiles {
@@ -16,7 +18,9 @@ export interface InstallWizardFiles {
16
18
  * versions and flows that do not run the dynamic script; both carry the same
17
19
  * items, and only the dynamic one adds the reuse notice when data exists.
18
20
  */
19
- export declare function renderInstallWizardFiles(packageName: string, render: (t: Translate) => InstallWizardStep[]): InstallWizardFiles;
21
+ export declare function renderInstallWizardFiles(packageName: string, render: (t: Translate) => InstallWizardStep[], minMemoryMb?: number): InstallWizardFiles;
22
+ /** Prepend to an existing dynamic wizard; retain its normal pages when memory is sufficient. */
23
+ export declare function renderMemoryWizardCheck(minMemoryMb: number | undefined, locale: Locale): string;
20
24
  /** Lists the App's unauthenticated service callbacks for the administrator. */
21
25
  export declare function integrationWizardSteps(t: Translate, methods?: readonly string[]): InstallWizardStep[];
22
26
  /** The native-go install step: no parameters, only the app-space consent. */
@@ -1,5 +1,6 @@
1
1
  import { DSM_LANGS, LOCALES } from "../standalone/i18n.js";
2
2
  import { renderWizardFiles, translator } from "./wizard-i18n.js";
3
+ import { memoryReason, renderMemoryProbe } from "../standalone/install-memory.js";
3
4
  const BASE = "install_uifile";
4
5
  function shellQuote(value) {
5
6
  return `'${value.replaceAll("'", "'\\''")}'`;
@@ -26,11 +27,11 @@ function withReuseNotice(steps, packageName, t) {
26
27
  * is chosen after the wizard on some flows). The wizard JSON is written to
27
28
  * `SYNOPKG_TEMP_LOGFILE`, DSM's documented channel, or stdout without it.
28
29
  */
29
- function renderDynamicScript(packageName, withData, withoutData) {
30
+ function renderDynamicScript(packageName, withData, withoutData, memoryCheck = "") {
30
31
  return `#!/bin/sh
31
32
  # Generated by synopkgland. Read-only: it checks whether this package already
32
33
  # has App Data on a volume, then prints the install wizard for this language.
33
- pkg=${shellQuote(packageName)}
34
+ ${memoryCheck}pkg=${shellQuote(packageName)}
34
35
  existing=
35
36
  for root in \${SYNOPKG_PKGDEST_VOL:-} /volume*; do
36
37
  if [ -n "$root" ] && [ -d "$root/@appdata/$pkg" ]; then
@@ -58,7 +59,7 @@ fi
58
59
  * versions and flows that do not run the dynamic script; both carry the same
59
60
  * items, and only the dynamic one adds the reuse notice when data exists.
60
61
  */
61
- export function renderInstallWizardFiles(packageName, render) {
62
+ export function renderInstallWizardFiles(packageName, render, minMemoryMb) {
62
63
  const staticFiles = renderWizardFiles(BASE, render);
63
64
  const dynamic = {};
64
65
  for (const locale of LOCALES) {
@@ -66,10 +67,36 @@ export function renderInstallWizardFiles(packageName, render) {
66
67
  const steps = render(t);
67
68
  const withData = JSON.stringify(withReuseNotice(steps, packageName, t), null, 2);
68
69
  const withoutData = JSON.stringify(steps, null, 2);
69
- dynamic[localeName(locale, ".sh")] = renderDynamicScript(packageName, withData, withoutData);
70
+ dynamic[localeName(locale, ".sh")] = renderDynamicScript(packageName, withData, withoutData, renderMemoryWizardCheck(minMemoryMb, locale));
70
71
  }
71
72
  return { static: staticFiles, dynamic };
72
73
  }
74
+ /** Prepend to an existing dynamic wizard; retain its normal pages when memory is sufficient. */
75
+ export function renderMemoryWizardCheck(minMemoryMb, locale) {
76
+ if (minMemoryMb === undefined)
77
+ return "";
78
+ const reason = memoryReason(minMemoryMb, locale, "__SYNOPKGLAND_MEMORY_GB__");
79
+ const page = [{
80
+ step_title: translator(locale)("memory.title"),
81
+ invalid_next_disabled_v2: true,
82
+ items: [{ type: "textfield", desc: reason, subitems: [{
83
+ key: "pkgwizard_memory_requirement", desc: "", defaultValue: "__SYNOPKGLAND_MEMORY_GB__",
84
+ readOnly: true, validator: { allowBlank: false, fn: `{return ${JSON.stringify(reason)}}` },
85
+ }] }],
86
+ }];
87
+ // Only a formatted numeric value enters JSON, never shell or meminfo text.
88
+ const json = JSON.stringify(page, null, 2);
89
+ return `${renderMemoryProbe(minMemoryMb)}if [ -n "$synopkgland_memory_low" ]; then
90
+ if [ -n "\${SYNOPKG_TEMP_LOGFILE:-}" ]; then
91
+ exec > "$SYNOPKG_TEMP_LOGFILE"
92
+ fi
93
+ sed "s/__SYNOPKGLAND_MEMORY_GB__/$synopkgland_memory_gb/g" <<'SYNOPKGLAND_MEMORY_WIZARD'
94
+ ${json}
95
+ SYNOPKGLAND_MEMORY_WIZARD
96
+ exit 0
97
+ fi
98
+ `;
99
+ }
73
100
  /** Lists the App's unauthenticated service callbacks for the administrator. */
74
101
  export function integrationWizardSteps(t, methods = []) {
75
102
  return methods.length ? [{ step_title: t("integration.step"), items: [{ desc: t("integration.notice", { methods: methods.join(", ") }) }] }] : [];
@@ -1,4 +1,26 @@
1
1
  export declare const WIZARD_MESSAGES: {
2
+ "memory.title": {
3
+ en: string;
4
+ "zh-TW": string;
5
+ "zh-CN": string;
6
+ ja: string;
7
+ ko: string;
8
+ de: string;
9
+ fr: string;
10
+ es: string;
11
+ it: string;
12
+ };
13
+ "memory.required": {
14
+ en: string;
15
+ "zh-TW": string;
16
+ "zh-CN": string;
17
+ ja: string;
18
+ ko: string;
19
+ de: string;
20
+ fr: string;
21
+ es: string;
22
+ it: string;
23
+ };
2
24
  "ports.http": {
3
25
  en: string;
4
26
  "zh-TW": string;
@@ -1,4 +1,26 @@
1
1
  export const WIZARD_MESSAGES = {
2
+ "memory.title": {
3
+ "en": "Memory requirement",
4
+ "zh-TW": "記憶體需求",
5
+ "zh-CN": "内存要求",
6
+ "ja": "必要なメモリ",
7
+ "ko": "메모리 요구 사항",
8
+ "de": "Arbeitsspeicheranforderung",
9
+ "fr": "Mémoire requise",
10
+ "es": "Memoria necesaria",
11
+ "it": "Memoria richiesta"
12
+ },
13
+ "memory.required": {
14
+ "en": "This App requires at least {required} GB of RAM; this NAS has {actual} GB",
15
+ "zh-TW": "此應用程式需要至少 {required} GB 記憶體,此 NAS 有 {actual} GB",
16
+ "zh-CN": "此应用程序需要至少 {required} GB 内存,此 NAS 有 {actual} GB",
17
+ "ja": "このアプリには {required} GB 以上の RAM が必要です。この NAS のメモリは {actual} GB です",
18
+ "ko": "이 앱에는 최소 {required} GB의 RAM이 필요합니다. 이 NAS의 메모리는 {actual} GB입니다",
19
+ "de": "Diese App benötigt mindestens {required} GB RAM; dieses NAS verfügt über {actual} GB",
20
+ "fr": "Cette application nécessite au moins {required} Go de RAM ; ce NAS dispose de {actual} Go",
21
+ "es": "Esta aplicación requiere al menos {required} GB de RAM; este NAS tiene {actual} GB",
22
+ "it": "Questa app richiede almeno {required} GB di RAM; questo NAS dispone di {actual} GB"
23
+ },
2
24
  "ports.http": {
3
25
  "en": "HTTP port",
4
26
  "zh-TW": "HTTP 連接埠",
@@ -50,6 +50,7 @@ export const ERROR_REGISTRY = {
50
50
  DSM_WINDOW_COLOR_SCHEME: { code: 'DSM_WINDOW_COLOR_SCHEME', description: 'A DSM-window Vue component combines OS theme detection with a dynamic color-scheme binding', suggestion: 'Leave color-scheme unset in DSM windows; follow OS preferences only on the App\'s own full page' },
51
51
  STANDALONE_IDENTITY_WITHOUT_PORTAL: { code: 'STANDALONE_IDENTITY_WITHOUT_PORTAL', description: 'Standalone identity is enabled without an Application Portal declaration', suggestion: 'Use HTTPS-only standalone login outside DSM windows; declare portal only when an alias is needed' },
52
52
  INSTALL_SETTINGS_INVALID: { "code": "INSTALL_SETTINGS_INVALID", "description": "The installation setting declaration is invalid.", "suggestion": "Declare 1–32 lowercase identifier keys in install.settings, each with type https-origin, a plain label and an explicit boolean required; omit defaults and values." },
53
+ INSTALL_MIN_MEMORY_INVALID: { code: "INSTALL_MIN_MEMORY_INVALID", description: "The physical memory requirement or its packaged check is invalid.", suggestion: "Set install.min_memory_mb to a positive integer in MiB, at most 2147483647, and rebuild with the generated package-account hooks and wizards." },
53
54
  INSTALL_PORT_INVALID: { code: "INSTALL_PORT_INVALID", description: "The installation port declaration or selected value is invalid", suggestion: "Enable install.ports for a declared identity gateway and choose distinct available non-reserved ports between 1024 and 65535" },
54
55
  SDK_PORT_SETTINGS_UNSUPPORTED: { code: "SDK_PORT_SETTINGS_UNSUPPORTED", description: "The selected SDK does not provide installer-selected ports", suggestion: "Pin SDK 0.38.2 or a matching supported release and rebuild with the matching CLI" },
55
56
  SDK_INSTALL_SETTINGS_UNSUPPORTED: { "code": "SDK_INSTALL_SETTINGS_UNSUPPORTED", "description": "The selected SDK does not provide native installation settings.", "suggestion": "Pin SDK 0.24.0 or a matching supported release with installsettings/cmd/control, then rebuild with the matching CLI." },
@@ -20,6 +20,7 @@ export interface SpkInspection {
20
20
  tcpListeners?: TCPListeners;
21
21
  dependencies?: PackageDependencies;
22
22
  installSettings?: InstallSettings;
23
+ minMemoryMb?: number;
23
24
  /** Hyper Backup application backup, as sdk-package.json records it. */
24
25
  hyperBackup?: HyperBackup;
25
26
  identityGateway?: GatewayAdmissionReport;
@@ -5,6 +5,7 @@ import { DAEMON_NOFILE_UNSUPPORTED, DAEMON_NOFILE_ACTIVATION_PROBLEM, readNoFile
5
5
  import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
6
6
  import { renderGatewayIngressCheck } from './native-gateway.js';
7
7
  import { portDefaults, portInstallSteps } from "./install-ports.js";
8
+ import { readMinMemoryMb, renderMemoryHook } from "./install-memory.js";
8
9
  import { inspectPackageDependencies, dependencyInfo } from "./package-dependencies.js";
9
10
  import { readInstallSettings, settingsInstallSteps, settingsConfig, renderSettingsHook } from './install-settings.js';
10
11
  import { MODULE_UI_ENTRY, uiTreeDigest } from "./ui-assets.js";
@@ -186,6 +187,7 @@ export async function inspectSpk(spkPath, expectedKind) {
186
187
  findings.push("DAEMON_RESTART_INVALID daemon restart requires a native daemon controller, without Compose supervision");
187
188
  const { identityGateway, gateway } = await inspectGatewayAdmission(dir, paths, metadata.provider_only_oidc, findings);
188
189
  await inspectExternalGateway(dir, paths, payload, metadata.gateway_external, findings);
190
+ const minMemoryMb = inspectMemoryRequirement(dir, metadata.minMemoryMb, findings);
189
191
  const installSettings = await inspectInstallSettings(dir, payload, metadata, findings);
190
192
  const hyperBackup = metadataText === undefined ? undefined : await inspectHyperBackup(dir, async () => {
191
193
  const root = join(dir, "backup-inspection");
@@ -199,12 +201,14 @@ export async function inspectSpk(spkPath, expectedKind) {
199
201
  const integrations = metadata.integrations ?? [];
200
202
  await inspectCtlArtifacts(dir, paths, metadata.ctl, metadata.entry, findings);
201
203
  if (metadata.compose !== undefined) {
202
- const result = await inspectUnifiedCompose(dir, payload, { ...metadata, installSettings }, findings);
204
+ const result = await inspectUnifiedCompose(dir, payload, { ...metadata, installSettings, minMemoryMb }, findings);
203
205
  if (dependencies) {
204
206
  result.dependencies = dependencies;
205
207
  }
206
208
  if (installSettings)
207
209
  result.installSettings = installSettings;
210
+ if (minMemoryMb !== undefined)
211
+ result.minMemoryMb = minMemoryMb;
208
212
  if (hyperBackup)
209
213
  result.hyperBackup = hyperBackup;
210
214
  if (identityGateway)
@@ -346,7 +350,7 @@ export async function inspectSpk(spkPath, expectedKind) {
346
350
  ? await inspectLoginStyle(dir, info.package, Boolean(portal || executor?.policy.portal), findings)
347
351
  : undefined;
348
352
  if (standalone)
349
- checkSharedFolder(dir, findings, info.package, sharedFolder, executor?.policy.scope === "install-selected", portal, hasExecutor, nativeGateway, info.os_min_ver, installSettings, integrations, metadata.installPorts);
353
+ checkSharedFolder(dir, findings, info.package, sharedFolder, executor?.policy.scope === "install-selected", portal, hasExecutor, nativeGateway, info.os_min_ver, installSettings, integrations, metadata.installPorts, minMemoryMb);
350
354
  const icon = inspectPackageIcons(dir, findings);
351
355
  const cgiEntry = payload.find((entry) => entry.path === CGI_PAYLOAD_PATH);
352
356
  if (standalone && !cgiEntry) {
@@ -363,6 +367,7 @@ export async function inspectSpk(spkPath, expectedKind) {
363
367
  ...(identityGateway ? { identityGateway } : {}),
364
368
  ...(gateway ? { gateway } : {}),
365
369
  ...(installSettings ? { installSettings } : {}),
370
+ ...(minMemoryMb !== undefined ? { minMemoryMb } : {}),
366
371
  ...(hyperBackup ? { hyperBackup } : {}),
367
372
  ...(launch ? { launch } : {}),
368
373
  icon,
@@ -854,8 +859,8 @@ async function inspectUnifiedCompose(dir, payload, metadata, findings) {
854
859
  throw new Error("gateway configuration differs from the declared package contract");
855
860
  if (readOptional(join(dir, "conf/privilege")) !== renderNativePrivilege())
856
861
  throw new Error("Compose hooks must run as the package account");
857
- if (manifest.sharedFolder || metadata.installSettings || metadata.installPorts) {
858
- for (const [name, text] of Object.entries(expectedWizardFiles(info.package, manifest.sharedFolder, false, undefined, metadata.installSettings, [], manifest.identityGateway?.listen.https, metadata.installPorts)))
862
+ if (manifest.sharedFolder || metadata.installSettings || metadata.installPorts || metadata.minMemoryMb !== undefined) {
863
+ for (const [name, text] of Object.entries(expectedWizardFiles(info.package, manifest.sharedFolder, false, undefined, metadata.installSettings, [], manifest.identityGateway?.listen.https, metadata.installPorts, metadata.minMemoryMb)))
859
864
  if (readOptional(join(dir, "WIZARD_UIFILES", name)) !== text)
860
865
  throw new Error(`unexpected WIZARD_UIFILES/${name}; native share selection must match the declaration`);
861
866
  }
@@ -1510,7 +1515,7 @@ function checkBackground(dir, info, payload, findings, executor, daemon, bridge
1510
1515
  * declaration (without one, any present file must be the default native
1511
1516
  * install wizard), and no other install/upgrade wizard file may exist.
1512
1517
  */
1513
- function checkSharedFolder(dir, findings, pkg, folder, selected = false, portal, executor = false, nativeGateway, osMinVer, installSettings, integrations = [], installPortDefinitions = {}) {
1518
+ function checkSharedFolder(dir, findings, pkg, folder, selected = false, portal, executor = false, nativeGateway, osMinVer, installSettings, integrations = [], installPortDefinitions = {}, minMemoryMb) {
1514
1519
  const wizardDir = join(dir, "WIZARD_UIFILES");
1515
1520
  const present = (existsSync(wizardDir) ? readdirSync(wizardDir) : [])
1516
1521
  .filter((name) => /^(install|upgrade)_uifile(_|\.|$)/.test(name))
@@ -1537,7 +1542,7 @@ function checkSharedFolder(dir, findings, pkg, folder, selected = false, portal,
1537
1542
  : {}),
1538
1543
  ...portalManifest(portal),
1539
1544
  };
1540
- const wizards = expectedWizardFiles(pkg, folder, selected, portal, installSettings, integrations, nativeGateway?.listen.https, installPortDefinitions);
1545
+ const wizards = expectedWizardFiles(pkg, folder, selected, portal, installSettings, integrations, nativeGateway?.listen.https, installPortDefinitions, minMemoryMb);
1541
1546
  const source = selected
1542
1547
  ? "the install-selected policy"
1543
1548
  : folder
@@ -1548,7 +1553,7 @@ function checkSharedFolder(dir, findings, pkg, folder, selected = false, portal,
1548
1553
  ? "the integrations declaration"
1549
1554
  : "the native-go default install wizard";
1550
1555
  // The default native wizard is optional; a declared shared folder or portal needs all of its files.
1551
- for (const name of folder || selected || portal || installSettings || Object.keys(installPortDefinitions).length || integrations.length
1556
+ for (const name of folder || selected || portal || installSettings || Object.keys(installPortDefinitions).length || integrations.length || minMemoryMb !== undefined
1552
1557
  ? Object.keys(wizards)
1553
1558
  : present.filter((n) => n in wizards)) {
1554
1559
  if (readOptional(join(wizardDir, name)) !== wizards[name])
@@ -1570,6 +1575,28 @@ function checkSharedFolder(dir, findings, pkg, folder, selected = false, portal,
1570
1575
  }
1571
1576
  }
1572
1577
  }
1578
+ /** Verify and peel only the exact memory prefix, within a canonical App wrapper if present. */
1579
+ function inspectMemoryRequirement(dir, value, findings) {
1580
+ const minMemoryMb = readMinMemoryMb(value, e => findings.push(`${e.code} ${e.message}`));
1581
+ const file = join(dir, "scripts/preinst");
1582
+ const text = readOptional(file);
1583
+ if (minMemoryMb === undefined) {
1584
+ if (text?.includes("[INSTALL_MEMORY_READ_WARNING]"))
1585
+ findings.push("INSTALL_MIN_MEMORY_INVALID memory check has no valid declaration");
1586
+ return undefined;
1587
+ }
1588
+ const prefix = renderMemoryHook(minMemoryMb);
1589
+ const sdk = text && sdkScriptOf("preinst", text)?.sdk;
1590
+ if (!text || !sdk?.startsWith("#!/bin/sh\n" + prefix) || text.split(prefix).length !== 2) {
1591
+ findings.push("INSTALL_MIN_MEMORY_INVALID scripts/preinst lacks the exact declared memory check");
1592
+ }
1593
+ else {
1594
+ writeFileSync(file, text.replace(prefix, ""));
1595
+ }
1596
+ if (readOptional(join(dir, "conf/privilege")) !== renderNativePrivilege())
1597
+ findings.push("INSTALL_MIN_MEMORY_INVALID memory check must run as the package account");
1598
+ return minMemoryMb;
1599
+ }
1573
1600
  /** Validate SDK settings inventory and hook prefix before existing backend inspectors.
1574
1601
  * All reads and temporary rewrites are in the extracted inspection directory. */
1575
1602
  async function inspectInstallSettings(dir, payload, metadata, findings) {
@@ -1629,7 +1656,7 @@ async function inspectInstallSettings(dir, payload, metadata, findings) {
1629
1656
  }
1630
1657
  return settings;
1631
1658
  }
1632
- function expectedWizardFiles(pkg, folder, selected = false, portal, installSettings, integrations = [], settingsPort = 0, installPortDefinitions = {}) {
1659
+ function expectedWizardFiles(pkg, folder, selected = false, portal, installSettings, integrations = [], settingsPort = 0, installPortDefinitions = {}, minMemoryMb) {
1633
1660
  const steps = selected
1634
1661
  ? (t) => [
1635
1662
  ...renderDelegateScopeSteps(t),
@@ -1638,11 +1665,11 @@ function expectedWizardFiles(pkg, folder, selected = false, portal, installSetti
1638
1665
  : folder
1639
1666
  ? sharedFolderInstallSteps(pkg, folder)
1640
1667
  : renderNativeInstallWizard;
1641
- const install = renderInstallWizardFiles(pkg, t => [...steps(t), ...portInstallSteps({ package: pkg, ...(Object.keys(installPortDefinitions).length ? { installPorts: true } : {}) }, installPortDefinitions)(t), ...settingsInstallSteps(installSettings, settingsPort, Object.keys(installPortDefinitions).length ? pkg : undefined)(t), ...(portal ? [renderPortalWizardStep(t, portal.alias)] : []), ...integrationWizardSteps(t, integrations)]);
1668
+ const install = renderInstallWizardFiles(pkg, t => [...steps(t), ...portInstallSteps({ package: pkg, ...(Object.keys(installPortDefinitions).length ? { installPorts: true } : {}) }, installPortDefinitions)(t), ...settingsInstallSteps(installSettings, settingsPort, Object.keys(installPortDefinitions).length ? pkg : undefined)(t), ...(portal ? [renderPortalWizardStep(t, portal.alias)] : []), ...integrationWizardSteps(t, integrations)], minMemoryMb);
1642
1669
  return {
1643
1670
  ...install.static,
1644
1671
  ...install.dynamic,
1645
- ...renderUpgradeWizardFiles(pkg, folder, integrations),
1672
+ ...renderUpgradeWizardFiles(pkg, folder, integrations, minMemoryMb),
1646
1673
  };
1647
1674
  }
1648
1675
  function portalManifest(portal) {
@@ -0,0 +1,9 @@
1
+ import type { StandaloneError } from "./manifest.js";
2
+ import { type Locale } from "./i18n.js";
3
+ /** MiB of physical MemTotal, not free/available memory or a model allowlist. */
4
+ export declare function readMinMemoryMb(value: unknown, fail: (error: StandaloneError) => void): number | undefined;
5
+ /** Shared by wizard and preinst. A missing, malformed or unreadable read allows installation. */
6
+ export declare function renderMemoryProbe(minMemoryMb: number): string;
7
+ export declare function memoryReason(minMemoryMb: number, locale: Locale, actual: string): string;
8
+ /** Runs in preinst for both install and upgrade, before other SDK or App work, as the package account. */
9
+ export declare function renderMemoryHook(minMemoryMb?: number): string;
@@ -0,0 +1,52 @@
1
+ import { DSM_LANGS, LOCALES } from "./i18n.js";
2
+ import { translator } from "../build-spk/wizard-i18n.js";
3
+ const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
4
+ /** MiB of physical MemTotal, not free/available memory or a model allowlist. */
5
+ export function readMinMemoryMb(value, fail) {
6
+ if (value === undefined)
7
+ return undefined;
8
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 2147483647) {
9
+ fail({ code: "INSTALL_MIN_MEMORY_INVALID", message: "install.min_memory_mb must be a positive integer in MiB, at most 2147483647" });
10
+ return undefined;
11
+ }
12
+ return value;
13
+ }
14
+ /** Shared by wizard and preinst. A missing, malformed or unreadable read allows installation. */
15
+ export function renderMemoryProbe(minMemoryMb) {
16
+ return `synopkgland_memory_kb=$(LC_ALL=C awk '
17
+ $1 == "MemTotal:" { count++; if (NF == 3 && $2 ~ /^[0-9]+$/ && $2 > 0 && $3 == "kB") total = $2 }
18
+ END { if (count == 1 && total > 0) printf "%.0f", total; else exit 1 }
19
+ ' /proc/meminfo 2>/dev/null) || synopkgland_memory_kb=
20
+ synopkgland_memory_low=
21
+ if [ -n "$synopkgland_memory_kb" ]; then
22
+ synopkgland_memory_gb=$(LC_ALL=C awk -v kb="$synopkgland_memory_kb" 'BEGIN { printf "%.2f", kb / 1048576 }')
23
+ if LC_ALL=C awk -v kb="$synopkgland_memory_kb" 'BEGIN { exit !(kb < ${minMemoryMb * 1024}) }'; then
24
+ synopkgland_memory_low=1
25
+ fi
26
+ else
27
+ printf '%s\\n' '[INSTALL_MEMORY_READ_WARNING] Cannot read physical MemTotal; continuing installation' >&2
28
+ fi
29
+ `;
30
+ }
31
+ export function memoryReason(minMemoryMb, locale, actual) {
32
+ return translator(locale)("memory.required", { required: String(Math.ceil(minMemoryMb / 1024)), actual });
33
+ }
34
+ /** Runs in preinst for both install and upgrade, before other SDK or App work, as the package account. */
35
+ export function renderMemoryHook(minMemoryMb) {
36
+ if (minMemoryMb === undefined)
37
+ return "";
38
+ const cases = LOCALES.map(locale => ` ${locale}|${DSM_LANGS[locale]}) synopkgland_memory_format=${quote(memoryReason(minMemoryMb, locale, "%s"))} ;;`).join("\n");
39
+ return `${renderMemoryProbe(minMemoryMb)}if [ -n "$synopkgland_memory_low" ]; then
40
+ case "\${SYNOPKG_DSM_LANGUAGE:-enu}" in
41
+ ${cases}
42
+ *) synopkgland_memory_format=${quote(memoryReason(minMemoryMb, "en", "%s"))} ;;
43
+ esac
44
+ synopkgland_memory_message=$(printf "$synopkgland_memory_format" "$synopkgland_memory_gb")
45
+ printf '%s\\n' "$synopkgland_memory_message" >&2
46
+ if [ -n "\${SYNOPKG_TEMP_LOGFILE:-}" ]; then
47
+ printf '%s\\n' "$synopkgland_memory_message" > "$SYNOPKG_TEMP_LOGFILE" || :
48
+ fi
49
+ exit 1
50
+ fi
51
+ `;
52
+ }
@@ -1,4 +1,5 @@
1
1
  import { renderGatewayIngressCheck } from './native-gateway.js';
2
+ import { renderMemoryHook } from './install-memory.js';
2
3
  import { renderSettingsHook } from './install-settings.js';
3
4
  import { renderComposeRetainedData } from "../build-spk/compose-retained-data.js";
4
5
  import { renderNativeGatewayDiagnostic, renderNativeGatewayPortWait, renderNativeGatewayPrepare } from './native-gateway.js';
@@ -24,7 +25,7 @@ export function renderStandaloneScript(name, manifest) {
24
25
  }
25
26
  function renderStandaloneScriptPrefix(name, manifest) {
26
27
  const prepared = ['postinst', 'postupgrade'].includes(name) ? renderNativeGatewayPrepare(manifest) : '';
27
- return renderGatewayIngressCheck(manifest, name) + renderNativeGatewayDiagnostic(manifest, name) + renderNativeGatewayPortWait(manifest, name) + renderSettingsHook(name, manifest) + prepared;
28
+ return (name === 'preinst' ? renderMemoryHook(manifest.minMemoryMb) : '') + renderGatewayIngressCheck(manifest, name) + renderNativeGatewayDiagnostic(manifest, name) + renderNativeGatewayPortWait(manifest, name) + renderSettingsHook(name, manifest) + prepared;
28
29
  }
29
30
  /** Settings inspection peels its hook only at the position build's renderer writes.
30
31
  * The backend inspector then replays the entire remaining lifecycle script. */
@@ -116,6 +116,8 @@ export interface StandaloneManifest {
116
116
  sharedFolder?: SharedFolder;
117
117
  installSettings?: InstallSettings;
118
118
  installPorts?: true;
119
+ /** `install.min_memory_mb`: minimum physical MemTotal in MiB at install and upgrade. */
120
+ minMemoryMb?: number;
119
121
  /** `backup`: Hyper Backup application backup; on by default for native Apps, absent when opted out. */
120
122
  hyperBackup?: HyperBackup;
121
123
  /** Who may use the app at all; absent keeps the route policy alone. */
@@ -9,6 +9,7 @@ import { readRegistry, registryFile } from '../ctl/registry.js';
9
9
  import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
10
10
  import { nativeGatewaySdk } from "./native-gateway.js";
11
11
  import { portDefaults } from "./install-ports.js";
12
+ import { readMinMemoryMb } from "./install-memory.js";
12
13
  import { readPackageDependencies, packageDependencies, dependencyError } from "./package-dependencies.js";
13
14
  import { readInstallSettings } from './install-settings.js';
14
15
  import { auditGoRoutes } from './route-audit.js';
@@ -304,6 +305,7 @@ function readManifest(raw, c) {
304
305
  ? undefined
305
306
  : readSharedFolder(raw.install, (e) => c.fail(e.code, e.message));
306
307
  const installPorts = isRecord(raw.install) && raw.install.ports === true ? true : undefined;
308
+ const minMemoryMb = readMinMemoryMb(isRecord(raw.install) ? raw.install.min_memory_mb : undefined, e => c.fail(e.code, e.message));
307
309
  if (isRecord(raw.install) && raw.install.ports !== undefined && raw.install.ports !== true)
308
310
  c.fail("INSTALL_PORT_INVALID", "install.ports must be true when present");
309
311
  const installSettings = readInstallSettings(isRecord(raw.install) ? raw.install.settings : undefined, e => c.fail(e.code, e.message));
@@ -682,6 +684,7 @@ function readManifest(raw, c) {
682
684
  ...(sharedFolder ? { sharedFolder } : {}),
683
685
  ...(installSettings ? { installSettings } : {}),
684
686
  ...(installPorts ? { installPorts } : {}),
687
+ ...(minMemoryMb !== undefined ? { minMemoryMb } : {}),
685
688
  ...(hyperBackup ? { hyperBackup } : {}),
686
689
  ...(entry ? { entry } : {}),
687
690
  ...(integrations?.length ? { integrations } : {}),
@@ -39,7 +39,7 @@ export declare function renderSharedFolderUpgradeWizardFiles(pkg: string, folder
39
39
  * The upgrade wizard: the shared folder choice, then the service callbacks an
40
40
  * administrator re-approves on every upgrade. Empty without either.
41
41
  */
42
- export declare function renderUpgradeWizardFiles(pkg: string, folder: SharedFolder | undefined, integrations?: readonly string[]): Record<string, string>;
42
+ export declare function renderUpgradeWizardFiles(pkg: string, folder: SharedFolder | undefined, integrations?: readonly string[], minMemoryMb?: number): Record<string, string>;
43
43
  /** DSM substitutes wizard values and grants only the declared package account.
44
44
  * On upgrade, omitted values reuse DSM's saved installer variables. */
45
45
  export declare function sharedFolderResource(pkg: string, folder: SharedFolder): Record<string, unknown> | undefined;
@@ -2,7 +2,7 @@ import { DSM_LANGS, LOCALES } from "./i18n.js";
2
2
  import { existingShareValidator } from "../build-spk/share-validation.js";
3
3
  import { sharedFolderActivation, sharedFolderCombobox } from "../build-spk/share-combobox.js";
4
4
  import { renderWizardFiles, translator } from "../build-spk/wizard-i18n.js";
5
- import { integrationWizardSteps } from "../build-spk/install-wizard.js";
5
+ import { integrationWizardSteps, renderMemoryWizardCheck } from "../build-spk/install-wizard.js";
6
6
  const FIELDS = new Set(["mode", "key", "name", "permission"]);
7
7
  const KEY = /^[a-z][a-z0-9_]{0,31}$/;
8
8
  const RESERVED_KEY = /^(pkgwizard_|synopkg|change_)/;
@@ -16,10 +16,10 @@ export function readSharedFolder(value, fail) {
16
16
  fail({ code: "STANDALONE_SHARED_FOLDER_INVALID", message: `install.sharedFolder ${why}` });
17
17
  return undefined;
18
18
  };
19
- if (!isRecord(value) || Object.keys(value).some((key) => key !== "sharedFolder" && key !== "settings" && key !== "ports")) {
20
- return refuse(": only sharedFolder is allowed.");
19
+ if (!isRecord(value) || Object.keys(value).some((key) => !["sharedFolder", "settings", "ports", "min_memory_mb"].includes(key))) {
20
+ return refuse(": only sharedFolder, settings, ports and min_memory_mb are allowed.");
21
21
  }
22
- if (value.sharedFolder === undefined && (value.settings !== undefined || value.ports !== undefined))
22
+ if (value.sharedFolder === undefined && (value.settings !== undefined || value.ports !== undefined || value.min_memory_mb !== undefined))
23
23
  return undefined;
24
24
  const folder = value.sharedFolder;
25
25
  if (!isRecord(folder) || Object.keys(folder).some((key) => !FIELDS.has(key))) {
@@ -151,8 +151,8 @@ export function renderSharedFolderUpgradeWizardFiles(pkg, folder) {
151
151
  * The upgrade wizard: the shared folder choice, then the service callbacks an
152
152
  * administrator re-approves on every upgrade. Empty without either.
153
153
  */
154
- export function renderUpgradeWizardFiles(pkg, folder, integrations = []) {
155
- if (!folder && !integrations.length)
154
+ export function renderUpgradeWizardFiles(pkg, folder, integrations = [], minMemoryMb) {
155
+ if (!folder && !integrations.length && minMemoryMb === undefined)
156
156
  return {};
157
157
  const files = renderWizardFiles("upgrade_uifile", t => [
158
158
  ...(folder ? [sharedFolderStep(t("upgrade.step"), upgradeItems(t, pkg, folder), folder)] : []),
@@ -172,6 +172,13 @@ export function renderUpgradeWizardFiles(pkg, folder, integrations = []) {
172
172
  files[name] = sharedFolderUpgradeScript(pkg, folder.key, retained, fresh, invalid);
173
173
  }
174
174
  }
175
+ if (minMemoryMb !== undefined) {
176
+ for (const locale of LOCALES) {
177
+ const name = locale === "en" ? "upgrade_uifile" : `upgrade_uifile_${DSM_LANGS[locale]}`;
178
+ const script = files[name + ".sh"] ?? `#!/bin/sh\n[ -z "\${SYNOPKG_TEMP_LOGFILE:-}" ] || exec > "$SYNOPKG_TEMP_LOGFILE"\ncat <<'SYNOPKGLAND_UPGRADE_WIZARD'\n${files[name]}\nSYNOPKGLAND_UPGRADE_WIZARD\n`;
179
+ files[name + ".sh"] = script.replace("#!/bin/sh\n", () => "#!/bin/sh\n" + renderMemoryWizardCheck(minMemoryMb, locale));
180
+ }
181
+ }
175
182
  return files;
176
183
  }
177
184
  /** DSM substitutes wizard values and grants only the declared package account.
@@ -303,6 +303,7 @@ export async function assembleStandaloneSpk(options) {
303
303
  ...(moduleVersion ? { ui_module: moduleVersion } : {}),
304
304
  ...(manifest.installSettings ? { installSettings: manifest.installSettings } : {}),
305
305
  ...(manifest.installPorts ? { installPorts: portDefaults(manifest) } : {}),
306
+ ...(manifest.minMemoryMb !== undefined ? { minMemoryMb: manifest.minMemoryMb } : {}),
306
307
  ...(backup ? { hyperBackup: backupRecord(backup) } : {}),
307
308
  ...(manifest.integrations ? { integrations: manifest.integrations } : {}),
308
309
  ...(manifest.lifecycleTimeouts ? { lifecycleTimeouts: manifest.lifecycleTimeouts } : {}),
@@ -374,11 +375,11 @@ export async function assembleStandaloneSpk(options) {
374
375
  : folder
375
376
  ? sharedFolderInstallSteps(manifest.package, folder)
376
377
  : renderNativeInstallWizard;
377
- const install = renderInstallWizardFiles(manifest.package, (t) => [...steps(t), ...portInstallSteps(manifest)(t), ...settingsInstallSteps(manifest.installSettings, manifest.identityGateway?.listen.https, manifest.installPorts ? manifest.package : undefined)(t), ...(portal ? [renderPortalWizardStep(t, portal.alias)] : []), ...integrationWizardSteps(t, manifest.integrations)]);
378
+ const install = renderInstallWizardFiles(manifest.package, (t) => [...steps(t), ...portInstallSteps(manifest)(t), ...settingsInstallSteps(manifest.installSettings, manifest.identityGateway?.listen.https, manifest.installPorts ? manifest.package : undefined)(t), ...(portal ? [renderPortalWizardStep(t, portal.alias)] : []), ...integrationWizardSteps(t, manifest.integrations)], manifest.minMemoryMb);
378
379
  writeWizardUiFiles(staging, {
379
380
  ...install.static,
380
381
  ...install.dynamic,
381
- ...renderUpgradeWizardFiles(manifest.package, folder, manifest.integrations),
382
+ ...renderUpgradeWizardFiles(manifest.package, folder, manifest.integrations, manifest.minMemoryMb),
382
383
  ...renderUninstallWizardFiles(manifest.package, "native", {
383
384
  composeData: manifest.compose?.plan.app_data,
384
385
  executor: Boolean(options.executor),
@@ -0,0 +1,20 @@
1
+ # Minimum physical memory
2
+
3
+ Declare a physical RAM requirement in `dsm-package.yaml`:
4
+
5
+ ```yaml
6
+ install:
7
+ min_memory_mb: 1700
8
+ ```
9
+
10
+ `min_memory_mb` is a positive integer threshold in **MiB** (1–2147483647), measured against `/proc/meminfo` **MemTotal** on the NAS at installation time. It measures physical memory visible to DSM, independently of free memory, swap, model names and the package server's architecture filters. RAM upgrades are detected automatically.
11
+
12
+ MemTotal excludes firmware and kernel reservations. Set the threshold to approximately **85% of the nominal capacity** when all machines of that capacity should work: use **1700 MiB for 2 GB NAS machines**, rather than 2048 MiB. Check the intended hardware's MemTotal before choosing a threshold. The requirement label rounds the threshold up to a whole GB (1700 MiB displays as 2 GB); the detected capacity uses two decimal places. Both use DSM's 1024-based convention, so displayed GB means 1024 MiB. The exact threshold, rather than the rounded label, controls admission.
13
+
14
+ The existing dynamic install and upgrade wizards read MemTotal on the NAS. Below the threshold they show a localized memory page in every supported wizard language, with a read-only field that always fails validation and `invalid_next_disabled_v2` to disable Next on DSM flows that honor it. Static fallback wizards retain their usual pages because they cannot know the NAS memory. CLI installation, wizard bypasses and DSM flows that do not honor wizard validation remain covered by preinst.
15
+
16
+ The generated **package-account preinst** checks the same threshold before other SDK work and the App's preinst hook, for **both installation and upgrade**. A low-memory result exits nonzero and writes the same localized reason to `SYNOPKG_TEMP_LOGFILE` for Package Center. Upgrade admission uses the incoming package's requirement even if an earlier version installed successfully. No root helper or runtime/start check is added.
17
+
18
+ An unreadable, missing or malformed MemTotal emits `INSTALL_MEMORY_READ_WARNING` to stderr and **allows installation**. This requirement stops clearly undersized machines; it does not reject an unfamiliar memory-reporting environment. Omitting the field preserves the existing installation behavior. `synopkgland inspect <spk> --json` reports `minMemoryMb` and verifies the generated memory check and wizard files against the packaged declaration.
19
+
20
+ See Synology's [wizard contract](https://help.synology.com/developer-guide/synology_package/wizard/WIZARD_UIFILES_v2.html) for dynamic wizard scripts and the `SYNOPKG_TEMP_LOGFILE` output channel.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.52.11",
3
+ "version": "0.52.13",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,8 @@
22
22
  "skills",
23
23
  "docs/shared-folders.md",
24
24
  "docs/daemon-nofile.md",
25
- "docs/compose-admin.md"
25
+ "docs/compose-admin.md",
26
+ "docs/install-memory.md"
26
27
  ],
27
28
  "scripts": {
28
29
  "check:docs": "node --test scripts/check-doc-versions.test.mjs && node scripts/check-doc-versions.mjs",
@@ -7,6 +7,21 @@
7
7
  "required": ["schema"],
8
8
  "properties": {
9
9
  "schema": {"type": "integer", "const": 2},
10
+ "install": {
11
+ "type": "object",
12
+ "properties": {
13
+ "min_memory_mb": {
14
+ "type": "integer",
15
+ "minimum": 1,
16
+ "maximum": 2147483647,
17
+ "description": "Minimum physical /proc/meminfo MemTotal in MiB, checked dynamically on install and upgrade as the package account. Allow for firmware reservations: use about 85% of nominal RAM (1700 for a 2 GB NAS). Read failures warn and allow installation. No runtime check."
18
+ },
19
+ "sharedFolder": {"type": "object"},
20
+ "settings": {"type": "object"},
21
+ "ports": {"const": true}
22
+ },
23
+ "additionalProperties": false
24
+ },
10
25
  "ui_secret_ignores": {
11
26
  "description": "False-positive exceptions for public UI secret scanning. Exact paths relative to ui/; omit a module snapshot hash (app/help.json). Source maps cannot be ignored.",
12
27
  "type": "array",
package/skills/SKILL.md CHANGED
@@ -40,6 +40,8 @@ Query published releases with `npm view @synopackageland/cli version`,
40
40
  `npm view @synopackageland/templates version` and `npm view @synopackageland/sdk version`;
41
41
  keep the installed dependency tree and generated pins consistent.
42
42
 
43
+ For Apps with a physical RAM requirement, set `install.min_memory_mb` (MemTotal in MiB; use 1700 for 2 GB machines). The generated install/upgrade wizards and package-account preinst check it dynamically; read failures warn and allow installation, with no runtime check. See [minimum physical memory](../docs/install-memory.md).
44
+
43
45
  For Apps with data folders or gateway listeners, read [reference/install.md](reference/install.md). Default to an App-named dedicated DSM data share and installer-selected ports. Existing-folder access, port number format/range and required HTTPS origins use localized wizard validation before Next; detected port conflicts are nonblocking inline warnings, and an unavailable DSM port inventory does not block installation; upgrades retain port selections.
44
46
 
45
47
  For private native `<audio>` / `<video>` playback and seeking, read
@@ -6,6 +6,7 @@ Use matching CLI, SDK/App and templates releases, preserving the pins generated
6
6
 
7
7
  ```yaml
8
8
  install:
9
+ min_memory_mb: 1700
9
10
  ports: true
10
11
  sharedFolder:
11
12
  mode: dedicated
@@ -17,6 +18,8 @@ identity_gateway:
17
18
  listen: {https: 28443}
18
19
  ```
19
20
 
21
+ Use `install.min_memory_mb` for a physical RAM requirement checked dynamically on the NAS during install and upgrade. The value is MemTotal in MiB, so allow for firmware reservations: 1700 MiB admits 2 GB machines. All wizard locales show a low-memory page; package-account preinst enforces the same threshold through Package Center. Unreadable MemTotal warns and allows installation; no runtime check is added. See [minimum physical memory](../../docs/install-memory.md).
22
+
20
23
  For every App needing shared data, name the dedicated share after the package. The wizard defaults to that name, keeps it when the share list loads, and reuses the matching share if it exists. It also accepts a supported existing share. `mode: select` starts empty and requires an explicit choice; `mode: create` has no picker. Selecting a folder authorizes DSM's `data-share` worker to grant the declared RO/RW to the package account on install, upgrade/repair and starts. No pre-existing account or permission grant is required. Validation checks the name, existence and supported local mounted folder type, never package-account access. Local tiered/S2S shares are accepted; remote/C2, tiering buckets, WORM, unmounted, unavailable, moving, external and forced-read-only shares are refused. Runtime kernel checks still report the share, required access and recovery action when permission is revoked. No App root or ACL writer is generated.
21
24
 
22
25
  The upgrade wizard prefills and submits the recorded folder without a separate change checkbox. Keep the dedicated name rather than clearing it. CLI automation uses `--param media=Media` on install and `--param CHANGE_media=true --param media=OtherMedia` to change it on upgrade/repair. Explicitly submit the saved folder when migrating older installations without saved DSM installer values.