Skip to content

Commit

Permalink
Merge branch 'master' of github.com:svenstaro/genact
Browse files Browse the repository at this point in the history
  • Loading branch information
svenstaro committed Apr 22, 2019
2 parents 8fe2271 + f6fe91b commit 05308ce
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 40 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ yansi = "0.5"
rand = "0.6.4"
chrono = "0.4"
url = "1.6"
lazy_static = "1.0"
lazy_static = "1.3"
humantime = "1.1"
regex = "1.0"
regex = "1.1"
fake = "1.2.2"

[target.'cfg(not(target_os = "emscripten"))'.dependencies]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# genact - a nonsense activity generator

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

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.

![](https://svenstaro.org/genact/cc.gif)
![](https://svenstaro.org/genact/memdump.gif)
![](https://svenstaro.org/genact/cargo.gif)
![](gifs/cc.gif)
![](gifs/memdump.gif)
![](gifs/cargo.gif)

## Installation

Expand Down
17 changes: 17 additions & 0 deletions data/boot_hooks.txt
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
21 changes: 21 additions & 0 deletions data/os_releases.txt
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
16 changes: 13 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ extern crate fake;
mod bootlog;
mod botnet;
mod cargo;
mod composer;
mod cc;
mod composer;
mod cryptomining;
mod simcity;
mod download;
mod kernel_compile;
mod weblog;
mod memdump;
mod mkinitcpio;
mod simcity;
mod weblog;

mod utils;
mod parse_args;

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

lazy_static! {
static ref BOOTLOG_LIST: Vec<&'static str> = BOOTLOG.lines().collect();
static ref CFILES_LIST: Vec<&'static str> = CFILES.lines().collect();
static ref PACKAGES_LIST: Vec<&'static str> = PACKAGES.lines().collect();
static ref COMPOSERS_LIST: Vec<&'static str> = COMPOSERS.lines().collect();
static ref SIMCITY_LIST: Vec<&'static str> = SIMCITY.lines().collect();
static ref BOOT_HOOKS_LIST: Vec<&'static str> = BOOT_HOOKS.lines().collect();
static ref OS_RELEASES_LIST: Vec<&'static str> = OS_RELEASES.lines().collect();
}

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

static COMPRESSION_ALGORITHMS_LIST: &'static [&str] = &["gzip", "bzip2", "lzma", "xz", "lzop", "lz4"];

#[cfg(not(target_os = "emscripten"))]
use std::sync::atomic::AtomicBool;

Expand All @@ -85,6 +93,7 @@ fn main() {
"simcity",
"download",
"memdump",
"mkinitcpio",
"kernel_compile",
"weblog",
// "bruteforce",
Expand Down Expand Up @@ -125,6 +134,7 @@ fn main() {
"cargo" => cargo::run(&appconfig),
"cryptomining" => cryptomining::run(&appconfig),
"simcity" => simcity::run(&appconfig),
"mkinitcpio" => mkinitcpio::run(&appconfig),
"cc" => cc::run(&appconfig),
"download" => download::run(&appconfig),
"memdump" => memdump::run(&appconfig),
Expand Down
151 changes: 151 additions & 0 deletions src/mkinitcpio.rs
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,
);
}
Loading

0 comments on commit 05308ce

Please sign in to comment.