forked from svenstaro/genact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:svenstaro/genact
- Loading branch information
Showing
8 changed files
with
257 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[Makefile] | ||
indent_style = tab | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
base | ||
udev | ||
usr | ||
resume | ||
autodetect | ||
modconf | ||
block | ||
net | ||
mdadm | ||
mdadm_udev | ||
keyboard | ||
keymap | ||
consolefont | ||
encrypt | ||
lvm2 | ||
fsck | ||
filesystems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
5.0.7-arch1-1-ARCH | ||
5.2 | ||
2.6.32-431.el6.i686 | ||
9.0.2.2 | ||
1.5.19(0.150/4/2) | ||
2.2.1(0.289/5/3) | ||
3.1.9+ | ||
3.6.11+ | ||
8.0.1-amd64 | ||
2.13-DEVELOPMENT | ||
6.1-RELEASE-p15 | ||
9.0-RELEASE | ||
2.6.34-gentoo-r12 | ||
8.11.11 | ||
2.6.35-22-generic | ||
2.6.38.8-g2593b11 | ||
12.3.0 | ||
3.17.3-1-MANJARO | ||
2.6.22.5-31-default | ||
2.6.38-10-generic | ||
2.6.35.7-unity1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
use crate::parse_args::AppConfig; | ||
use crate::utils::csleep; | ||
use crate::{BOOT_HOOKS_LIST, CFILES_LIST, COMPRESSION_ALGORITHMS_LIST, OS_RELEASES_LIST}; | ||
use rand::prelude::*; | ||
use rand::seq::SliceRandom; | ||
use regex::Regex; | ||
use yansi::Paint; | ||
|
||
const REQUIRED_HOOKS: &[&str] = &[ | ||
&"base", | ||
&"udev", | ||
&"autodetect", | ||
&"modconf", | ||
&"block", | ||
&"fsck", | ||
&"filesystems", | ||
]; | ||
|
||
fn warn(msg: &str) { | ||
println!( | ||
"{}{}", | ||
Paint::yellow("==> WARNING: ").bold(), | ||
Paint::new(msg).bold() | ||
); | ||
} | ||
|
||
fn msg1(msg: &str) { | ||
println!("{}{}", Paint::green("==> ").bold(), Paint::new(msg).bold()); | ||
} | ||
|
||
fn msg2(msg: &str) { | ||
println!("{}{}", Paint::blue(" -> ").bold(), Paint::new(msg).bold()); | ||
} | ||
|
||
fn build( | ||
hooks: &[&str], | ||
preset: &str, | ||
mode: &str, | ||
zip: &str, | ||
drivers: &[&str], | ||
os_release: &str, | ||
appconfig: &AppConfig, | ||
) { | ||
let mut rng = thread_rng(); | ||
|
||
msg1( | ||
format!( | ||
"Building image from preset: /etc/mkinitcpio.d/{preset}.preset: '{mode}'", | ||
preset = preset, | ||
mode = mode | ||
) | ||
.as_ref(), | ||
); | ||
|
||
let image = format!( | ||
"/boot/initramfs-{preset}{suffix}.img", | ||
preset = preset, | ||
suffix = if mode == "default" { | ||
"".to_string() | ||
} else { | ||
format!("-{}", mode) | ||
} | ||
); | ||
|
||
msg2( | ||
format!( | ||
"-k /boot/vmlinuz-{preset} -c /etc/mkinitcpio.conf -g {image}", | ||
preset = preset, | ||
image = image | ||
) | ||
.as_ref(), | ||
); | ||
msg1(format!("Starting build: {}", os_release).as_ref()); | ||
|
||
for hook in hooks { | ||
msg2(format!("Running build hook: [{}]", hook).as_ref()); | ||
csleep(rng.gen_range(50, 1000)); | ||
|
||
if *hook == "block" && mode == "fallback" { | ||
for driver in drivers { | ||
warn(format!("Possibly missing firmware for module: {}", driver).as_ref()); | ||
} | ||
} | ||
|
||
if appconfig.should_exit() { | ||
return; | ||
} | ||
} | ||
|
||
msg1("Generating module dependencies"); | ||
csleep(rng.gen_range(200, 500)); | ||
|
||
msg1( | ||
format!( | ||
"Creating {zip}-compressed initcpio image: {image}", | ||
image = image, | ||
zip = zip | ||
) | ||
.as_ref(), | ||
); | ||
csleep(rng.gen_range(500, 2500)); | ||
|
||
msg1("Image generation successful"); | ||
} | ||
|
||
pub fn run(appconfig: &AppConfig) { | ||
let mut rng = thread_rng(); | ||
|
||
// Select a few hooks from the list of all hooks (in order). Make sure the required default | ||
// hooks are also included (also, in order). | ||
let hooks = { | ||
let mut ret: Vec<&str> = vec![]; | ||
for hook in BOOT_HOOKS_LIST.iter() { | ||
if REQUIRED_HOOKS.contains(hook) || rng.gen_range(0, 10) < 3 { | ||
ret.push(&hook); | ||
} | ||
} | ||
ret | ||
}; | ||
|
||
// Find some "drivers" that cannot find firmware in fallback mode, by identifying files in the | ||
// kernel under driverr/scsi/**/*.c and use their file name (without extension) as the kernel | ||
// module name. It may not be 100% what happens, but it's close enough and looks reasonable. | ||
let drivers = { | ||
let mut ret: Vec<&str> = vec![]; | ||
|
||
let re = Regex::new(r"^drivers/scsi.*/([^/\.]+).c$").unwrap(); | ||
|
||
let count = rng.gen_range(0, 5); | ||
while ret.len() < count { | ||
let file = CFILES_LIST.choose(&mut rng).unwrap(); | ||
|
||
if let Some(m) = re.captures(file) { | ||
ret.push(m.get(1).unwrap().as_str()); | ||
} | ||
} | ||
ret | ||
}; | ||
|
||
// For now, the preset is always the same. | ||
let preset = "linux"; | ||
let os_release = OS_RELEASES_LIST.choose(&mut rng).unwrap(); | ||
let zip = COMPRESSION_ALGORITHMS_LIST.choose(&mut rng).unwrap(); | ||
|
||
build( | ||
&hooks, preset, "default", zip, &drivers, os_release, &appconfig, | ||
); | ||
build( | ||
&hooks, preset, "fallback", zip, &drivers, os_release, &appconfig, | ||
); | ||
} |
Oops, something went wrong.