// Print the BusyBox links from a reference image, optionally with their owners // in a signed Vinix root previously checked by tests/installed-root.v. module main import os fn release_links(archive string) ![]string { listing := os.exec(['tar', '--numeric-owner', '--quoting-style=literal', '-tvf', archive]) if listing.exit_code != 0 { return error(listing.output.trim_space()) } mut links := map[string]string{} for line in listing.output.split_into_lines() { if !line.starts_with('l') || !line.contains(' -> ') { continue } name := '/' + line.all_before(' -> ').all_after_last(' ').trim_string_left('./').trim_left('/') target := line.all_after(' -> ') links[name] = os.norm_path(if target.starts_with('/') { target } else { os.join_path(os.dir(name), target) }) } mut result := []string{} for name, target in links { if os.dir(name) !in ['/bin', '/sbin', '/usr/bin', '/usr/sbin'] { continue } mut resolved := target mut visited := map[string]bool{} for (resolved in links) && !visited[resolved] { visited[resolved] = true resolved = links[resolved] } if resolved == '/bin/busybox' { result << name } } result.sort() if result.len == 0 { return error('no BusyBox applet links in ${archive}') } return result } fn installed_owners(database string, paths []string) !map[string]string { mut owners := map[string]string{} for path in paths { owners[path] = '' } for entry in os.ls(database)! { if entry == 'ALPM_DB_VERSION' { continue } dir := os.join_path(database, entry) desc := '\n' + os.read_file(os.join_path(dir, 'desc'))! if !desc.contains('\n%NAME%\n') { return error('missing package name in ${entry}') } name := desc.all_after('\n%NAME%\n').all_before('\n') files := os.read_file(os.join_path(dir, 'files'))! if !files.starts_with('%FILES%\n') { return error('missing file list in ${entry}') } for file in files.all_after('%FILES%\n').all_before('\n\n').split_into_lines() { path := '/' + file if path !in owners { continue } if owners[path] != '' { return error('${path} is owned by both ${owners[path]} and ${name}') } owners[path] = name } } for path in paths { if owners[path] == '' { return error('published BusyBox path has no package owner: ${path}') } } return owners } fn main() { if os.args.len !in [2, 3] { eprintln('usage: release-links ROOT_TARBALL [INSTALLED_LOCAL_DB]') exit(2) } links := release_links(os.args[1]) or { eprintln(err) exit(1) } if os.args.len == 3 { owners := installed_owners(os.args[2], links) or { eprintln(err) exit(1) } for name in links { println('${name}\t${owners[name]}') } } else { for name in links { println(name) } } }