@hurshb50/setup-ubuntu 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ import fs from "fs/promises";
10
10
  import { execa } from "execa";
11
11
  //#region package.json
12
12
  var name = "@hurshb50/setup-ubuntu";
13
- var version = "0.0.3";
13
+ var version = "1.0.0";
14
14
  //#endregion
15
15
  //#region source/modules/logger/logger.ts
16
16
  var Logger = class Logger {
@@ -184,6 +184,19 @@ var DependencyManager = class {
184
184
  }
185
185
  }))).every((installation) => installation === true);
186
186
  }
187
+ async authenticate() {
188
+ if (await this.isAuthenticated()) return;
189
+ process.stdout.write("Administrator access is required to install packages. You may be prompted for your password.\n");
190
+ try {
191
+ await execa("sudo", ["--validate"], {
192
+ stdin: "inherit",
193
+ stdout: "inherit",
194
+ stderr: "inherit"
195
+ });
196
+ } catch (error) {
197
+ throw new Error("Administrator access was not granted. Run 'sudo --validate' and then run this tool again.", { cause: error });
198
+ }
199
+ }
187
200
  async install(dependencies, task) {
188
201
  await this.enqueue([
189
202
  "install",
@@ -195,8 +208,17 @@ var DependencyManager = class {
195
208
  async update(task) {
196
209
  await this.enqueue(["update"], task);
197
210
  }
211
+ async isAuthenticated() {
212
+ try {
213
+ await execa("sudo", ["--non-interactive", "--validate"], { stdin: "ignore" });
214
+ return true;
215
+ } catch {
216
+ return false;
217
+ }
218
+ }
198
219
  enqueue(managerArguments, task) {
199
220
  const operation = this.queue.then(async () => {
221
+ if (!await this.isAuthenticated()) throw new Error("Administrator access is no longer available for apt-get. Run 'sudo --validate' and then run this tool again.");
200
222
  const subprocess = execa("sudo", [
201
223
  "env",
202
224
  ...["DEBIAN_FRONTEND=noninteractive", "NEEDRESTART_SUSPEND=1"],
@@ -204,13 +226,15 @@ var DependencyManager = class {
204
226
  ...managerArguments
205
227
  ], { stdin: "ignore" });
206
228
  let partial = "";
207
- subprocess.stdout?.on("data", (chunk) => {
229
+ const track = (chunk) => {
208
230
  partial += chunk.toString();
209
231
  const lines = partial.split(/\r\n|\r|\n/);
210
232
  partial = lines.pop() ?? "";
211
233
  const line = lines.at(-1)?.trim();
212
234
  if (line) task.continue(line);
213
- });
235
+ };
236
+ subprocess.stdout?.on("data", track);
237
+ subprocess.stderr?.on("data", track);
214
238
  await subprocess;
215
239
  });
216
240
  this.queue = operation.catch(() => {});
@@ -604,6 +628,7 @@ var Wallpapers = class {
604
628
  program.name(name).version(version).description("Sets up a fresh Ubuntu machine with a standard set of tools, configuration, and dotfiles.").action(async () => {
605
629
  const logger = new Logger();
606
630
  const dependencyManager = new DependencyManager();
631
+ await dependencyManager.authenticate();
607
632
  logger.start();
608
633
  const packages = [
609
634
  new AgentRules(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hurshb50/setup-ubuntu",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "distribution"