4 Commits
1.5.1 ... 1.6

Author SHA1 Message Date
Oliver Smith
2a75cf9b4e getInitfsExtraFiles: add scripts from hooks-extra (MR 27)
Put scripts from /etc/postmarketos-mkinitfs/hooks-extra into the extra
initramfs instead of the regular one, similar to how it is possible with
files listed in /etc/postmarketos-mkinitfs/files-extra.

This way we will be able to launch hooks not only very early in the
initramfs as it's currently the case. But also later on after the
initramfs-extra was extracted, and more files are available. ondev2 will
make use of this feature.
2023-01-17 08:12:03 +01:00
Oliver Smith
d52cc16c88 getBinaryDeps: search in /usr/lib/expect* (MR 28)
Instead of only searching for shared libraries in /usr/lib and /lib,
also search in /usr/lib/expect* (currently the expect binary links
against /usr/lib/expect5.45.4/libexpect5.45.4.so).

I've also considered searching /usr/lib recursively, but that would be a
major performance hit.

Expect gets added to the initramfs-extra in a script that runs the
ondev2 testsuite inside qemu.
2023-01-16 22:55:36 -08:00
Oliver Smith
112b572dc2 getFile: print exact error from os.Stat (MR 28)
Pass the exact error message down and make formatting of the message
consistent.
2023-01-16 22:55:30 -08:00
Oliver Smith
0c0a85f3bb getHookFiles: print exact error from getFiles (MR 28)
Instead of assuming that the error is "unable to find file", print the
actual error from getFiles. I just had a situation where the file
exists, but a dependency couldn't be found.

Before:
  generateInitfsExtra: getHookFiles: unable to find file "/usr/bin/expect" required by "/etc/postmarketos-mkinitfs/files-extra/ondev2-test.files"

After:
  generateInitfsExtra: getHookFiles: unable to add file "/usr/bin/expect" required by "/etc/postmarketos-mkinitfs/files-extra/ondev2-test.files": getBinaryDeps: unable to locate dependency for "/usr/bin/expect": libexpect5.45.4.so
2023-01-16 22:55:18 -08:00

71
main.go
View File

@@ -165,7 +165,7 @@ func getHookFiles(filesdir string) (files []string, err error) {
s := bufio.NewScanner(f)
for s.Scan() {
if filelist, err := getFiles([]string{s.Text()}, true); err != nil {
return nil, fmt.Errorf("getHookFiles: unable to find file %q required by %q", s.Text(), path)
return nil, fmt.Errorf("getHookFiles: unable to add file %q required by %q: %w", s.Text(), path, err)
} else {
files = append(files, filelist...)
}
@@ -218,20 +218,30 @@ func getBinaryDeps(file string) (files []string, err error) {
return files, err
}
libdirs := []string{"/usr/lib", "/lib"}
// we don't recursively search these paths for performance reasons
libdirGlobs := []string{
"/usr/lib",
"/lib",
"/usr/lib/expect*",
}
for _, lib := range libs {
found := false
for _, libdir := range libdirs {
path := filepath.Join(libdir, lib)
if _, err := os.Stat(path); err == nil {
binaryDepFiles, err := getBinaryDeps(path)
if err != nil {
return files, err
findDepLoop:
for _, libdirGlob := range libdirGlobs {
libdirs, _ := filepath.Glob(libdirGlob)
for _, libdir := range libdirs {
path := filepath.Join(libdir, lib)
if _, err := os.Stat(path); err == nil {
binaryDepFiles, err := getBinaryDeps(path)
if err != nil {
return files, err
}
files = append(files, binaryDepFiles...)
files = append(files, path)
found = true
break findDepLoop
}
files = append(files, binaryDepFiles...)
files = append(files, path)
found = true
break
}
}
if !found {
@@ -275,7 +285,7 @@ func getFile(file string, required bool) (files []string, err error) {
fileInfo, err := os.Stat(file)
if err != nil {
if required {
return files, errors.New("getFile: File does not exist :" + file)
return files, fmt.Errorf("getFile: failed to stat file %q: %w", file, err)
}
return files, nil
}
@@ -426,11 +436,16 @@ func getFdeFiles(devinfo deviceinfo.DeviceInfo) (files []string, err error) {
return
}
func getHookScripts() (files []string) {
scripts, _ := filepath.Glob("/etc/postmarketos-mkinitfs/hooks/*.sh")
files = append(files, scripts...)
return
func getHookScripts(scriptsdir string) (files []string, err error) {
fileInfo, err := os.ReadDir(scriptsdir)
if err != nil {
return nil, fmt.Errorf("getHookScripts: unable to read hook script dir: %w", err)
}
for _, file := range fileInfo {
path := filepath.Join(scriptsdir, file.Name())
files = append(files, path)
}
return files, nil
}
func getInitfsExtraFiles(devinfo deviceinfo.DeviceInfo) (files []string, err error) {
@@ -466,6 +481,15 @@ func getInitfsExtraFiles(devinfo deviceinfo.DeviceInfo) (files []string, err err
}
}
if exists("/etc/postmarketos-mkinitfs/hooks-extra") {
log.Println("- Including extra hook scripts")
if hookScripts, err := getHookScripts("/etc/postmarketos-mkinitfs/hooks-extra"); err != nil {
return nil, err
} else {
files = append(files, hookScripts...)
}
}
if exists("/usr/bin/osk-sdl") {
log.Println("- Including FDE support")
if fdeFiles, err := getFdeFiles(devinfo); err != nil {
@@ -506,9 +530,14 @@ func getInitfsFiles(devinfo deviceinfo.DeviceInfo) (files []string, err error) {
}
}
log.Println("- Including hook scripts")
hookScripts := getHookScripts()
files = append(files, hookScripts...)
if exists("/etc/postmarketos-mkinitfs/hooks") {
log.Println("- Including hook scripts")
if hookScripts, err := getHookScripts("/etc/postmarketos-mkinitfs/hooks"); err != nil {
return nil, err
} else {
files = append(files, hookScripts...)
}
}
log.Println("- Including required binaries")
if filelist, err := getFiles(requiredFiles, true); err != nil {