diff --git a/commands/project/exec.sh b/commands/project/exec.sh index 35b7175..09a2d04 100755 --- a/commands/project/exec.sh +++ b/commands/project/exec.sh @@ -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() { diff --git a/commands/project/exec/root.sh b/commands/project/exec/root.sh deleted file mode 100755 index 92930b7..0000000 --- a/commands/project/exec/root.sh +++ /dev/null @@ -1,21 +0,0 @@ -## Opens privileged shell on first container -# -# Command -# project:exec:root -# p:e:r -# exec-root - -function project:exec:root() { - _checkProject - ${DOCKER_COMPOSE} exec $(docker run --rm -v $(pwd):/workdir mikefarah/yq:3 yq r --printMode p docker-compose.yml 'services.*' | head -n1 | sed 's/.*\.//') sh -} - -function p:e:r() { - project:exec:root -} - -function exec-root() { - project:exec:root -} - - diff --git a/commands/project/shell.sh b/commands/project/shell.sh new file mode 100755 index 0000000..6930d1a --- /dev/null +++ b/commands/project/shell.sh @@ -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} +} diff --git a/commands/project/shell/root.sh b/commands/project/shell/root.sh new file mode 100755 index 0000000..84dc75f --- /dev/null +++ b/commands/project/shell/root.sh @@ -0,0 +1,36 @@ +## Opens privileged shell on first container +# +# Command +# project:shell:root +# s:e:r +# shell-root + +function project:shell:root() { + _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 "sh" +} + +function p:s:r() { + project:shell:root ${1} +} + +function shell:root() { + project:shell:root ${1} +}