@@ -23,6 +23,7 @@ import (
23
23
"strings"
24
24
25
25
"github.com/google/uuid"
26
+ EtcBuilder "github.com/linux-immutability-tools/EtcBuilder/cmd"
26
27
"github.com/vanilla-os/abroot/settings"
27
28
)
28
29
@@ -152,92 +153,6 @@ func (s *ABSystem) CheckUpdate() (string, bool) {
152
153
return s .Registry .HasUpdate (s .CurImage .Digest )
153
154
}
154
155
155
- // MergeUserEtcFiles merges user-related files from the new lower etc (/.system/etc)
156
- // with the old upper etc, if present, saving the result in the new upper etc.
157
- func (s * ABSystem ) MergeUserEtcFiles (oldUpperEtc , newLowerEtc , newUpperEtc string ) error {
158
- PrintVerboseInfo ("ABSystem.SyncLowerEtc" , "syncing /.system/etc ->" , newLowerEtc )
159
-
160
- etcFiles := []string {
161
- "passwd" ,
162
- "group" ,
163
- "shells" ,
164
- "shadow" ,
165
- "subuid" ,
166
- "subgid" ,
167
- }
168
-
169
- etcDir := "/.system/etc"
170
- if _ , err := os .Stat (etcDir ); os .IsNotExist (err ) {
171
- PrintVerboseErr ("ABSystem.SyncLowerEtc" , 0 , err )
172
- return err
173
- }
174
-
175
- for _ , file := range etcFiles {
176
- // Use file present in the immutable /etc if it exists. Otherwise, use the immutable one.
177
- _ , err := os .Stat (oldUpperEtc + "/" + file )
178
- if err != nil {
179
- if os .IsNotExist (err ) { // No changes were made to the file from its image base, skip merge
180
- continue
181
- } else {
182
- PrintVerboseErr ("ABSystem.SyncLowerEtc" , 1 , err )
183
- return err
184
- }
185
- } else {
186
- firstFile := oldUpperEtc + "/" + file
187
- secondFile := newLowerEtc + "/" + file
188
- destination := newUpperEtc + "/" + file
189
-
190
- // write the diff to the destination
191
- err = MergeDiff (firstFile , secondFile , destination )
192
- if err != nil {
193
- PrintVerboseErr ("ABSystem.SyncLowerEtc" , 2 , err )
194
- return err
195
- }
196
- }
197
- }
198
-
199
- PrintVerboseInfo ("ABSystem.SyncLowerEtc" , "sync completed" )
200
- return nil
201
- }
202
-
203
- // SyncUpperEtc syncs the mutable etc directories from /var/lib/abroot/etc
204
- func (s * ABSystem ) SyncUpperEtc (newEtc string ) error {
205
- PrintVerboseInfo ("ABSystem.SyncUpperEtc" , "Starting" )
206
-
207
- current_part , err := s .RootM .GetPresent ()
208
- if err != nil {
209
- PrintVerboseErr ("ABSystem.SyncUpperEtc" , 0 , err )
210
- return err
211
- }
212
-
213
- etcDir := fmt .Sprintf ("/var/lib/abroot/etc/%s" , current_part .Label )
214
- if _ , err := os .Stat (etcDir ); os .IsNotExist (err ) {
215
- PrintVerboseErr ("ABSystem.SyncEtc" , 1 , err )
216
- return err
217
- }
218
-
219
- PrintVerboseInfo ("ABSystem.SyncUpperEtc: syncing /var/lib/abroot/etc/%s -> %s" , current_part .Label , newEtc )
220
-
221
- opts := []string {
222
- "--exclude=passwd" ,
223
- "--exclude=group" ,
224
- "--exclude=shells" ,
225
- "--exclude=shadow" ,
226
- "--exclude=subuid" ,
227
- "--exclude=subgid" ,
228
- "--exclude=fstab" ,
229
- "--exclude=crypttab" ,
230
- }
231
- err = rsyncCmd (etcDir + "/" , newEtc , opts , false )
232
- if err != nil {
233
- PrintVerboseErr ("ABSystem.SyncUpperEtc" , 2 , err )
234
- return err
235
- }
236
-
237
- PrintVerboseInfo ("ABSystem.SyncUpperEtc" , "sync completed" )
238
- return nil
239
- }
240
-
241
156
// RunCleanUpQueue runs the functions in the queue or only the specified one
242
157
func (s * ABSystem ) RunCleanUpQueue (fnName string ) error {
243
158
PrintVerboseInfo ("ABSystem.RunCleanUpQueue" , "running..." )
@@ -937,6 +852,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
937
852
// ------------------------------------------------
938
853
PrintVerboseSimple ("[Stage 8] -------- ABSystemRunOperation" )
939
854
855
+ oldEtc := "/.system/sysconf" // The current etc WITHOUT anything overlayed
940
856
presentEtc , err := s .RootM .GetPresent ()
941
857
if err != nil {
942
858
PrintVerboseErr ("ABSystem.RunOperation" , 8 , err )
@@ -950,29 +866,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
950
866
oldUpperEtc := fmt .Sprintf ("/var/lib/abroot/etc/%s" , presentEtc .Label )
951
867
newUpperEtc := fmt .Sprintf ("/var/lib/abroot/etc/%s" , futureEtc .Label )
952
868
953
- // Clean new upper etc to prevent deleted files from persisting
954
- err = os .RemoveAll (newUpperEtc )
955
- if err != nil {
956
- PrintVerboseErr ("ABSystem.RunOperation" , 8.2 , err )
957
- return err
958
- }
959
- err = os .Mkdir (newUpperEtc , 0755 )
960
- if err != nil {
961
- PrintVerboseErr ("ABSystem.RunOperation" , 8.3 , err )
962
- return err
963
- }
964
-
965
- err = s .MergeUserEtcFiles (oldUpperEtc , filepath .Join (systemNew , "/etc" ), newUpperEtc )
966
- if err != nil {
967
- PrintVerboseErr ("ABSystem.RunOperation" , 8.4 , err )
968
- return err
969
- }
970
-
971
- s .RunCleanUpQueue ("clearUnstagedPackages" )
972
-
973
- err = s .SyncUpperEtc (newUpperEtc )
869
+ err = EtcBuilder .ExtBuildCommand (oldEtc , systemNew + "/sysconf" , oldUpperEtc , newUpperEtc )
974
870
if err != nil {
975
- PrintVerboseErr ("ABSystem .RunOperation" , 8.6 , err )
871
+ PrintVerboseErr ("AbSystem .RunOperation" , 8.2 , err )
976
872
return err
977
873
}
978
874
0 commit comments