@lethevimlet/sshift 1.7.6 → 1.7.7
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/package.json +1 -1
- package/src/server/index.js +6 -1
- package/src/server/utils/config.js +60 -3
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -25,7 +25,7 @@ const selfsigned = require('selfsigned');
|
|
|
25
25
|
const httpolyglot = require('httpolyglot');
|
|
26
26
|
|
|
27
27
|
// Import utilities
|
|
28
|
-
const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getHttpRedirect, getCertPath, getKeyPath, getDataDir, getLegacyDataDir, isPasswordSet, USER_INSTALL_DIR } = require('./utils/config');
|
|
28
|
+
const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getHttpRedirect, getCertPath, getKeyPath, getDataDir, getLegacyDataDir, isPasswordSet, USER_INSTALL_DIR, migrateLegacyPackageConfig } = require('./utils/config');
|
|
29
29
|
|
|
30
30
|
// Import services
|
|
31
31
|
const { sshManager, sftpManager } = require('./services');
|
|
@@ -214,6 +214,11 @@ let actuallyHttps = false;
|
|
|
214
214
|
|
|
215
215
|
// Async initialization function
|
|
216
216
|
async function initializeServer() {
|
|
217
|
+
// Rescue legacy package-directory configs BEFORE anything else: they
|
|
218
|
+
// are destroyed by the next `npm install -g` (GUI update). Must run
|
|
219
|
+
// before ensureConfig(), which would otherwise consider the package-
|
|
220
|
+
// dir config "existing" and skip creating the durable user-space one.
|
|
221
|
+
migrateLegacyPackageConfig();
|
|
217
222
|
ensureConfig();
|
|
218
223
|
|
|
219
224
|
if (enableHttps) {
|
|
@@ -11,8 +11,16 @@ const crypto = require('crypto');
|
|
|
11
11
|
// Get user's home directory
|
|
12
12
|
const HOME_DIR = os.homedir();
|
|
13
13
|
|
|
14
|
-
// User install directory for config
|
|
15
|
-
|
|
14
|
+
// User install directory for config. SSHIFT_DATA_DIR overrides it — used
|
|
15
|
+
// by the Docker image to point the app at a mounted volume so that
|
|
16
|
+
// config.json (bookmarks, folders, settings) and the self-signed
|
|
17
|
+
// certificates survive container recreation on image updates. Without
|
|
18
|
+
// it, a Docker install writes to $HOME/.local/share/sshift inside the
|
|
19
|
+
// container's ephemeral writable layer and loses everything whenever the
|
|
20
|
+
// container is recreated (docker compose pull && up -d).
|
|
21
|
+
const USER_INSTALL_DIR = process.env.SSHIFT_DATA_DIR
|
|
22
|
+
? path.resolve(process.env.SSHIFT_DATA_DIR)
|
|
23
|
+
: path.join(HOME_DIR, '.local', 'share', 'sshift');
|
|
16
24
|
|
|
17
25
|
// Config paths - prioritize package directory, then user install directory
|
|
18
26
|
const PACKAGE_DIR = path.join(__dirname, '..', '..', '..');
|
|
@@ -302,7 +310,55 @@ function getDataDir() {
|
|
|
302
310
|
}
|
|
303
311
|
|
|
304
312
|
/**
|
|
305
|
-
*
|
|
313
|
+
* Legacy package-directory config migration.
|
|
314
|
+
*
|
|
315
|
+
* Versions before ~v1.3.x (pre May 2026) created config.json INSIDE the
|
|
316
|
+
* npm package directory (<npm-global>/node_modules/@lethevimlet/sshift/).
|
|
317
|
+
* The search order still prefers those paths, so legacy installs keep
|
|
318
|
+
* working — but they are a time bomb: `npm install -g` (used by the GUI
|
|
319
|
+
* update and manual updates) replaces the package directory wholesale
|
|
320
|
+
* and DESTROYS such configs (verified: bookmarks vanish on update).
|
|
321
|
+
*
|
|
322
|
+
* This copies a legacy package-dir config to the user install directory
|
|
323
|
+
* (which survives npm updates) BEFORE an update can delete it. The
|
|
324
|
+
* package-dir file is left in place (it still wins the search order),
|
|
325
|
+
* but once an update removes it the user-space copy takes over
|
|
326
|
+
* seamlessly with all bookmarks/folders/settings intact.
|
|
327
|
+
*
|
|
328
|
+
* No-op when a user-space config already exists or when no package-dir
|
|
329
|
+
* config is present.
|
|
330
|
+
*
|
|
331
|
+
* @returns {string|null} Path the config was migrated to, or null
|
|
332
|
+
*/
|
|
333
|
+
function migrateLegacyPackageConfig() {
|
|
334
|
+
const userConfigPath = path.join(USER_INSTALL_DIR, '.env', 'config.json');
|
|
335
|
+
if (fs.existsSync(userConfigPath)) return null;
|
|
336
|
+
|
|
337
|
+
const legacyPaths = [
|
|
338
|
+
path.join(PACKAGE_DIR, '.env', 'config.json'),
|
|
339
|
+
path.join(PACKAGE_DIR, 'config.json'),
|
|
340
|
+
];
|
|
341
|
+
|
|
342
|
+
for (const legacyPath of legacyPaths) {
|
|
343
|
+
if (fs.existsSync(legacyPath)) {
|
|
344
|
+
try {
|
|
345
|
+
fs.mkdirSync(path.dirname(userConfigPath), { recursive: true });
|
|
346
|
+
fs.copyFileSync(legacyPath, userConfigPath);
|
|
347
|
+
console.log('[CONFIG] Legacy package-directory config detected — copied to', userConfigPath);
|
|
348
|
+
console.log('[CONFIG] The package-dir copy is left in place; the user-space copy now');
|
|
349
|
+
console.log('[CONFIG] guarantees settings/bookmarks survive the next npm update.');
|
|
350
|
+
return userConfigPath;
|
|
351
|
+
} catch (e) {
|
|
352
|
+
console.warn('[CONFIG] Failed to migrate package-directory config:', e.message);
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Get legacy data directory (package directory) used before
|
|
306
362
|
* certs were moved to user space. Used for migration only.
|
|
307
363
|
* @returns {string|null} Path to legacy data directory, or null if N/A
|
|
308
364
|
*/
|
|
@@ -476,6 +532,7 @@ module.exports = {
|
|
|
476
532
|
getConfigPath,
|
|
477
533
|
loadConfig,
|
|
478
534
|
saveConfig,
|
|
535
|
+
migrateLegacyPackageConfig,
|
|
479
536
|
getPort,
|
|
480
537
|
getBindAddress,
|
|
481
538
|
getSSHKeepaliveSettings,
|