Skip to content

Commit

Permalink
feat: move exec to shell
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaerlocher committed Feb 22, 2024
1 parent cbf1a84 commit ac5ebb0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 40 deletions.
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
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
}

0 comments on commit ac5ebb0

Please sign in to comment.