Skip to content

Commit 4f311c4

Browse files
committed
by default fill in uid and gid
Signed-off-by: Charlie Drage <[email protected]>
1 parent ca19def commit 4f311c4

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

packages/backend/src/api-impl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { History } from './history';
2525
import * as containerUtils from './container-utils';
2626
import { Messages } from '/@shared/src/messages/Messages';
2727
import { telemetryLogger } from './extension';
28-
import { checkPrereqs, isLinux } from './machine-utils';
28+
import { checkPrereqs, isLinux, getUidGid } from './machine-utils';
2929

3030
export class BootcApiImpl implements BootcApi {
3131
private history: History;
@@ -244,6 +244,10 @@ export class BootcApiImpl implements BootcApi {
244244
return isLinux();
245245
}
246246

247+
async getUidGid(): Promise<string> {
248+
return getUidGid();
249+
}
250+
247251
// The API does not allow callbacks through the RPC, so instead
248252
// we send "notify" messages to the frontend to trigger a refresh
249253
// this method is internal and meant to be used by the API implementation

packages/backend/src/machine-utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,12 @@ const linux = os.platform() === 'linux';
138138
export function isLinux(): boolean {
139139
return linux;
140140
}
141+
142+
// Get the GID and UID of the current user and return in the format gid:uid
143+
// in order for this to work, we must get this information from process.exec
144+
// since there is no native way via node
145+
export async function getUidGid(): Promise<string> {
146+
const { stdout: uidOutput } = await extensionApi.process.exec('id', ['-u']);
147+
const { stdout: gidOutput } = await extensionApi.process.exec('id', ['-g']);
148+
return `${uidOutput.trim()}:${gidOutput.trim()}`;
149+
}

packages/frontend/src/Build.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ async function fillArchitectures(historyInfo: BootcBuildInfo[]) {
125125
}
126126
}
127127
128+
// This will fill the chown function by getting the user and group ID from the OS
129+
// and filling in the information in the chown input field.
130+
async function fillChownOption() {
131+
try {
132+
const gidUid = await bootcClient.getUidGid();
133+
buildChown = gidUid;
134+
} catch (error) {
135+
console.error('Error getting UID and GID:', error);
136+
}
137+
}
138+
128139
async function validate() {
129140
let prereqs = await bootcClient.checkPrereqs();
130141
if (prereqs) {
@@ -293,6 +304,10 @@ onMount(async () => {
293304
await fillBuildOptions(historyInfo);
294305
await fillArchitectures(historyInfo);
295306
307+
if (isLinux) {
308+
await fillChownOption();
309+
}
310+
296311
validate();
297312
});
298313
@@ -701,12 +716,13 @@ export function goToHomePage(): void {
701716
name="chown"
702717
id="chown"
703718
bind:value={buildChown}
704-
placeholder="GID and UID parameters (ex. 1000:1000)"
719+
placeholder="UID and GID parameters (ex. 1000:1000)"
705720
class="w-full"
706721
aria-label="chown-select" />
707722
</div>
708723
<p class="text-sm text-[var(--pd-content-text)] pt-2">
709-
This option allows you to change the owner and group of the files in the output directory.
724+
Linux only. By default the UID and GID of the current user is used. This option allows you to
725+
change the owner and group of the files in the output directory.
710726
</p>
711727
</div>
712728
{/if}

packages/shared/src/BootcAPI.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export abstract class BootcApi {
3636
abstract generateUniqueBuildID(name: string): Promise<string>;
3737
abstract openLink(link: string): Promise<void>;
3838
abstract isLinux(): Promise<boolean>;
39+
abstract getUidGid(): Promise<string>;
3940
abstract telemetryLogUsage(eventName: string, data?: Record<string, unknown> | undefined): Promise<void>;
4041
abstract telemetryLogError(eventName: string, data?: Record<string, unknown> | undefined): Promise<void>;
4142
}

0 commit comments

Comments
 (0)