diff --git a/pkg/docker/start.go b/pkg/docker/start.go index 4a955b8ab2..d10d993ab5 100644 --- a/pkg/docker/start.go +++ b/pkg/docker/start.go @@ -51,7 +51,7 @@ func (d *DockerClient) startDaytonaAgent(p *project.Project, containerUser, dayt go func() { result, err := d.ExecSync(d.GetProjectContainerName(p), container.ExecOptions{ - Cmd: []string{"bash", "-c", util.GetProjectStartScript(daytonaDownloadUrl, p.ApiKey)}, + Cmd: []string{"sh", "-c", util.GetProjectStartScript(daytonaDownloadUrl, p.ApiKey)}, AttachStdout: true, AttachStderr: true, User: containerUser, diff --git a/pkg/docker/start_test.go b/pkg/docker/start_test.go index 943fe450ef..72a4574155 100644 --- a/pkg/docker/start_test.go +++ b/pkg/docker/start_test.go @@ -41,7 +41,7 @@ func (s *DockerClientTestSuite) TestStartProject() { }, }, nil) - s.setupExecTest([]string{"bash", "-c", util.GetProjectStartScript("", project1.ApiKey)}, containerName, project1.User, []string{}, "Daytona Agent started") + s.setupExecTest([]string{"sh", "-c", util.GetProjectStartScript("", project1.ApiKey)}, containerName, project1.User, []string{}, "Daytona Agent started") err := s.dockerClient.StartProject(&docker.CreateProjectOptions{ Project: project1, diff --git a/pkg/provider/util/project_start_script.go b/pkg/provider/util/project_start_script.go index dc2bac4b86..f3d86dfc11 100644 --- a/pkg/provider/util/project_start_script.go +++ b/pkg/provider/util/project_start_script.go @@ -5,6 +5,101 @@ package util import "fmt" +const INSTALL_DEPENDENCIES_SCRIPT = ` +# List of supported package managers +PACKAGE_MANAGERS="apt-get yum dnf apk brew pacman" + +# Check if sudo exists +if ! command -v sudo >/dev/null 2>&1; then + echo "Sudo not found." + + for pm in $PACKAGE_MANAGERS; do + if command -v "$pm" >/dev/null 2>&1; then + echo "Trying to install sudo using $pm..." + + case "$pm" in + apt-get) + apt-get update >/dev/null 2>&1 + apt-get install -y sudo >/dev/null 2>&1 + ;; + yum) + yum install -y sudo >/dev/null 2>&1 + ;; + dnf) + dnf install -y sudo >/dev/null 2>&1 + ;; + apk) + apk add --no-cache sudo >/dev/null 2>&1 + ;; + brew) + brew install sudo >/dev/null 2>&1 + ;; + pacman) + pacman -Sy --noconfirm sudo >/dev/null 2>&1 + ;; + esac + + if command -v sudo >/dev/null 2>&1; then + break + fi + fi + done +fi + +# Verify sudo is working +if ! sudo -v; then + echo "Failed to configure sudo. Check system permissions." + exit 1 +fi + +# Check for missing dependencies +DEPENDENCIES="curl bash git" +MISSING_DEPS="" + +for dep in $DEPENDENCIES; do + if ! command -v "$dep" >/dev/null 2>&1; then + MISSING_DEPS="$MISSING_DEPS $dep" + fi +done + +# Install missing dependencies +if test -n "$MISSING_DEPS"; then + echo "Missing dependencies:$MISSING_DEPS" + + for pm in $PACKAGE_MANAGERS; do + if command -v "$pm" >/dev/null 2>&1; then + case "$pm" in + apt-get) + sudo apt-get update >/dev/null 2>&1 + sudo apt-get install -y $MISSING_DEPS >/dev/null 2>&1 + ;; + yum) + sudo yum install -y $MISSING_DEPS >/dev/null 2>&1 + ;; + dnf) + sudo dnf install -y $MISSING_DEPS >/dev/null 2>&1 + ;; + apk) + sudo apk add --no-cache $MISSING_DEPS libc6-compat >/dev/null 2>&1 + ;; + brew) + sudo brew install $MISSING_DEPS >/dev/null 2>&1 + ;; + pacman) + sudo pacman -Sy --noconfirm $MISSING_DEPS >/dev/null 2>&1 + ;; + esac + + break + fi + done +fi +` + func GetProjectStartScript(daytonaDownloadUrl string, apiKey string) string { - return fmt.Sprintf(`curl -sfL -H "Authorization: Bearer %s" %s | sudo -E bash && daytona agent`, apiKey, daytonaDownloadUrl) + return fmt.Sprintf(` +%s +# Download and install Daytona agent +curl -sfL -H "Authorization: Bearer %s" %s | sudo -E bash && daytona agent +`, INSTALL_DEPENDENCIES_SCRIPT, apiKey, daytonaDownloadUrl) }