mirror of
https://github.com/epi052/feroxbuster.git
synced 2026-05-20 02:11:13 -03:00
config file is dropped to disk when installing via cargo
This commit is contained in:
@@ -19,6 +19,7 @@ maintenance = { status = "actively-developed" }
|
||||
clap = "2.33"
|
||||
regex = "1"
|
||||
lazy_static = "1.4"
|
||||
dirs = "3.0"
|
||||
|
||||
[dependencies]
|
||||
futures = { version = "0.3.14"}
|
||||
|
||||
29
build.rs
29
build.rs
@@ -1,6 +1,7 @@
|
||||
use std::fs::OpenOptions;
|
||||
use std::fs::{copy, create_dir_all, OpenOptions};
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
extern crate clap;
|
||||
extern crate dirs;
|
||||
|
||||
use clap::Shell;
|
||||
|
||||
@@ -47,4 +48,30 @@ fn main() {
|
||||
bash_file
|
||||
.write_all(contents.as_bytes())
|
||||
.expect("Couldn't write updated bash completion script to disk");
|
||||
|
||||
// hunter0x8 let me know that when installing via cargo, it would be nice if we dropped a
|
||||
// config file during the build process. The following code will place an example config in
|
||||
// the user's configuration directory
|
||||
// - linux: $XDG_CONFIG_HOME or $HOME/.config
|
||||
// - macOS: $HOME/Library/Application Support
|
||||
// - windows: {FOLDERID_RoamingAppData}
|
||||
let mut config_dir = dirs::config_dir().expect("Couldn't resolve user's config directory");
|
||||
config_dir = config_dir.join("feroxbuster"); // $HOME/.config/feroxbuster
|
||||
|
||||
if !config_dir.exists() {
|
||||
// recursively create the feroxbuster directory and all of its parent components if
|
||||
// they are missing
|
||||
create_dir_all(&config_dir)
|
||||
.expect("Couldn't create one or more directories needed to copy the config file");
|
||||
}
|
||||
|
||||
// hard-coding config name here to not rely on the crate we're building, if DEFAULT_CONFIG_NAME
|
||||
// ever changes, this will need to be updated
|
||||
let config_file = config_dir.join("ferox-config.toml");
|
||||
|
||||
if !config_file.exists() {
|
||||
// config file doesn't exist, add it to the config directory
|
||||
copy("ferox-config.toml.example", config_file)
|
||||
.expect("Couldn't copy example config into config directory");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user