Files
linux-odyssey/server/quests/helloworld/home/.bashrc
T
wancat d997a061a9 feat: send command typed in container to API
- Modify the Dockerfile in the `server/quests/helloworld` directory to add a user and change the working directory
- Rename the file `server/quests/helloworld/entrypoint.sh` to `server/quests/helloworld/home/.bashrc`
- Modify the `server/src/config.js` file to add the `isProduction` flag
- Modify the `server/src/utils/docker.js` file to add a `HostConfig` option and bind a directory if not in production mode
- Modify the Dockerfile to add an argument `DOCKER_GID` and create a group and user with the specified `DOCKER_GID`
- Add a new Dockerfile.dev file with the same modifications as the Dockerfile
- Add a new file `inspect.sh`
- Modify the `server/src/client.js` file to use the `API_ENDPOINT` variable instead of a hardcoded URL

Signed-off-by: wancat <wancat@wancat.cc>
2023-07-26 20:54:01 +08:00

17 lines
597 B
Bash

# This function will be called before each command is executed
preexec() {
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # do nothing if completing
local command="$BASH_COMMAND"
local pwd="$PWD"
# Store command in variable
local cmd=$(printf '{"token": "%s", "pwd": "%s", "command": "%s"}' "$TOKEN" "$pwd" "$command")
# Send command to the API
curl -X POST $API_ENDPOINT/api/v1/commands -H 'accept: */*' -H 'Content-Type: application/json' -d "$cmd"
}
# Install the trap
trap 'preexec' DEBUG