mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-12 15:24:14 +03:00
82 lines
1.6 KiB
Ruby
Executable File
82 lines
1.6 KiB
Ruby
Executable File
#!/usr/bin/env nix-shell
|
||
#!nix-shell -p ruby -i ruby
|
||
|
||
require "shellwords"
|
||
ROOT = File.join(__dir__, "..")
|
||
|
||
def usage()
|
||
puts "Usage: bin/menuconfig [--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 =
|
||
# 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
|
||
|
||
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
|
||
$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
|
||
tool = File.join(`#{[
|
||
"nix-build",
|
||
"--no-out-link",
|
||
*arg,
|
||
"-A", "config.mobile.boot.stage-1.kernel.package.menuconfig"
|
||
].shelljoin}`.strip, "bin/nconf")
|
||
|
||
if ONLY_SAVE
|
||
# Equivalent to F9,Enter
|
||
`echo -e "[20~\n" | #{[tool, FILE].shelljoin}`
|
||
else
|
||
system(tool, FILE)
|
||
end
|
||
|
||
unless $?.success?
|
||
exit $?.exitstatus
|
||
end
|
||
|
||
# Force normalize at the end. Otherwise recent kernels (5.8+) will have the wrong compiler data.
|
||
exec(File.join(ROOT, "bin", "kernel-normalize-config"), *ARGV)
|
||
end
|
||
|
||
# vim: ft=ruby
|