Skip to content

Commit e026c64

Browse files
axtlossmirkobrombin
authored andcommitted
Feat: [close Vanilla-OS#225] Add EtcBuilder
Replace the custom Etc merge functions with EtcBuilder
1 parent 621a2a3 commit e026c64

File tree

21 files changed

+3346
-130
lines changed

21 files changed

+3346
-130
lines changed

core/system.go

+4-108
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/google/uuid"
26+
EtcBuilder "github.com/linux-immutability-tools/EtcBuilder/cmd"
2627
"github.com/vanilla-os/abroot/settings"
2728
)
2829

@@ -152,92 +153,6 @@ func (s *ABSystem) CheckUpdate() (string, bool) {
152153
return s.Registry.HasUpdate(s.CurImage.Digest)
153154
}
154155

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-
241156
// RunCleanUpQueue runs the functions in the queue or only the specified one
242157
func (s *ABSystem) RunCleanUpQueue(fnName string) error {
243158
PrintVerboseInfo("ABSystem.RunCleanUpQueue", "running...")
@@ -937,6 +852,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
937852
// ------------------------------------------------
938853
PrintVerboseSimple("[Stage 8] -------- ABSystemRunOperation")
939854

855+
oldEtc := "/.system/sysconf" // The current etc WITHOUT anything overlayed
940856
presentEtc, err := s.RootM.GetPresent()
941857
if err != nil {
942858
PrintVerboseErr("ABSystem.RunOperation", 8, err)
@@ -950,29 +866,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
950866
oldUpperEtc := fmt.Sprintf("/var/lib/abroot/etc/%s", presentEtc.Label)
951867
newUpperEtc := fmt.Sprintf("/var/lib/abroot/etc/%s", futureEtc.Label)
952868

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)
974870
if err != nil {
975-
PrintVerboseErr("ABSystem.RunOperation", 8.6, err)
871+
PrintVerboseErr("AbSystem.RunOperation", 8.2, err)
976872
return err
977873
}
978874

docs/core.md

-22
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@
7373
* [func (s *ABSystem) GenerateFstab(rootPath string, root ABRootPartition) error](#ABSystem.GenerateFstab)
7474
* [func (s *ABSystem) GenerateSystemdUnits(rootPath string, root ABRootPartition) error](#ABSystem.GenerateSystemdUnits)
7575
* [func (s *ABSystem) LockUpgrade() error](#ABSystem.LockUpgrade)
76-
* [func (s *ABSystem) MergeUserEtcFiles(oldUpperEtc, newLowerEtc, newUpperEtc string) error](#ABSystem.MergeUserEtcFiles)
7776
* [func (s *ABSystem) RemoveFromCleanUpQueue(name string)](#ABSystem.RemoveFromCleanUpQueue)
7877
* [func (s *ABSystem) RemoveStageFile() error](#ABSystem.RemoveStageFile)
7978
* [func (s *ABSystem) ResetQueue()](#ABSystem.ResetQueue)
8079
* [func (s *ABSystem) Rollback() (response ABRollbackResponse, err error)](#ABSystem.Rollback)
8180
* [func (s *ABSystem) RunCleanUpQueue(fnName string) error](#ABSystem.RunCleanUpQueue)
8281
* [func (s *ABSystem) RunOperation(operation ABSystemOperation) error](#ABSystem.RunOperation)
83-
* [func (s *ABSystem) SyncUpperEtc(newEtc string) error](#ABSystem.SyncUpperEtc)
8482
* [func (s *ABSystem) UnlockUpgrade() error](#ABSystem.UnlockUpgrade)
8583
* [func (s *ABSystem) UpgradeLockExists() bool](#ABSystem.UpgradeLockExists)
8684
* [func (s *ABSystem) UserLockRequested() bool](#ABSystem.UserLockRequested)
@@ -837,16 +835,6 @@ LockUpgrade creates a lock file, preventing upgrades from proceeding
837835

838836

839837

840-
### <a name="ABSystem.MergeUserEtcFiles">func</a> (\*ABSystem) [MergeUserEtcFiles](/src/target/system.go?s=4344:4432#L149)
841-
``` go
842-
func (s *ABSystem) MergeUserEtcFiles(oldUpperEtc, newLowerEtc, newUpperEtc string) error
843-
```
844-
MergeUserEtcFiles merges user-related files from the new lower etc (/.system/etc)
845-
with the old upper etc, if present, saving the result in the new upper etc.
846-
847-
848-
849-
850838
### <a name="ABSystem.RemoveFromCleanUpQueue">func</a> (\*ABSystem) [RemoveFromCleanUpQueue](/src/target/system.go?s=9681:9735#L332)
851839
``` go
852840
func (s *ABSystem) RemoveFromCleanUpQueue(name string)
@@ -911,16 +899,6 @@ RunOperation executes a root-switching operation from the options below:
911899

912900

913901

914-
915-
### <a name="ABSystem.SyncUpperEtc">func</a> (\*ABSystem) [SyncUpperEtc](/src/target/system.go?s=5629:5681#L196)
916-
``` go
917-
func (s *ABSystem) SyncUpperEtc(newEtc string) error
918-
```
919-
SyncUpperEtc syncs the mutable etc directories from /var/lib/abroot/etc
920-
921-
922-
923-
924902
### <a name="ABSystem.UnlockUpgrade">func</a> (\*ABSystem) [UnlockUpgrade](/src/target/system.go?s=33993:34033#L1175)
925903
``` go
926904
func (s *ABSystem) UnlockUpgrade() error

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ require (
7474
github.com/klauspost/compress v1.17.4 // indirect
7575
github.com/klauspost/pgzip v1.2.6 // indirect
7676
github.com/letsencrypt/boulder v0.0.0-20240104140712-c1f7de06e9f8 // indirect
77+
github.com/linux-immutability-tools/EtcBuilder v0.0.0-20240221201646-c038f3d3418d // indirect
7778
github.com/mailru/easyjson v0.7.7 // indirect
7879
github.com/manifoldco/promptui v0.9.0 // indirect
7980
github.com/mattn/go-shellwords v1.0.12 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
257257
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
258258
github.com/letsencrypt/boulder v0.0.0-20240104140712-c1f7de06e9f8 h1:VhZp18bDTiwcMExEJnuajfgtjMx03bh/NH7qIplYfdc=
259259
github.com/letsencrypt/boulder v0.0.0-20240104140712-c1f7de06e9f8/go.mod h1:rS3/odUsNpJzEb3gCFNAL32rFXDS4kLeS28vd2x8NfQ=
260+
github.com/linux-immutability-tools/EtcBuilder v0.0.0-20240221201646-c038f3d3418d h1:i0z+Mrudwrnup7/0tBrJhYE2eKIfcjfVPmmMoUfUrkg=
261+
github.com/linux-immutability-tools/EtcBuilder v0.0.0-20240221201646-c038f3d3418d/go.mod h1:zOvDqvS9ojo8mr6dMYsk8L8c6aY9S785WgVIzgGwm8c=
260262
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
261263
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
262264
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=

0 commit comments

Comments
 (0)