feat: install vscode-server and devstar in remote container when first connecting
This commit is contained in:
		@@ -16,6 +16,11 @@ export default class RemoteContainer {
 | 
			
		||||
 | 
			
		||||
      // first connect to the remote host using password
 | 
			
		||||
      const ssh = new NodeSSH();
 | 
			
		||||
      vscode.window.withProgress({
 | 
			
		||||
          location: vscode.ProgressLocation.Notification,
 | 
			
		||||
          title: "正在容器中安装vscode-server及devstar插件",
 | 
			
		||||
          cancellable: false
 | 
			
		||||
      }, async (progress) => {
 | 
			
		||||
      try {
 | 
			
		||||
        await ssh.connect({
 | 
			
		||||
          host: host,
 | 
			
		||||
@@ -23,10 +28,32 @@ export default class RemoteContainer {
 | 
			
		||||
          password: password,
 | 
			
		||||
          port: port
 | 
			
		||||
        });
 | 
			
		||||
        progress.report({ message: "连接成功,开始安装" });
 | 
			
		||||
 | 
			
		||||
        // install vscode-server and devstar extension
 | 
			
		||||
        const vscodeCommitId = await utils.getVsCodeCommitId();
 | 
			
		||||
        const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`
 | 
			
		||||
        const installVscodeServerScript = `
 | 
			
		||||
        mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\
 | 
			
		||||
        if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then
 | 
			
		||||
            ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
 | 
			
		||||
        else
 | 
			
		||||
            wget ${vscodeServerUrl} -O vscode-server-linux-x64.tar.gz && \\
 | 
			
		||||
            mv vscode-server-linux-x64.tar.gz ~/.vscode-server/bin/${vscodeCommitId} && \\
 | 
			
		||||
            cd ~/.vscode-server/bin/${vscodeCommitId} && \\
 | 
			
		||||
            tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1 && \\
 | 
			
		||||
            rm vscode-server-linux-x64.tar.gz && \\
 | 
			
		||||
            ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
 | 
			
		||||
        fi
 | 
			
		||||
        `;
 | 
			
		||||
        await ssh.execCommand(installVscodeServerScript);
 | 
			
		||||
        console.log("vscode-server and extension installed");
 | 
			
		||||
        vscode.window.showInformationMessage('安装完成!');
 | 
			
		||||
 | 
			
		||||
        // add the public key to the remote authorized_keys
 | 
			
		||||
        await ssh.execCommand(`mkdir -p ~/.ssh && echo '${publicKey}' >> ~/.ssh/authorized_keys`);
 | 
			
		||||
        console.log('Public key added to remote authorized_keys');
 | 
			
		||||
 | 
			
		||||
        await ssh.dispose();
 | 
			
		||||
 | 
			
		||||
        // only connect successfully then save the host info
 | 
			
		||||
@@ -44,7 +71,7 @@ export default class RemoteContainer {
 | 
			
		||||
        console.error('Error adding public key: ', error);
 | 
			
		||||
        await ssh.dispose();
 | 
			
		||||
        reject("failed");
 | 
			
		||||
      }
 | 
			
		||||
      }});
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user