mirror of
https://github.com/NixOS/mobile-nixos.git
synced 2024-12-18 05:21:47 +03:00
58 lines
1.2 KiB
Plaintext
58 lines
1.2 KiB
Plaintext
|
#!/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,
|
|||
|
"-A", "config.mobile.device.info.kernel.menuconfig"
|
|||
|
].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
|