diff --git a/lib/content/basic_entries.dart b/lib/content/basic_entries.dart index b4cb935..5a759f3 100644 --- a/lib/content/basic_entries.dart +++ b/lib/content/basic_entries.dart @@ -178,5 +178,18 @@ List getBasicEntries(BuildContext context) { .contains(SOFTWARE_MANAGERS.SNAP); }, ), + ActionEntry( + name: AppLocalizations.of(context)!.makeAdministrator, + description: AppLocalizations.of(context)!.makeAdministratorDescription, + action: "make_administrator", + iconWidget: Icon( + Icons.admin_panel_settings, + size: 48, + color: MintY.currentColor, + ), + disableEntryIf: () { + return Linux.hasCurrentUserAdministratorRights(); + }, + ) ]; } diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index c4919f4..0693c06 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -343,6 +343,8 @@ "setupSnap": "Snap einrichten", "setupSnapDescription": "Installiere Snap und den Snap-Store, um viele weitere Anwendungen zu installieren.\nDanach ist ein Neustart des Rechners empfohlen.", "vivaldiDescription": "Proprietärer Browser mit Fokus auf Privatsphäre und vielen Anpassungsmöglichkeiten.", + "makeAdministrator": "Aktuellen Benutzer zum Administrator machen", + "makeAdministratorDescription": "Füge den aktuellen Benutzer zur Gruppe 'sudo' hinzu, um Root-Rechte zu erhalten. Dafür ist das Passwort des Root-Benutzers nötig.\nDanach ist ein Neustart des Rechners empfohlen.", "@helloWorld": { "placeholders": {}, "description": "", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 042041d..fe6fdba 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -343,6 +343,8 @@ "setupSnap": "Set up Snap", "setupSnapDescription": "Install Snap and the Snap Store to install many more applications.\nAfterwards a restart of the computer is recommended.", "vivaldiDescription": "Proprietary browser with focus on privacy and many customization options.", + "makeAdministrator": "Make the current user an administrator", + "makeAdministratorDescription": "Add the current user to the 'sudo' group to obtain root rights. The password of the root user is required for this.\nAfterwards a restart of the computer is recommended.", "@helloWorld": { "placeholders": {}, "description": "The conventional newborn programmer greeting", diff --git a/lib/models/environment.dart b/lib/models/environment.dart index 1b4291f..cbf3ecc 100644 --- a/lib/models/environment.dart +++ b/lib/models/environment.dart @@ -22,6 +22,7 @@ class Environment { String kernelVersion = ""; String cpuModel = ""; String gpuModel = ""; + List groups = []; /// POSIX User ID. var currentUserId = 1000; diff --git a/lib/services/action_handler.dart b/lib/services/action_handler.dart index 2cc03e3..43941f2 100644 --- a/lib/services/action_handler.dart +++ b/lib/services/action_handler.dart @@ -378,5 +378,9 @@ class ActionHandler { if (actionEntry.action.startsWith("setup_snap")) { Linux.setupSnapAndSnapStore(context); } + + if (actionEntry.action.startsWith("make_administrator")) { + Linux.makeCurrentUserToAdministrator(context); + } } } diff --git a/lib/services/linux.dart b/lib/services/linux.dart index d81adcb..54b8728 100644 --- a/lib/services/linux.dart +++ b/lib/services/linux.dart @@ -918,6 +918,7 @@ class Linux { newEnvironment.currentUserId = await getUserIdOfCurrentUser(); newEnvironment.hostname = await getHostname(); newEnvironment.username = await getUsername(); + newEnvironment.groups = await getGroupsOfCurrentUser(); newEnvironment.osPrettyName = await Linux.getOsPrettyName(); newEnvironment.kernelVersion = await getKernelVersion(); newEnvironment.cpuModel = await getCpuModel(); @@ -926,6 +927,11 @@ class Linux { return newEnvironment; } + static Future> getGroupsOfCurrentUser() async { + String groups = await runCommand("groups"); + return groups.split(" "); + } + static String getExecutablePathOfSoftwareManager(SOFTWARE_MANAGERS input) { switch (input) { case SOFTWARE_MANAGERS.FLATPAK: @@ -2387,4 +2393,24 @@ class Linux { route: MainSearchLoader()), )); } + + /// Checks if the current user is in the group sudo + static bool hasCurrentUserAdministratorRights() { + return currentenvironment.groups.contains("sudo"); + } + + /// Adds the current user to sudo group + static void makeCurrentUserToAdministrator(context) { + commandQueue.add(LinuxCommand( + userId: 0, + command: "/usr/sbin/usermod -aG sudo ${currentenvironment.username}", + )); + + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => RunCommandQueue( + title: AppLocalizations.of(context)!.makeAdministrator, + message: AppLocalizations.of(context)!.makeAdministratorDescription, + route: MainSearchLoader()), + )); + } }