Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL First Setup Utterly Broken #10

Open
theAkito opened this issue Sep 21, 2024 · 2 comments
Open

WSL First Setup Utterly Broken #10

theAkito opened this issue Sep 21, 2024 · 2 comments

Comments

@theAkito
Copy link

Not related to #2 and #4.

Using Windows 10, trying to connect Debian on WSL2.

Connecting to WSL is broken, as the installation script is passed via wsl.exe ...cli-options... -- bash -c '.....script-content...', where script-content contains single quotes. Obviously, the first single quote inside the script will terminate the one launched in the shell running that wsl command, leading to an unrecoverable error.

It especially does not make sense, as those single quotes can be replaced with double quotes, without causing issues, as far as I have checked.

Workaround

I hotfix patched the extension.js @ "C:\Users\USERNAME\.vscode-oss\extensions\jeanp413.open-remote-wsl-0.0.4-universal\out\extension.js" with the following content.

(()=>{"use strict";var e={618:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.RemoteWSLResolver=t.getRemoteAuthority=t.REMOTE_WSL_AUTHORITY=void 0;const s=i(n(496)),a=n(744);t.REMOTE_WSL_AUTHORITY="wsl",t.getRemoteAuthority=function(e){return`${t.REMOTE_WSL_AUTHORITY}+${e}`};class l{constructor(e,t){this.remoteAddress=e,this.localAddress=t,this._onDidDisposeEmitter=new s.EventEmitter,this.onDidDispose=this._onDidDisposeEmitter.event,"localhost"!==t.host&&"127.0.0.1"!==t.host&&(t.host="localhost")}dispose(){this._onDidDisposeEmitter.fire()}}t.RemoteWSLResolver=class{constructor(e,t){this.wslManager=e,this.logger=t}resolve(e,n){const[r,o]=e.split("+");if(r!==t.REMOTE_WSL_AUTHORITY)throw new Error(`Invalid authority type for WSL resolver: ${r}`);this.logger.info(`Resolving wsl remote authority '${e}' (attemp #${n.resolveAttempt})`);const i=s.workspace.getConfiguration("remote.WSL").get("serverDownloadUrlTemplate");return s.window.withProgress({title:`Setting up WSL Distro: ${o}`,location:s.ProgressLocation.Notification,cancellable:!1},(async()=>{try{const e=await(0,a.installCodeServer)(this.wslManager,o,i,[],[],this.logger);return this.labelFormatterDisposable?.dispose(),this.labelFormatterDisposable=s.workspace.registerResourceLabelFormatter({scheme:"vscode-remote",authority:`${t.REMOTE_WSL_AUTHORITY}+*`,formatting:{label:"${path}",separator:"/",tildify:!0,workspaceSuffix:`WSL: ${o}`,workspaceTooltip:`Running in ${o}`}}),new s.ResolvedAuthority("127.0.0.1",e.listeningOn,e.connectionToken)}catch(e){if(this.logger.error("Error resolving authority",e),1===n.resolveAttempt){this.logger.show();const e="Close Remote",t="Retry",n=await s.window.showErrorMessage(`Could not establish connection to WSL distro "${o}"`,{modal:!0},e,t);n===e?await s.commands.executeCommand("workbench.action.remote.close"):n===t&&await s.commands.executeCommand("workbench.action.reloadWindow")}throw e instanceof a.ServerInstallError||!(e instanceof Error)?s.RemoteAuthorityResolverError.NotAvailable(e instanceof Error?e.message:String(e)):s.RemoteAuthorityResolverError.TemporarilyNotAvailable(e.message)}}))}async tunnelFactory(e){return new l(e.remoteAddress,{host:e.remoteAddress.host,port:e.localAddressPort??e.remoteAddress.port})}dispose(){this.labelFormatterDisposable?.dispose()}}},49:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.deleteWSLDistro=t.setDefaultWSLDistro=t.openRemoteWSLLocationWindow=t.openRemoteWSLWindow=t.promptInstallNewWSLDistro=t.promptOpenRemoteWSLWindow=void 0;const a=i(n(496)),l=n(618),c=s(n(574));function d(e,t){a.commands.executeCommand("vscode.newWindow",{remoteAuthority:(0,l.getRemoteAuthority)(e),reuseWindow:t})}t.promptOpenRemoteWSLWindow=async function(e,t,n){let r;if(t){const t=await e.listDistros();r=t.find((e=>e.isDefault))?.name}else r=(await async function(e,t){const n=e.listDistros().then((e=>e.map((e=>({...e,label:`${e.name}`,detail:e.isDefault?"default distro":void 0})))));return await a.window.showQuickPick(n,{canPickMany:!1,placeHolder:"Select WSL distro"})}(e))?.name;r&&d(r,n)},t.promptInstallNewWSLDistro=async function(e){let t;t=(await async function(e,t){const n=Promise.all([e.listOnlineDistros(),e.listDistros()]).then((([e,t])=>e.filter((e=>!t.some((t=>t.name===e.name)))).map((e=>({...e,label:`${e.friendlyName}`})))));return await a.window.showQuickPick(n,{canPickMany:!1,placeHolder:"Select the WSL distro to install"})}(e))?.name,t&&c.default.runCommand(`wsl.exe --install -d ${t}`)},t.openRemoteWSLWindow=d,t.openRemoteWSLLocationWindow=function(e,t,n){a.commands.executeCommand("vscode.openFolder",a.Uri.from({scheme:"vscode-remote",authority:(0,l.getRemoteAuthority)(e),path:t}),{forceNewWindow:!n})},t.setDefaultWSLDistro=async function(e,t){await e.setDefaultDistro(t)},t.deleteWSLDistro=async function(e,t){const n="Delete";return await a.window.showInformationMessage(`Are you sure you want to permanently delete the distro "${t}" including all its data?`,{modal:!0},n)===n&&(await e.deleteDistro(t),!0)}},771:(e,t)=>{function n(e){for(;e.length;){const t=e.pop();t&&t.dispose()}}Object.defineProperty(t,"__esModule",{value:!0}),t.Disposable=t.disposeAll=void 0,t.disposeAll=n,t.Disposable=class{constructor(){this._isDisposed=!1,this._disposables=[]}dispose(){this._isDisposed||(this._isDisposed=!0,n(this._disposables))}_register(e){return this._isDisposed?e.dispose():this._disposables.push(e),e}get isDisposed(){return this._isDisposed}}},110:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventEmitter=t.once=t.toPromise=void 0,t.toPromise=function(e,n){return n?n.aborted?Promise.resolve(void 0):new Promise((r=>{const o=(0,t.once)(e,(e=>{n.removeEventListener("abort",i),r(e)})),i=()=>{o.dispose(),n.removeEventListener("abort",i),r(void 0)};n.addEventListener("abort",i)})):new Promise((n=>(0,t.once)(e,n)))},t.once=(e,t)=>{const n=e((e=>{t(e),n.dispose()}));return n},t.EventEmitter=class{constructor(){this.event=(e,t,n)=>{const r=this.add(t?e.bind(t):e);return n?.push(r),r}}get size(){return this.listeners?"function"==typeof this.listeners?1:this.listeners.length:0}fire(e){if(this.listeners)if("function"==typeof this.listeners)this.listeners(e);else for(const t of this.listeners)t(e)}dispose(){this.listeners=void 0}add(e){return this.listeners?"function"==typeof this.listeners?this.listeners=[this.listeners,e]:this.listeners.push(e):this.listeners=e,{dispose:()=>this.rm(e)}}rm(e){if(!this.listeners)return;if("function"==typeof this.listeners)return void(this.listeners===e&&(this.listeners=void 0));const t=this.listeners.indexOf(e);-1!==t&&(2===this.listeners.length?this.listeners=0===t?this.listeners[1]:this.listeners[0]:this.listeners=this.listeners.slice(0,t).concat(this.listeners.slice(t+1)))}}},249:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0});const s=i(n(496));function a(e,t,n=" "){return n.repeat(Math.max(0,t-e.length))+e}t.default=class{constructor(e){this.output=s.window.createOutputChannel(e)}data2String(e){return e instanceof Error?e.stack||e.message:!1===e.success&&e.message?e.message:e.toString()}trace(e,t){this.logLevel("Trace",e,t)}info(e,t){this.logLevel("Info",e,t)}error(e,t){this.logLevel("Error",e,t)}logLevel(e,t,n){this.output.appendLine(`[${e}  - ${this.now()}] ${t}`),n&&this.output.appendLine(this.data2String(n))}now(){const e=new Date;return a(e.getUTCHours()+"",2,"0")+":"+a(e.getMinutes()+"",2,"0")+":"+a(e.getUTCSeconds()+"",2,"0")+"."+e.getMilliseconds()}show(){this.output.show()}dispose(){this.output.dispose()}}},400:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isLinux=t.isMacintosh=t.isWindows=void 0,t.isWindows="win32"===process.platform,t.isMacintosh="darwin"===process.platform,t.isLinux="linux"===process.platform},679:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.DistroTreeDataProvider=void 0;const s=i(n(496)),a=i(n(17)),l=n(771),c=n(49);class d{constructor(e,t,n){this.name=e,this.isDefault=t,this.locations=n}}class u{constructor(e,t){this.path=e,this.name=t}}class p extends l.Disposable{constructor(e,t){super(),this.locationHistory=e,this.wslManager=t,this._onDidChangeTreeData=this._register(new s.EventEmitter),this.onDidChangeTreeData=this._onDidChangeTreeData.event,this._register(s.commands.registerCommand("openremotewsl.explorer.addDistro",(()=>(0,c.promptInstallNewWSLDistro)(t)))),this._register(s.commands.registerCommand("openremotewsl.explorer.refresh",(()=>this.refresh()))),this._register(s.commands.registerCommand("openremotewsl.explorer.emptyWindowInNewWindow",(e=>this.openRemoteWSLWindow(e,!1)))),this._register(s.commands.registerCommand("openremotewsl.explorer.emptyWindowInCurrentWindow",(e=>this.openRemoteWSLWindow(e,!0)))),this._register(s.commands.registerCommand("openremotewsl.explorer.reopenFolderInNewWindow",(e=>this.openRemoteWSLocationWindow(e,!1)))),this._register(s.commands.registerCommand("openremotewsl.explorer.reopenFolderInCurrentWindow",(e=>this.openRemoteWSLocationWindow(e,!0)))),this._register(s.commands.registerCommand("openremotewsl.explorer.deleteFolderHistoryItem",(e=>this.deleteDistroLocation(e)))),this._register(s.commands.registerCommand("openremotewsl.explorer.setDefaultDistro",(e=>this.setDefaultDistro(e)))),this._register(s.commands.registerCommand("openremotewsl.explorer.deleteDistro",(e=>this.deleteDistro(e))))}getTreeItem(e){if(e instanceof u){const t=a.posix.basename(e.path).replace(/\.code-workspace$/," (Workspace)"),n=new s.TreeItem(t);return n.description=a.posix.dirname(e.path),n.iconPath=new s.ThemeIcon("folder"),n.contextValue="openremotewsl.explorer.folder",n}const t=new s.TreeItem(e.name);return t.description=e.isDefault?"default distro":void 0,t.collapsibleState=e.locations.length?s.TreeItemCollapsibleState.Collapsed:s.TreeItemCollapsibleState.None,t.iconPath=new s.ThemeIcon("vm"),t.contextValue="openremotewsl.explorer.distro",t}async getChildren(e){return e?e instanceof d?e.locations.map((t=>new u(t,e.name))):[]:(await this.wslManager.listDistros()).map((e=>new d(e.name,e.isDefault,this.locationHistory.getHistory(e.name))))}refresh(){this._onDidChangeTreeData.fire()}async deleteDistroLocation(e){await this.locationHistory.removeLocation(e.name,e.path),this.refresh()}async openRemoteWSLWindow(e,t){(0,c.openRemoteWSLWindow)(e.name,t)}async openRemoteWSLocationWindow(e,t){(0,c.openRemoteWSLLocationWindow)(e.name,e.path,t)}async setDefaultDistro(e){await(0,c.setDefaultWSLDistro)(this.wslManager,e.name),this.refresh()}async deleteDistro(e){await(0,c.deleteWSLDistro)(this.wslManager,e.name),this.refresh()}}t.DistroTreeDataProvider=p},112:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.deactivate=t.activate=void 0;const a=i(n(496)),l=s(n(249)),c=n(618),d=n(49),u=n(679),p=n(879),h=n(114),m=n(400);t.activate=async function(e){if(!m.isWindows)return;const t=new l.default("Remote - WSL");e.subscriptions.push(t);const n=new h.WSLManager(t),r=new c.RemoteWSLResolver(n,t);e.subscriptions.push(a.workspace.registerRemoteAuthorityResolver(c.REMOTE_WSL_AUTHORITY,r)),e.subscriptions.push(r);const o=new p.RemoteLocationHistory(e),i=(0,p.getRemoteWorkspaceLocationData)();i&&await o.addLocation(i[0],i[1]);const s=new u.DistroTreeDataProvider(o,n);e.subscriptions.push(a.window.createTreeView("wslTargets",{treeDataProvider:s})),e.subscriptions.push(s),e.subscriptions.push(a.commands.registerCommand("openremotewsl.connect",(()=>(0,d.promptOpenRemoteWSLWindow)(n,!0,!0)))),e.subscriptions.push(a.commands.registerCommand("openremotewsl.connectInNewWindow",(()=>(0,d.promptOpenRemoteWSLWindow)(n,!0,!1)))),e.subscriptions.push(a.commands.registerCommand("openremotewsl.connectUsingDistro",(()=>(0,d.promptOpenRemoteWSLWindow)(n,!1,!0)))),e.subscriptions.push(a.commands.registerCommand("openremotewsl.connectUsingDistroInNewWindow",(()=>(0,d.promptOpenRemoteWSLWindow)(n,!1,!1)))),e.subscriptions.push(a.commands.registerCommand("openremotewsl.showLog",(()=>t.show())))},t.deactivate=function(){}},879:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.getRemoteWorkspaceLocationData=t.RemoteLocationHistory=void 0;const s=i(n(496)),a=n(618);class l{constructor(e){this.context=e,this.remoteLocationHistory={},this.remoteLocationHistory=e.globalState.get(l.STORAGE_KEY)||{}}getHistory(e){return this.remoteLocationHistory[e]||[]}async addLocation(e,t){let n=this.remoteLocationHistory[e]||[];n.includes(t)||(n.unshift(t),this.remoteLocationHistory[e]=n,await this.context.globalState.update(l.STORAGE_KEY,this.remoteLocationHistory))}async removeLocation(e,t){let n=this.remoteLocationHistory[e]||[];n=n.filter((e=>e!==t)),this.remoteLocationHistory[e]=n,await this.context.globalState.update(l.STORAGE_KEY,this.remoteLocationHistory)}}t.RemoteLocationHistory=l,l.STORAGE_KEY="remoteLocationHistory_v0",t.getRemoteWorkspaceLocationData=function(){let e=s.workspace.workspaceFile;if(e&&"vscode-remote"===e.scheme&&e.authority.startsWith(a.REMOTE_WSL_AUTHORITY)&&e.path.endsWith(".code-workspace")){const[,t]=e.authority.split("+");return[t,e.path]}if(e=s.workspace.workspaceFolders?.[0].uri,e&&"vscode-remote"===e.scheme&&e.authority.startsWith(a.REMOTE_WSL_AUTHORITY)){const[,t]=e.authority.split("+");return[t,e.path]}}},487:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.getVSCodeServerConfig=void 0;const s=i(n(496)),a=i(n(147)),l=i(n(17));let c;t.getVSCodeServerConfig=async function(){const e=await async function(){if(!c){const e=await a.promises.readFile(l.join(s.env.appRoot,"product.json"),"utf8");c=JSON.parse(e)}return c}();return{version:s.version.replace("-insider",""),commit:e.commit,quality:e.quality,release:e.release,serverApplicationName:e.serverApplicationName,serverDataFolderName:e.serverDataFolderName,serverDownloadUrlTemplate:e.serverDownloadUrlTemplate}}},744:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.installCodeServer=t.ServerInstallError=void 0;const s=i(n(113)),a=n(487);class l extends Error{constructor(e){super(e)}}t.ServerInstallError=l,t.installCodeServer=async function(e,t,n,r,o,i){const c=s.randomBytes(12).toString("hex"),d=await(0,a.getVSCodeServerConfig)(),u=function({id:e,quality:t,version:n,commit:r,release:o,extensionIds:i,envVariables:a,serverApplicationName:l,serverDataFolderName:c,serverDownloadUrlTemplate:d}){const u=i.map((e=>"--install-extension "+e)).join(" ");return`\n# Server installation script\n\nTMP_DIR="\${XDG_RUNTIME_DIR:-"/tmp"}"\n\nDISTRO_VERSION="${n}"\nDISTRO_COMMIT="${r}"\nDISTRO_QUALITY="${t}"\nDISTRO_VSCODIUM_RELEASE="${o??""}"\n\nSERVER_APP_NAME="${l}"\nSERVER_INITIAL_EXTENSIONS="${u}"\nSERVER_LISTEN_FLAG="--port=0"\nSERVER_DATA_DIR="$HOME/${c}"\nSERVER_DIR="$SERVER_DATA_DIR/bin/$DISTRO_COMMIT"\nSERVER_SCRIPT="$SERVER_DIR/bin/$SERVER_APP_NAME"\nSERVER_LOGFILE="$SERVER_DATA_DIR/.$DISTRO_COMMIT.log"\nSERVER_PIDFILE="$SERVER_DATA_DIR/.$DISTRO_COMMIT.pid"\nSERVER_TOKENFILE="$SERVER_DATA_DIR/.$DISTRO_COMMIT.token"\nSERVER_OS=\nSERVER_ARCH=\nSERVER_CONNECTION_TOKEN=\nSERVER_DOWNLOAD_URL=\n\nLISTENING_ON=\nOS_RELEASE_ID=\nARCH=\nPLATFORM=\n\n# Mimic output from logs of remote-ssh extension\nprint_install_results_and_exit() {\n    echo "${e}: start"\n    echo "exitCode==$1=="\n    echo "listeningOn==$LISTENING_ON=="\n    echo "connectionToken==$SERVER_CONNECTION_TOKEN=="\n    echo "logFile==$SERVER_LOGFILE=="\n    echo "osReleaseId==$OS_RELEASE_ID=="\n    echo "arch==$ARCH=="\n    echo "platform==$PLATFORM=="\n    echo "tmpDir==$TMP_DIR=="\n    ${a.map((e=>`echo "${e}==$${e}=="`)).join("\n")}\n    echo "${e}: end"\n    exit 0\n}\n\n# Check if platform is supported\nPLATFORM="$(uname -s)"\ncase $PLATFORM in\n    Linux)\n        SERVER_OS="linux"\n        ;;\n    *)\n        echo "Error platform not supported: $PLATFORM"\n        print_install_results_and_exit 1\n        ;;\nesac\n\n# Check machine architecture\nARCH="$(uname -m)"\ncase $ARCH in\n    x86_64 | amd64)\n        SERVER_ARCH="x64"\n        ;;\n    armv7l | armv8l)\n        SERVER_ARCH="armhf"\n        ;;\n    arm64 | aarch64)\n        SERVER_ARCH="arm64"\n        ;;\n    *)\n        echo "Error architecture not supported: $ARCH"\n        print_install_results_and_exit 1\n        ;;\nesac\n\n# https://www.freedesktop.org/software/systemd/man/os-release.html\nOS_RELEASE_ID="debian"\nif [[ -z $OS_RELEASE_ID ]]; then\n    OS_RELEASE_ID="debian"\n    if [[ -z $OS_RELEASE_ID ]]; then\n        OS_RELEASE_ID="unknown"\n    fi\nfi\n\n# Create installation folder\nif [[ ! -d $SERVER_DIR ]]; then\n    mkdir -p $SERVER_DIR\n    if (( $? > 0 )); then\n        echo "Error creating server install directory"\n        print_install_results_and_exit 1\n    fi\nfi\n\nSERVER_DOWNLOAD_URL="$(echo "${d.replace(/\$\{/g,"\\${")}" | sed "s/\\\${quality}/$DISTRO_QUALITY/g" | sed "s/\\\${version}/$DISTRO_VERSION/g" | sed "s/\\\${commit}/$DISTRO_COMMIT/g" | sed "s/\\\${os}/$SERVER_OS/g" | sed "s/\\\${arch}/$SERVER_ARCH/g" | sed "s/\\\${release}/$DISTRO_VSCODIUM_RELEASE/g")"\n\n# Check if server script is already installed\nif [[ ! -f $SERVER_SCRIPT ]]; then\n    if [[ "$SERVER_OS" = "dragonfly" ]] || [[ "$SERVER_OS" = "freebsd" ]]; then\n        echo "Error "$SERVER_OS" needs manual installation of remote extension host"\n        print_install_results_and_exit 1\n    fi\n\n    pushd $SERVER_DIR > /dev/null\n\n    if [[ ! -z $(which wget) ]]; then\n        wget --tries=3 --timeout=10 --continue --no-verbose -O vscode-server.tar.gz $SERVER_DOWNLOAD_URL\n    elif [[ ! -z $(which curl) ]]; then\n        curl --retry 3 --connect-timeout 10 --location --show-error --silent --output vscode-server.tar.gz $SERVER_DOWNLOAD_URL\n    else\n        echo "Error no tool to download server binary"\n        print_install_results_and_exit 1\n    fi\n\n    if (( $? > 0 )); then\n        echo "Error downloading server from $SERVER_DOWNLOAD_URL"\n        print_install_results_and_exit 1\n    fi\n\n    tar -xf vscode-server.tar.gz --strip-components 1\n    if (( $? > 0 )); then\n        echo "Error while extracting server contents"\n        print_install_results_and_exit 1\n    fi\n\n    if [[ ! -f $SERVER_SCRIPT ]]; then\n        echo "Error server contents are corrupted"\n        print_install_results_and_exit 1\n    fi\n\n    rm -f vscode-server.tar.gz\n\n    popd > /dev/null\nelse\n    echo "Server script already installed in $SERVER_SCRIPT"\nfi\n\n# Try to find if server is already running\nif [[ -f $SERVER_PIDFILE ]]; then\n    SERVER_PID="$(cat $SERVER_PIDFILE)"\n    SERVER_RUNNING_PROCESS="$(ps -o pid,args -p $SERVER_PID | grep $SERVER_SCRIPT)"\nelse\n    SERVER_RUNNING_PROCESS="$(ps -o pid,args -A | grep $SERVER_SCRIPT | grep -v grep)"\nfi\n\nif [[ -z $SERVER_RUNNING_PROCESS ]]; then\n    if [[ -f $SERVER_LOGFILE ]]; then\n        rm $SERVER_LOGFILE\n    fi\n    if [[ -f $SERVER_TOKENFILE ]]; then\n        rm $SERVER_TOKENFILE\n    fi\n\n    touch $SERVER_TOKENFILE\n    chmod 600 $SERVER_TOKENFILE\n    SERVER_CONNECTION_TOKEN="${s.randomUUID()}"\n    echo $SERVER_CONNECTION_TOKEN > $SERVER_TOKENFILE\n\n    $SERVER_SCRIPT --start-server --host=127.0.0.1 $SERVER_LISTEN_FLAG $SERVER_INITIAL_EXTENSIONS --connection-token-file $SERVER_TOKENFILE --telemetry-level off --use-host-proxy --disable-websocket-compression --without-browser-env-var --enable-remote-auto-shutdown --accept-server-license-terms &> $SERVER_LOGFILE &\n    echo $! > $SERVER_PIDFILE\nelse\n    echo "Server script is already running $SERVER_SCRIPT"\nfi\n\nif [[ -f $SERVER_TOKENFILE ]]; then\n    SERVER_CONNECTION_TOKEN="$(cat $SERVER_TOKENFILE)"\nelse\n    echo "Error server token file not found $SERVER_TOKENFILE"\n    print_install_results_and_exit 1\nfi\n\nif [[ -f $SERVER_LOGFILE ]]; then\n    for i in {1..5}; do\n        LISTENING_ON="$(cat $SERVER_LOGFILE | grep -E "Extension host agent listening on .+" | sed "s/Extension host agent listening on //")"\n        if [[ -n $LISTENING_ON ]]; then\n            break\n        fi\n        sleep 0.5\n    done\n\n    if [[ -z $LISTENING_ON ]]; then\n        echo "Error server did not start sucessfully"\n        print_install_results_and_exit 1\n    fi\nelse\n    echo "Error server log file not found $SERVER_LOGFILE"\n    print_install_results_and_exit 1\nfi\n\n# Finish server setup and keep script running\nif [[ -z $SERVER_RUNNING_PROCESS ]]; then\n    echo "${e}: start"\n    echo "exitCode==0=="\n    echo "listeningOn==$LISTENING_ON=="\n    echo "connectionToken==$SERVER_CONNECTION_TOKEN=="\n    echo "logFile==$SERVER_LOGFILE=="\n    echo "osReleaseId==$OS_RELEASE_ID=="\n    echo "arch==$ARCH=="\n    echo "platform==$PLATFORM=="\n    echo "tmpDir==$TMP_DIR=="\n    ${a.map((e=>`echo "${e}==$${e}=="`)).join("\n")}\n    echo "${e}: end"\n\n    echo "${e}: Server installation script done"\n\n    SERVER_PID="$(cat $SERVER_PIDFILE)"\n    SERVER_RUNNING_PROCESS="$(ps -o pid,args -p $SERVER_PID | grep $SERVER_SCRIPT)"\n    while [[ -n $SERVER_RUNNING_PROCESS ]]; do\n        sleep 300;\n        SERVER_RUNNING_PROCESS="$(ps -o pid,args -p $SERVER_PID | grep $SERVER_SCRIPT)"\n    done\nelse\n    print_install_results_and_exit 0\nfi\n`}({id:c,version:d.version,commit:d.commit,quality:d.quality,release:d.release,extensionIds:r,envVariables:o,serverApplicationName:d.serverApplicationName,serverDataFolderName:d.serverDataFolderName,serverDownloadUrlTemplate:n??d.serverDownloadUrlTemplate??"https://github.com/VSCodium/vscodium/releases/download/${version}.${release}/vscodium-reh-${os}-${arch}-${version}.${release}.tar.gz"}),p=await e.exec("bash",["-c",`'${u.replace(/'/g,"'\\''")}'`],t),h=new RegExp(`${c}: Server installation script done`,"m"),m=await Promise.race([p.exitPromise.then((e=>({stdout:p.stdout,stderr:p.stderr,exitCode:e.exitCode}))),new Promise((e=>{p.onStdoutData((t=>{h.test(t.toString("utf8"))&&e({stdout:p.stdout,stderr:p.stderr,exitCode:0})}))}))]);m.exitCode&&i.trace("Server install command stderr:",m.stderr),i.trace("Server install command stdout:",m.stdout);const f=function(e,t){const n=`${t}: start`,r=`${t}: end`,o=e.indexOf(n);if(o<0)return;const i=e.indexOf(r,o+n.length);if(i<0)return;const s={},a=e.substring(o+n.length,i).split(/\r?\n/);for(const e of a){const[t,n]=e.split("==");s[t]=n}return s}(m.stdout,c);if(!f)throw new l("Failed parsing install script output");const _=parseInt(f.exitCode,10);if(0!==_)throw new l("Couldn't install vscode server on remote server, install script returned non-zero exit status");const E=parseInt(f.listeningOn,10),R=Object.fromEntries(Object.entries(f).filter((([e])=>o.includes(e))));return{exitCode:_,listeningOn:E,connectionToken:f.connectionToken,logFile:f.logFile,osReleaseId:f.osReleaseId,arch:f.arch,platform:f.platform,tmpDir:f.tmpDir,...R}}},114:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.WSLManager=void 0;const s=i(n(81)),a=n(110),l="wsl.exe";t.WSLManager=class{constructor(e){this.logger=e}async listDistros(){const e=this._runWSLCommand(["--list","--verbose"],"utf16le"),{exitCode:t}=await e.exitPromise,{stdout:n,stderr:r}=e;if(t)throw this.logger.trace(`Command wsl listDistros exited with code ${t}`,n+"\n\n"+r),new Error(`Command wsl listDistros exited with code ${t}`);const o=/(?<default>\*|\s)\s+(?<name>[\w\.-]+)\s+(?<state>[\w]+)\s+(?<version>\d)/,i=[];for(const e of n.split(/\r?\n/)){const t=e.match(o);t&&t.groups&&i.push({isDefault:"*"===t.groups.default,name:t.groups.name,state:t.groups.state,version:t.groups.version})}return i}async listOnlineDistros(){const e=this._runWSLCommand(["--list","--online"],"utf16le"),{exitCode:t}=await e.exitPromise,{stdout:n,stderr:r}=e;if(t)throw this.logger.trace(`Command wsl listOnlineDistros exited with code ${t}`,n+"\n\n"+r),new Error(`Command wsl listOnlineDistros exited with code ${t}`);let o=n.split(/\r?\n/);const i=o.findIndex((e=>/\s*NAME\s+FRIENDLY NAME\s*/.test(e)));o=o.slice(i+1);const s=/(?<name>[\w\.-]+)\s+(?<friendlyName>\w.+\w)/,a=[];for(const e of o){const t=e.match(s);t&&t.groups&&a.push({name:t.groups.name,friendlyName:t.groups.friendlyName})}return a}async setDefaultDistro(e){const t=this._runWSLCommand(["--set-default",e],"utf16le"),{exitCode:n}=await t.exitPromise,{stdout:r,stderr:o}=t;if(n)throw this.logger.trace(`Command wsl setDefaultDistro exited with code ${n}`,r+"\n\n"+o),new Error(`Command wsl setDefaultDistro exited with code ${n}`)}async deleteDistro(e){const t=this._runWSLCommand(["--unregister",e],"utf16le"),{exitCode:n}=await t.exitPromise,{stdout:r,stderr:o}=t;if(n)throw this.logger.trace(`Command wsl deleteDistro exited with code ${n}`,r+"\n\n"+o),new Error(`Command wsl deleteDistro exited with code ${n}`)}async exec(e,t,n){return this._runWSLCommand(["--distribution",n,"--",e,...t],"utf8")}_runWSLCommand(e,t){this.logger.trace(`Running WSL command: ${l} ${e.join(" ")}`);const n=s.spawn(l,e,{windowsHide:!0,windowsVerbatimArguments:!0}),r=new a.EventEmitter,o=[],i=new a.EventEmitter,c=[];return n.stdout.on("data",(e=>{o.push(e),r.fire(e)})),n.stderr.on("data",(e=>{c.push(e),i.fire(e)})),{get stdout(){return Buffer.concat(o).toString(t)},get stderr(){return Buffer.concat(c).toString(t)},get onStdoutData(){return r.event},get onStderrData(){return i.event},exitPromise:new Promise(((t,r)=>{n.on("error",(t=>{this.logger.error(`Error running WSL command: ${l} ${e.join(" ")}`,t),r(t)})),n.on("exit",((e,n)=>{t({exitCode:e??0})}))}))}}}},574:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0});const s=i(n(496));class a{getTerminal(){return s.window.terminals.find((e=>e.name===a.NAME))||s.window.createTerminal(a.NAME)}runCommand(e){const t=this.getTerminal();t.show(!1),t.sendText(e,!0)}}a.NAME="WSL",t.default=new a},496:e=>{e.exports=require("vscode")},81:e=>{e.exports=require("child_process")},113:e=>{e.exports=require("crypto")},147:e=>{e.exports=require("fs")},17:e=>{e.exports=require("path")}},t={},n=function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(112);module.exports=n})();

You have to replace debian with whatever distribution you try to target.

@GitMensch
Copy link

Can you try to spot the place where this is done in the code?

@theAkito
Copy link
Author

Can you try to spot the place where this is done in the code?

Am not sure what you mean. You mean inside the distributed JavaScript files? If yes, you can just grep them.

If you mean, in the source code, which presumably generated those files, then I did not check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants