Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2a75cf9b4e | ||
|
d52cc16c88 | ||
|
112b572dc2 | ||
|
0c0a85f3bb | ||
|
2761535e12 | ||
|
1a72589f6f | ||
|
df0b5d66d7 |
81
main.go
81
main.go
@@ -151,25 +151,27 @@ func exists(file string) bool {
|
||||
func getHookFiles(filesdir string) (files []string, err error) {
|
||||
fileInfo, err := os.ReadDir(filesdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("getHookFiles: unable to read hook file dir: %w", err)
|
||||
}
|
||||
for _, file := range fileInfo {
|
||||
path := filepath.Join(filesdir, file.Name())
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("getHookFiles: unable to open hook file: %w", err)
|
||||
|
||||
}
|
||||
defer f.Close()
|
||||
log.Printf("-- Including files from: %s\n", path)
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if filelist, err := getFiles([]string{s.Text()}, true); err != nil {
|
||||
return nil, fmt.Errorf("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...)
|
||||
}
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("getHookFiles: uname to process hook file %q: %w", path, err)
|
||||
}
|
||||
}
|
||||
return files, nil
|
||||
@@ -216,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 {
|
||||
@@ -273,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
|
||||
}
|
||||
@@ -424,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) {
|
||||
@@ -464,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 {
|
||||
@@ -485,7 +511,7 @@ func getInitfsFiles(devinfo deviceinfo.DeviceInfo) (files []string, err error) {
|
||||
"/bin/sh",
|
||||
"/bin/busybox-extras",
|
||||
"/usr/sbin/telnetd",
|
||||
"/sbin/kpartx",
|
||||
"/usr/sbin/kpartx",
|
||||
"/etc/deviceinfo",
|
||||
"/usr/bin/unudhcpd",
|
||||
}
|
||||
@@ -504,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 {
|
||||
|
Reference in New Issue
Block a user