mirror of
https://github.com/whyour/qinglong.git
synced 2026-02-12 22:16:42 +08:00
Modify linkCommand to create symlinks in ~/bin for non-root users
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
9c2fbb3788
commit
9824ecfbcc
|
|
@ -1,5 +1,6 @@
|
|||
import path from 'path';
|
||||
import fs from 'fs/promises';
|
||||
import os from 'os';
|
||||
import chokidar from 'chokidar';
|
||||
import config from '../config/index';
|
||||
import { fileExist, promiseExec, rmPath } from '../config/util';
|
||||
|
|
@ -17,8 +18,24 @@ async function linkToNodeModule(src: string, dst?: string) {
|
|||
}
|
||||
|
||||
async function linkCommand() {
|
||||
const homeDir = os.homedir();
|
||||
const userBinDir = path.join(homeDir, 'bin');
|
||||
|
||||
// Create ~/bin directory if it doesn't exist
|
||||
try {
|
||||
await fs.mkdir(userBinDir, { recursive: true });
|
||||
} catch (error) {
|
||||
// If we can't create ~/bin, fall back to system directory
|
||||
const commandPath = await promiseExec('which node');
|
||||
const commandDir = path.dirname(commandPath);
|
||||
await linkCommandToDir(commandDir);
|
||||
return;
|
||||
}
|
||||
|
||||
await linkCommandToDir(userBinDir);
|
||||
}
|
||||
|
||||
async function linkCommandToDir(commandDir: string) {
|
||||
const linkShell = [
|
||||
{
|
||||
src: 'update.sh',
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Add ~/bin to PATH for non-root users
|
||||
export PATH="$HOME/bin:$PATH"
|
||||
|
||||
dir_shell=/ql/shell
|
||||
. $dir_shell/share.sh
|
||||
. $dir_shell/env.sh
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user