Skip to content

Commit 05308ce

Browse files
committed
Merge branch 'master' of github.com:svenstaro/genact
2 parents 8fe2271 + f6fe91b commit 05308ce

File tree

8 files changed

+257
-40
lines changed

8 files changed

+257
-40
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
charset = utf-8
8+
indent_style = space
9+
indent_size = 4
10+
11+
[Makefile]
12+
indent_style = tab
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ yansi = "0.5"
2020
rand = "0.6.4"
2121
chrono = "0.4"
2222
url = "1.6"
23-
lazy_static = "1.0"
23+
lazy_static = "1.3"
2424
humantime = "1.1"
25-
regex = "1.0"
25+
regex = "1.1"
2626
fake = "1.2.2"
2727

2828
[target.'cfg(not(target_os = "emscripten"))'.dependencies]

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# genact - a nonsense activity generator
22

33
[![Build Status](https://travis-ci.org/svenstaro/genact.svg?branch=master)](https://travis-ci.org/svenstaro/genact)
4-
[![Snap Status](https://build.snapcraft.io/badge/svenstaro/genact.svg)](https://build.snapcraft.io/user/svenstaro/genact)
4+
[![DockerHub](https://img.shields.io/docker/build/svenstaro/genact.svg?style=flat)](https://cloud.docker.com/repository/docker/svenstaro/genact)
55
[![AUR](https://img.shields.io/aur/version/genact.svg)](https://aur.archlinux.org/packages/genact/)
66
[![Crates.io](https://img.shields.io/crates/v/genact.svg)](https://crates.io/crates/genact)
77
[![dependency status](https://deps.rs/repo/github/svenstaro/genact/status.svg)](https://deps.rs/repo/github/svenstaro/genact)
@@ -11,9 +11,9 @@
1111

1212
Pretend to be busy or waiting for your computer when you should actually be doing real work! Impress people with your insane multitasking skills. Just open a few instances of `genact` and watch the show. `genact` has multiple scenes that pretend to be doing something exciting or useful when in reality nothing is happening at all.
1313

14-
![](https://svenstaro.org/genact/cc.gif)
15-
![](https://svenstaro.org/genact/memdump.gif)
16-
![](https://svenstaro.org/genact/cargo.gif)
14+
![](gifs/cc.gif)
15+
![](gifs/memdump.gif)
16+
![](gifs/cargo.gif)
1717

1818
## Installation
1919

data/boot_hooks.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
base
2+
udev
3+
usr
4+
resume
5+
autodetect
6+
modconf
7+
block
8+
net
9+
mdadm
10+
mdadm_udev
11+
keyboard
12+
keymap
13+
consolefont
14+
encrypt
15+
lvm2
16+
fsck
17+
filesystems

data/os_releases.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
5.0.7-arch1-1-ARCH
2+
5.2
3+
2.6.32-431.el6.i686
4+
9.0.2.2
5+
1.5.19(0.150/4/2)
6+
2.2.1(0.289/5/3)
7+
3.1.9+
8+
3.6.11+
9+
8.0.1-amd64
10+
2.13-DEVELOPMENT
11+
6.1-RELEASE-p15
12+
9.0-RELEASE
13+
2.6.34-gentoo-r12
14+
8.11.11
15+
2.6.35-22-generic
16+
2.6.38.8-g2593b11
17+
12.3.0
18+
3.17.3-1-MANJARO
19+
2.6.22.5-31-default
20+
2.6.38-10-generic
21+
2.6.35.7-unity1

src/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ extern crate fake;
3030
mod bootlog;
3131
mod botnet;
3232
mod cargo;
33-
mod composer;
3433
mod cc;
34+
mod composer;
3535
mod cryptomining;
36-
mod simcity;
3736
mod download;
3837
mod kernel_compile;
39-
mod weblog;
4038
mod memdump;
39+
mod mkinitcpio;
40+
mod simcity;
41+
mod weblog;
42+
4143
mod utils;
4244
mod parse_args;
4345

@@ -50,20 +52,26 @@ static CFILES: &str = include_str!("../data/cfiles.txt");
5052
static PACKAGES: &str = include_str!("../data/packages.txt");
5153
static COMPOSERS: &str = include_str!("../data/composer.txt");
5254
static SIMCITY: &str = include_str!("../data/simcity.txt");
55+
static BOOT_HOOKS: &str = include_str!("../data/boot_hooks.txt");
56+
static OS_RELEASES: &str = include_str!("../data/os_releases.txt");
5357

5458
lazy_static! {
5559
static ref BOOTLOG_LIST: Vec<&'static str> = BOOTLOG.lines().collect();
5660
static ref CFILES_LIST: Vec<&'static str> = CFILES.lines().collect();
5761
static ref PACKAGES_LIST: Vec<&'static str> = PACKAGES.lines().collect();
5862
static ref COMPOSERS_LIST: Vec<&'static str> = COMPOSERS.lines().collect();
5963
static ref SIMCITY_LIST: Vec<&'static str> = SIMCITY.lines().collect();
64+
static ref BOOT_HOOKS_LIST: Vec<&'static str> = BOOT_HOOKS.lines().collect();
65+
static ref OS_RELEASES_LIST: Vec<&'static str> = OS_RELEASES.lines().collect();
6066
}
6167

6268
static EXTENSIONS_LIST: &'static [&str] = &["gif", "webm", "mp4", "html", "php", "md",
6369
"png", "jpg", "ogg", "mp3", "flac", "iso",
6470
"zip", "rar", "tar.gz", "tar.bz2", "tar.xz",
6571
"deb", "rpm", "exe"];
6672

73+
static COMPRESSION_ALGORITHMS_LIST: &'static [&str] = &["gzip", "bzip2", "lzma", "xz", "lzop", "lz4"];
74+
6775
#[cfg(not(target_os = "emscripten"))]
6876
use std::sync::atomic::AtomicBool;
6977

@@ -85,6 +93,7 @@ fn main() {
8593
"simcity",
8694
"download",
8795
"memdump",
96+
"mkinitcpio",
8897
"kernel_compile",
8998
"weblog",
9099
// "bruteforce",
@@ -125,6 +134,7 @@ fn main() {
125134
"cargo" => cargo::run(&appconfig),
126135
"cryptomining" => cryptomining::run(&appconfig),
127136
"simcity" => simcity::run(&appconfig),
137+
"mkinitcpio" => mkinitcpio::run(&appconfig),
128138
"cc" => cc::run(&appconfig),
129139
"download" => download::run(&appconfig),
130140
"memdump" => memdump::run(&appconfig),

src/mkinitcpio.rs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
use crate::parse_args::AppConfig;
2+
use crate::utils::csleep;
3+
use crate::{BOOT_HOOKS_LIST, CFILES_LIST, COMPRESSION_ALGORITHMS_LIST, OS_RELEASES_LIST};
4+
use rand::prelude::*;
5+
use rand::seq::SliceRandom;
6+
use regex::Regex;
7+
use yansi::Paint;
8+
9+
const REQUIRED_HOOKS: &[&str] = &[
10+
&"base",
11+
&"udev",
12+
&"autodetect",
13+
&"modconf",
14+
&"block",
15+
&"fsck",
16+
&"filesystems",
17+
];
18+
19+
fn warn(msg: &str) {
20+
println!(
21+
"{}{}",
22+
Paint::yellow("==> WARNING: ").bold(),
23+
Paint::new(msg).bold()
24+
);
25+
}
26+
27+
fn msg1(msg: &str) {
28+
println!("{}{}", Paint::green("==> ").bold(), Paint::new(msg).bold());
29+
}
30+
31+
fn msg2(msg: &str) {
32+
println!("{}{}", Paint::blue(" -> ").bold(), Paint::new(msg).bold());
33+
}
34+
35+
fn build(
36+
hooks: &[&str],
37+
preset: &str,
38+
mode: &str,
39+
zip: &str,
40+
drivers: &[&str],
41+
os_release: &str,
42+
appconfig: &AppConfig,
43+
) {
44+
let mut rng = thread_rng();
45+
46+
msg1(
47+
format!(
48+
"Building image from preset: /etc/mkinitcpio.d/{preset}.preset: '{mode}'",
49+
preset = preset,
50+
mode = mode
51+
)
52+
.as_ref(),
53+
);
54+
55+
let image = format!(
56+
"/boot/initramfs-{preset}{suffix}.img",
57+
preset = preset,
58+
suffix = if mode == "default" {
59+
"".to_string()
60+
} else {
61+
format!("-{}", mode)
62+
}
63+
);
64+
65+
msg2(
66+
format!(
67+
"-k /boot/vmlinuz-{preset} -c /etc/mkinitcpio.conf -g {image}",
68+
preset = preset,
69+
image = image
70+
)
71+
.as_ref(),
72+
);
73+
msg1(format!("Starting build: {}", os_release).as_ref());
74+
75+
for hook in hooks {
76+
msg2(format!("Running build hook: [{}]", hook).as_ref());
77+
csleep(rng.gen_range(50, 1000));
78+
79+
if *hook == "block" && mode == "fallback" {
80+
for driver in drivers {
81+
warn(format!("Possibly missing firmware for module: {}", driver).as_ref());
82+
}
83+
}
84+
85+
if appconfig.should_exit() {
86+
return;
87+
}
88+
}
89+
90+
msg1("Generating module dependencies");
91+
csleep(rng.gen_range(200, 500));
92+
93+
msg1(
94+
format!(
95+
"Creating {zip}-compressed initcpio image: {image}",
96+
image = image,
97+
zip = zip
98+
)
99+
.as_ref(),
100+
);
101+
csleep(rng.gen_range(500, 2500));
102+
103+
msg1("Image generation successful");
104+
}
105+
106+
pub fn run(appconfig: &AppConfig) {
107+
let mut rng = thread_rng();
108+
109+
// Select a few hooks from the list of all hooks (in order). Make sure the required default
110+
// hooks are also included (also, in order).
111+
let hooks = {
112+
let mut ret: Vec<&str> = vec![];
113+
for hook in BOOT_HOOKS_LIST.iter() {
114+
if REQUIRED_HOOKS.contains(hook) || rng.gen_range(0, 10) < 3 {
115+
ret.push(&hook);
116+
}
117+
}
118+
ret
119+
};
120+
121+
// Find some "drivers" that cannot find firmware in fallback mode, by identifying files in the
122+
// kernel under driverr/scsi/**/*.c and use their file name (without extension) as the kernel
123+
// module name. It may not be 100% what happens, but it's close enough and looks reasonable.
124+
let drivers = {
125+
let mut ret: Vec<&str> = vec![];
126+
127+
let re = Regex::new(r"^drivers/scsi.*/([^/\.]+).c$").unwrap();
128+
129+
let count = rng.gen_range(0, 5);
130+
while ret.len() < count {
131+
let file = CFILES_LIST.choose(&mut rng).unwrap();
132+
133+
if let Some(m) = re.captures(file) {
134+
ret.push(m.get(1).unwrap().as_str());
135+
}
136+
}
137+
ret
138+
};
139+
140+
// For now, the preset is always the same.
141+
let preset = "linux";
142+
let os_release = OS_RELEASES_LIST.choose(&mut rng).unwrap();
143+
let zip = COMPRESSION_ALGORITHMS_LIST.choose(&mut rng).unwrap();
144+
145+
build(
146+
&hooks, preset, "default", zip, &drivers, os_release, &appconfig,
147+
);
148+
build(
149+
&hooks, preset, "fallback", zip, &drivers, os_release, &appconfig,
150+
);
151+
}

0 commit comments

Comments
 (0)