2020-03-27 05:12:34 +03:00
|
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
|
#!nix-shell -p ruby -i ruby
|
|
|
|
|
|
|
|
|
|
require "shellwords"
|
|
|
|
|
ROOT = File.join(__dir__, "..")
|
|
|
|
|
|
|
|
|
|
def usage()
|
|
|
|
|
puts "Usage: #{$PROGRAM_NAME} [--only-save] <device_name>"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
DEVICE = other_args.shift
|
|
|
|
|
FILE = Dir.glob(File.join(ROOT, "devices", DEVICE, "kernel", "config.*")).sort.first
|
|
|
|
|
|
|
|
|
|
ONLY_SAVE = !!params.delete("--only-save")
|
|
|
|
|
|
|
|
|
|
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.exists?(FILE)
|
|
|
|
|
$stderr.puts "Could not find kernel configuration file for #{DEVICE}."
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Dir.chdir(ROOT) do
|
|
|
|
|
tool = File.join(`#{[
|
|
|
|
|
"nix-build",
|
|
|
|
|
"--no-out-link",
|
|
|
|
|
"--argstr", "device", DEVICE,
|
2020-05-26 18:51:43 +03:00
|
|
|
|
"-A", "config.mobile.boot.stage-1.kernel.package.menuconfig"
|
2020-03-27 05:12:34 +03:00
|
|
|
|
].shelljoin}`.strip, "bin/nconf")
|
|
|
|
|
|
|
|
|
|
if ONLY_SAVE
|
|
|
|
|
# Equivalent to F9,Enter
|
|
|
|
|
`echo -e "[20~\n" | #{[tool, FILE].shelljoin}`
|
|
|
|
|
else
|
|
|
|
|
system(tool, FILE)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# vim: ft=ruby
|