From ac5ebb05720be9d504512c46e324126ac8b9f7be Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Thu, 22 Feb 2024 15:09:18 +0100 Subject: [PATCH 1/3] feat: move exec to shell --- commands/project/exec.sh | 20 +----------------- commands/project/exec/root.sh | 21 ------------------- commands/project/shell.sh | 38 ++++++++++++++++++++++++++++++++++ commands/project/shell/root.sh | 36 ++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 40 deletions(-) delete mode 100755 commands/project/exec/root.sh create mode 100755 commands/project/shell.sh create mode 100755 commands/project/shell/root.sh 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..c2f563d --- /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:e:r() { + project:shell:root +} + +function shell-root() { + project:shell:root +} From 48567e2ec1b2cd3adbcf43e8be671c9f67d6d08c Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Thu, 22 Feb 2024 17:10:09 +0100 Subject: [PATCH 2/3] fix: commands --- commands/project/shell/root.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/project/shell/root.sh b/commands/project/shell/root.sh index c2f563d..efddb42 100755 --- a/commands/project/shell/root.sh +++ b/commands/project/shell/root.sh @@ -27,10 +27,10 @@ function project:shell:root() { ${DOCKER_COMPOSE} exec ${service} /bin/sh -c "sh" } -function p:e:r() { +function p:s:r() { project:shell:root } -function shell-root() { +function shell:root() { project:shell:root } From edc5d50d77bdc3468bd44f82453daa2b35e58904 Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Fri, 23 Feb 2024 14:19:19 +0100 Subject: [PATCH 3/3] fix: feedback --- commands/project/shell/root.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/project/shell/root.sh b/commands/project/shell/root.sh index efddb42..84dc75f 100755 --- a/commands/project/shell/root.sh +++ b/commands/project/shell/root.sh @@ -28,9 +28,9 @@ function project:shell:root() { } function p:s:r() { - project:shell:root + project:shell:root ${1} } function shell:root() { - project:shell:root + project:shell:root ${1} }