@@ -2647,7 +2647,7 @@ class Linux {
26472647 "git clone https://aur.archlinux.org/snapd.git /tmp/snapd; cd /tmp/snapd; makepkg -si --noconfirm;" ;
26482648 commandQueue.add (LinuxCommand (
26492649 userId: currentenvironment.currentUserId,
2650- command: "bash -c '$ bashCode '" ,
2650+ command: bashCode,
26512651 environment: {"PATH" : getPATH (), "HOME" : getHomeDirectory ()},
26522652 ));
26532653 commandQueue.add (LinuxCommand (
@@ -2776,4 +2776,114 @@ class Linux {
27762776 ));
27772777 }
27782778 }
2779+
2780+ static Map <String , dynamic > getGrubSettings () {
2781+ String grubFileContent = File ("/etc/default/grub" ).readAsStringSync ();
2782+ List <String > lines = grubFileContent.split ("\n " );
2783+ Map <String , String > settingsFileMap = {};
2784+ for (String line in lines) {
2785+ if (line.contains ("=" ) && ! line.trim ().startsWith ("#" )) {
2786+ List <String > parts = line.split ("=" );
2787+ settingsFileMap[parts[0 ]] = parts[1 ];
2788+ }
2789+ }
2790+
2791+ Map <String , dynamic > returnValue = {};
2792+ returnValue["grubVisible" ] =
2793+ settingsFileMap["GRUB_TIMEOUT_STYLE" ] == "menu" ||
2794+ settingsFileMap["GRUB_TIMEOUT_STYLE" ] == null ;
2795+ returnValue["enableBigFont" ] = settingsFileMap["GRUB_GFXMODE" ] == "640x480" ;
2796+ if (settingsFileMap["GRUB_TIMEOUT" ] == null ) {
2797+ settingsFileMap["GRUB_TIMEOUT" ] = "0" ;
2798+ }
2799+ returnValue["timeout" ] =
2800+ int .tryParse (settingsFileMap["GRUB_TIMEOUT" ]! ) ?? 0 ;
2801+ returnValue["startLastBootedOne" ] =
2802+ settingsFileMap["GRUB_DEFAULT" ] == "saved" ;
2803+
2804+ return returnValue;
2805+ }
2806+
2807+ static void ensureGrubSettings (context, bool grubVisible, bool enableBigFont,
2808+ int timeout, bool startLastBootedOne) {
2809+ String grub_timeout_style = grubVisible ? "menu" : "hidden" ;
2810+ String grub_timeout = timeout.toString ();
2811+ String grub_default = startLastBootedOne ? "saved" : "0" ;
2812+ String grub_save_default = startLastBootedOne ? "true" : "false" ;
2813+ String grub_gfxmode = enableBigFont ? "640x480" : "" ;
2814+
2815+ if (grub_timeout_style == "menu" && timeout < 1 ) {
2816+ grub_timeout = "1" ;
2817+ }
2818+
2819+ if (grub_timeout_style == "hidden" && timeout < 0 ) {
2820+ grub_timeout = "0" ;
2821+ }
2822+
2823+ ensureOptionInConfigFile (
2824+ "GRUB_TIMEOUT_STYLE" , grub_timeout_style, "/etc/default/grub" );
2825+ ensureOptionInConfigFile ("GRUB_TIMEOUT" , grub_timeout, "/etc/default/grub" );
2826+ ensureOptionInConfigFile ("GRUB_DEFAULT" , grub_default, "/etc/default/grub" );
2827+ ensureOptionInConfigFile (
2828+ "GRUB_SAVEDEFAULT" , grub_save_default, "/etc/default/grub" );
2829+ ensureOptionInConfigFile ("GRUB_GFXMODE" , grub_gfxmode, "/etc/default/grub" );
2830+
2831+ if (currentenvironment.distribution != DISTROS .FEDORA ) {
2832+ commandQueue.add (LinuxCommand (
2833+ userId: 0 ,
2834+ command: "/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg" ,
2835+ ));
2836+ } else {
2837+ commandQueue.add (LinuxCommand (
2838+ userId: 0 ,
2839+ command: "/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg" ,
2840+ ));
2841+ }
2842+
2843+ Navigator .of (context).push (MaterialPageRoute (
2844+ builder: (context) => RunCommandQueue (
2845+ title: AppLocalizations .of (context)! .grubConfiguration,
2846+ route: MainSearchLoader ()),
2847+ ));
2848+ }
2849+
2850+ /// Used for config files like /etc/default/grub.
2851+ ///
2852+ /// Only adds the commands to the command queue to ensure that the key is set to the value.
2853+ /// If the value is empty, the key will be removed from the file.
2854+ static void ensureOptionInConfigFile (String key, String value, String path) {
2855+ /// Remove the key from the file if the value is empty
2856+ if (value.isEmpty) {
2857+ commandQueue.add (LinuxCommand (
2858+ userId: 0 ,
2859+ command: "sed -i '/$key /d' $path " ,
2860+ ));
2861+ return ;
2862+ }
2863+
2864+ bool settingFound = false ;
2865+ // Check if the key is already in the file and is not commented out
2866+ String fileContent = File (path).readAsStringSync ();
2867+ List <String > lines = fileContent.split ("\n " );
2868+ for (String line in lines) {
2869+ if (line.contains ("$key =" ) && ! line.trim ().startsWith ("#" )) {
2870+ settingFound = true ;
2871+ break ;
2872+ }
2873+ }
2874+
2875+ if (! settingFound) {
2876+ // Add the key to the file
2877+ commandQueue.add (LinuxCommand (
2878+ userId: 0 ,
2879+ command: "echo '$key =$value ' >> $path " ,
2880+ ));
2881+ } else {
2882+ // Replace the key in the file
2883+ commandQueue.add (LinuxCommand (
2884+ userId: 0 ,
2885+ command: "sed -i 's/$key =.*/$key =$value /' $path " ,
2886+ ));
2887+ }
2888+ }
27792889}
0 commit comments