Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhanced Project Interaction with exec.sh to shell.sh Transition #66

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions commands/project/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@
# Arguments
# service optional, open shell of service, default open first container
function project:exec() {
_checkProject
local service=$(docker run --rm -v $(pwd):/workdir mikefarah/yq:3 yq r --printMode p docker-compose.yml 'services.*' | head -n1 | sed 's/.*\.//')

if [[ "${1}" != "" ]]; then
if _serviceExists ${1}; then
service=${1}
else
_logRed "service ${1} does not exists in project"
_existingServices
return 1
fi
fi

if ! _serviceIsRunning ${service}; then
_logYellow "Project is not running. Starting ..."
project:up
fi

${DOCKER_COMPOSE} exec ${service} /bin/sh -c "if [ -f /usr/bin/doas ]; then doas -u dde sh; else gosu dde sh; fi"
_logYellow "Please note that the command exec has been renamed to 'shell' in the script."
}

function p:e() {
Expand Down
21 changes: 0 additions & 21 deletions commands/project/exec/root.sh

This file was deleted.

38 changes: 38 additions & 0 deletions commands/project/shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Opens shell with user dde on first container
#
# Command
# project:shell
# p:s
# shell

# Arguments
# service optional, open shell of service, default open first container
function project:shell() {
_checkProject
local service=$(docker run --rm -v $(pwd):/workdir mikefarah/yq:3 yq r --printMode p docker-compose.yml 'services.*' | head -n1 | sed 's/.*\.//')

if [[ "${1}" != "" ]]; then
if _serviceExists ${1}; then
service=${1}
else
_logRed "service ${1} does not exists in project"
_existingServices
return 1
fi
fi

if ! _serviceIsRunning ${service}; then
_logYellow "Project is not running. Starting ..."
project:up
fi

${DOCKER_COMPOSE} exec ${service} /bin/sh -c "if [ -f /usr/bin/doas ]; then doas -u dde sh; else gosu dde sh; fi"
}

function p:s() {
project:shell ${1}
}

function shell() {
project:shell ${1}
}
36 changes: 36 additions & 0 deletions commands/project/shell/root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Opens privileged shell on first container
#
# Command
# project:shell:root
# s:e:r
# shell-root

function project:shell:root() {
_checkProject
s4mpl3d marked this conversation as resolved.
Show resolved Hide resolved
local service=$(docker run --rm -v $(pwd):/workdir mikefarah/yq:3 yq r --printMode p docker-compose.yml 'services.*' | head -n1 | sed 's/.*\.//')

if [[ "${1}" != "" ]]; then
if _serviceExists ${1}; then
service=${1}
else
_logRed "service ${1} does not exists in project"
_existingServices
return 1
fi
fi

if ! _serviceIsRunning ${service}; then
_logYellow "Project is not running. Starting ..."
project:up
fi

${DOCKER_COMPOSE} exec ${service} /bin/sh -c "sh"
}

function p:s:r() {
project:shell:root
s4mpl3d marked this conversation as resolved.
Show resolved Hide resolved
}

function shell:root() {
project:shell:root
}