@@ -129,14 +129,23 @@ def pre_arg_parser(key: str, fallback: str) -> str:
129
129
return fallback
130
130
131
131
132
- class CustomUserId (IntOrBoolSingleton ):
132
+ class IntOrBoolSingletonUpdateableFallback (IntOrBoolSingleton ):
133
+
134
+ @classmethod
135
+ def update_fallback (cls , new_id : int ) -> None :
136
+ cls .set_value (cls () or new_id )
137
+
138
+
139
+ class CustomUserId (IntOrBoolSingletonUpdateableFallback ):
133
140
@classmethod
134
141
def init_value (cls ) -> int :
135
142
return int (pre_arg_parser ("--user-id" , "0" ))
136
143
144
+
145
+ class CustomGroupId (IntOrBoolSingletonUpdateableFallback ):
137
146
@classmethod
138
- def update_fallback (cls , new_id : int ) -> None :
139
- cls . set_value ( cls () or new_id )
147
+ def init_value (cls ) -> int :
148
+ return int ( pre_arg_parser ( "--group-id" , "0" ) )
140
149
141
150
142
151
class RunningAsRoot (IntOrBoolSingleton ):
@@ -380,7 +389,7 @@ def __new__(cls) -> "ConfigSchemaT": # type: ignore[misc]
380
389
"Consider either calling Pikaur from your actual"
381
390
" user account without `sudo`,"
382
391
" or creating `pikaur` user"
383
- " and specifying its UserId in Pikaur config\n "
392
+ " and specifying its UserId and GroupId in Pikaur config\n "
384
393
"and set DynamicUsers to `never`." ,
385
394
),
386
395
"when_value" : ["root" , "always" ],
@@ -552,6 +561,10 @@ def __new__(cls) -> "ConfigSchemaT": # type: ignore[misc]
552
561
"data_type" : INT ,
553
562
"default" : "0" ,
554
563
},
564
+ "GroupId" : {
565
+ "data_type" : INT ,
566
+ "default" : "0" ,
567
+ },
555
568
"PreserveEnv" : {
556
569
"data_type" : STR ,
557
570
"default" : (
@@ -612,18 +625,24 @@ def write_config(config: configparser.ConfigParser | None = None) -> None:
612
625
need_write = True
613
626
if need_write :
614
627
CustomUserId .update_fallback (int (config ["misc" ]["UserId" ]))
628
+ CustomGroupId .update_fallback (int (config ["misc" ]["GroupId" ]))
615
629
config_root = ConfigRoot ()
616
630
config_path = ConfigPath ()
617
631
if not config_root .exists ():
618
632
config_root .mkdir (parents = True )
619
633
with config_path .open ("w" , encoding = DEFAULT_CONFIG_ENCODING ) as configfile :
620
634
config .write (configfile )
621
635
if custom_user_id := CustomUserId ():
636
+ custom_group_id = CustomGroupId ()
637
+ if not custom_group_id :
638
+ _err_write (translate (
639
+ "Either both UserId and GroupId or neither of them should be set" ,
640
+ ))
622
641
for path in (
623
642
config_root ,
624
643
config_path ,
625
644
):
626
- os .chown (path , custom_user_id , custom_user_id )
645
+ os .chown (path , custom_user_id , custom_group_id )
627
646
628
647
629
648
def str_to_bool (value : str ) -> bool :
@@ -703,6 +722,7 @@ def get_config(cls) -> configparser.ConfigParser:
703
722
write_config (config = cls ._config )
704
723
cls .validate_config ()
705
724
CustomUserId .update_fallback (int (cls ._config ["misc" ]["UserId" ]))
725
+ CustomGroupId .update_fallback (int (cls ._config ["misc" ]["GroupId" ]))
706
726
return cls ._config
707
727
708
728
def __getattr__ (self , attr : str ) -> PikaurConfigSection :
0 commit comments