mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e37b13d99 | ||
|
|
b2a251576c |
No files matched your search
+29
-8
@@ -1,24 +1,39 @@
|
|||||||
PROMPT='%F{2}%n%f:%F{6}%~%f $ '
|
PROMPT='%F{2}%n%f:%F{6}%~%f $ '
|
||||||
unsetopt CASE_GLOB
|
unsetopt CASE_GLOB
|
||||||
setopt CHASE_LINKS
|
setopt CHASE_LINKS
|
||||||
emulate bash
|
# emulate bash
|
||||||
|
|
||||||
set +o prompt_cr
|
set +o prompt_cr
|
||||||
|
|
||||||
preexec() {
|
preexec() {
|
||||||
export CMD_START_TIME=$(date +%s%N) # capture start time
|
export CMD_START_TIME=$(date +%s%N) # capture start time
|
||||||
export CMD_NAME=$1 # capture command
|
export CMD_NAME="$1" # capture command
|
||||||
|
export CMD_PID=$$
|
||||||
|
|
||||||
# A list of interactive commands
|
# # A list of interactive commands
|
||||||
interactive_commands=("vim" "nano" "top" "ssh" "less" "zsh" "bash")
|
# readlink /proc/$PPID/exe
|
||||||
|
interactive_commands=("vim" "nano" "top" "ssh" "less" "zsh" "bash" "script" "exec")
|
||||||
|
# # if [[ $CMD_EXECUTED = 1 ]]; then
|
||||||
|
# # export CMD_EXECUTED=0
|
||||||
|
# # return
|
||||||
|
# # fi
|
||||||
|
|
||||||
# Check if the command is in the list of interactive commands
|
# # Check if the command is in the list of interactive commands
|
||||||
if [[ " ${interactive_commands[@]} " =~ " $1 " ]]; then
|
if [[ " ${interactive_commands[@]} " =~ " $1 " ]]; then
|
||||||
# If it is, just execute it normally
|
# If it is, just execute it normally
|
||||||
exec
|
# exec
|
||||||
|
# echo IF
|
||||||
|
return
|
||||||
else
|
else
|
||||||
# If it's not, execute it and redirect its output to a file
|
# If it's not, execute it and redirect its output to a file
|
||||||
exec > >(tee /tmp/cmd.out) 2> >(tee /tmp/cmd.error >&2)
|
# exec > >(tee /tmp/cmd.out) 2> >(tee /tmp/cmd.error >&2)
|
||||||
|
# echo ELSE
|
||||||
|
# export CMD_EXECUTED=1
|
||||||
|
# eval >&1 >/tmp/cmd.out
|
||||||
|
# exec >&1
|
||||||
|
# exec
|
||||||
|
script --quiet -O /tmp/cmd.out -c "$CMD_NAME"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +44,12 @@ precmd() {
|
|||||||
export CMD_ERROR_FILE=/tmp/cmd.error
|
export CMD_ERROR_FILE=/tmp/cmd.error
|
||||||
|
|
||||||
# Now run your Node.js script with the result as an argument
|
# Now run your Node.js script with the result as an argument
|
||||||
node /usr/local/lib/container/cli.js; rm /tmp/cmd.out /tmp/cmd.error 2>/dev/null
|
node /usr/local/lib/container/cli.js
|
||||||
|
if [[ -n $CMD_PID ]]; then
|
||||||
|
# echo $CMD_PID
|
||||||
|
# kill $CMD_PID
|
||||||
|
fi
|
||||||
|
# rm /tmp/cmd.out /tmp/cmd.error 2>/dev/null
|
||||||
|
|
||||||
# Reset variables
|
# Reset variables
|
||||||
unset CMD_START_TIME
|
unset CMD_START_TIME
|
||||||
@@ -38,5 +58,6 @@ precmd() {
|
|||||||
unset CMD_OUTPUT_FILE
|
unset CMD_OUTPUT_FILE
|
||||||
unset CMD_ERROR_FILE
|
unset CMD_ERROR_FILE
|
||||||
unset CMD_NAME
|
unset CMD_NAME
|
||||||
|
export CMD_EXECUTED=0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ import { asyncHandler } from '../../middleware/error.js'
|
|||||||
|
|
||||||
export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
||||||
const { command, pwd, output, error, params } = matchedData(req)
|
const { command, pwd, output, error, params } = matchedData(req)
|
||||||
|
console.log(command, output, error)
|
||||||
|
|
||||||
const { sessionId } = req.user as any
|
const { sessionId } = req.user as any
|
||||||
const session = await Session.findById(sessionId)
|
const session = await Session.findById(sessionId)
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ export async function createContainer(
|
|||||||
imageId: string
|
imageId: string
|
||||||
): Promise<Docker.Container> {
|
): Promise<Docker.Container> {
|
||||||
let binds: string[] = []
|
let binds: string[] = []
|
||||||
|
binds.push(
|
||||||
|
`${config.docker.hostProjectRoot}/quests/.includes/zshrc:/etc/zsh/zshrc`
|
||||||
|
)
|
||||||
if (await questHomeExists(questId)) {
|
if (await questHomeExists(questId)) {
|
||||||
logger.info('Mounting quest home', questId)
|
logger.info('Mounting quest home', questId)
|
||||||
binds.push(
|
binds.push(
|
||||||
|
|||||||
Reference in new issue
Block a user