( ctx devspacecontext.Context, command []string, tty bool, disableScreen bool, screenSession string, stdout io.Writer, stderr io.Writer, stdin io.Reader, container *selector.SelectedPodContainer, )
| 157 | } |
| 158 | |
| 159 | func startTerminal( |
| 160 | ctx devspacecontext.Context, |
| 161 | command []string, |
| 162 | tty bool, |
| 163 | disableScreen bool, |
| 164 | screenSession string, |
| 165 | stdout io.Writer, |
| 166 | stderr io.Writer, |
| 167 | stdin io.Reader, |
| 168 | container *selector.SelectedPodContainer, |
| 169 | ) error { |
| 170 | interruptpkg.Global.Stop() |
| 171 | defer interruptpkg.Global.Start() |
| 172 | |
| 173 | // try to install screen |
| 174 | useScreen := false |
| 175 | if term.IsTerminal(stdin) && !disableScreen { |
| 176 | ctx.Log().Debugf("Installing screen in container...") |
| 177 | bufferStdout, bufferStderr, err := ctx.KubeClient().ExecBuffered(ctx.Context(), container.Pod, container.Container.Name, []string{ |
| 178 | "sh", |
| 179 | "-c", |
| 180 | `if ! command -v screen; then |
| 181 | if command -v apk; then |
| 182 | apk add --no-cache screen |
| 183 | elif command -v apt-get; then |
| 184 | apt-get -qq update && apt-get install -y screen && rm -rf /var/lib/apt/lists/* |
| 185 | else |
| 186 | echo "Couldn't install screen using neither apt-get nor apk." |
| 187 | exit 1 |
| 188 | fi |
| 189 | fi |
| 190 | if command -v screen; then |
| 191 | echo "Screen installed successfully." |
| 192 | |
| 193 | if [ ! -f ~/.screenrc ]; then |
| 194 | echo "termcapinfo xterm* ti@:te@" > ~/.screenrc |
| 195 | echo "logfile /tmp/terminal-log.0" >> ~/.screenrc |
| 196 | echo "escape ^tt" >> ~/.screenrc |
| 197 | fi |
| 198 | else |
| 199 | echo "Couldn't find screen, need to fallback." |
| 200 | exit 1 |
| 201 | fi`, |
| 202 | }, nil) |
| 203 | if err != nil { |
| 204 | ctx.Log().Debugf("Error installing screen: %s %s %v", string(bufferStdout), string(bufferStderr), err) |
| 205 | } else { |
| 206 | useScreen = true |
| 207 | } |
| 208 | } |
| 209 | if useScreen { |
| 210 | newCommand := []string{"screen", "-dRSqL", screenSession, "--"} |
| 211 | newCommand = append(newCommand, command...) |
| 212 | command = newCommand |
| 213 | } |
| 214 | |
| 215 | ctx.Log().Debugf("Starting terminal...") |
| 216 |
no test coverage detected