mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-04 21:18:28 +03:00
ea05551be1
This is needed for supporting families. The path to config files can't be guessed as it was previously.
99 lines
2.1 KiB
Ruby
Executable File
99 lines
2.1 KiB
Ruby
Executable File
#!/usr/bin/env nix-shell
|
|
#!nix-shell -p ruby -i ruby
|
|
|
|
# This script is expected to be used to copy back the `kernel-builder` built
|
|
# linux configuration to the kernel's source directory.
|
|
#
|
|
# Use this to normalize the configuration after:
|
|
#
|
|
# - Changing configuration options
|
|
# - Changing the kernel version
|
|
|
|
require "shellwords"
|
|
ROOT = File.join(__dir__, "..")
|
|
|
|
def usage()
|
|
puts "Usage: bin/kernel-normalize-config [--file=config.path] <device_name>"
|
|
puts ""
|
|
puts " --file=path/to/kernel/config.file -- detected automatically if not present."
|
|
end
|
|
|
|
# Poor approximation to arguments parsing.
|
|
params, other_args = ARGV.partition { |s| s.match(/^--/) }
|
|
|
|
if other_args.empty?
|
|
$stderr.puts "Device name required."
|
|
usage
|
|
exit 1
|
|
end
|
|
|
|
# Somewhat embarassing parameter parsing
|
|
params = params.map do |param|
|
|
k, v = param.split("=", 2)
|
|
v = true unless v
|
|
k = k.sub(/^--/, "")
|
|
[k, v]
|
|
end.to_h
|
|
|
|
DEVICE = other_args.shift
|
|
|
|
@file =
|
|
# Is the device a path?
|
|
if DEVICE.match(%r{/})
|
|
Dir.glob(File.join(DEVICE, "kernel", "config.*")).sort.first
|
|
else
|
|
Dir.glob(File.join(Dir.pwd, "devices", DEVICE, "kernel", "config.*")).sort.first
|
|
end
|
|
|
|
if params["file"]
|
|
@file = params.delete("file")
|
|
end
|
|
|
|
unless @file and File.exists?(@file)
|
|
$stderr.puts "Kernel config file not found."
|
|
$stderr.puts "Please provide path to the config file with `--file=...`."
|
|
$stderr.puts
|
|
usage
|
|
exit 1
|
|
end
|
|
|
|
unless params.empty?
|
|
$stderr.puts "Unknown parameters #{params.join(", ")}."
|
|
usage
|
|
exit 1
|
|
end
|
|
|
|
unless other_args.empty?
|
|
$stderr.puts "Unexpected arguments #{other_args.join(", ")}."
|
|
usage
|
|
exit 1
|
|
end
|
|
|
|
unless @file
|
|
$stderr.puts "Could not find kernel configuration file for #{DEVICE}."
|
|
usage
|
|
exit 1
|
|
end
|
|
|
|
arg =
|
|
# Is the device a path?
|
|
if DEVICE.match(%r{/})
|
|
["--arg", "device", DEVICE]
|
|
else
|
|
["--argstr", "device", DEVICE]
|
|
end
|
|
|
|
Dir.chdir(ROOT) do
|
|
result = `#{[
|
|
"nix-build",
|
|
"--no-out-link",
|
|
*arg,
|
|
"-A", "config.mobile.boot.stage-1.kernel.package.normalizedConfig"
|
|
].shelljoin}`.strip
|
|
|
|
# We "cat" into the file to ensure we don't copy the store path access rights.
|
|
File.write(@file, File.read(result))
|
|
end
|
|
|
|
# vim: ft=ruby
|