Compare commits
5 Commits
dec35b4c8f
...
d2c2f09ec3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d2c2f09ec3 | ||
![]() |
8f779d005f | ||
![]() |
36dae8ca6e | ||
![]() |
d5c3e55613 | ||
![]() |
784c28af77 |
@ -4,5 +4,5 @@ rest_url = "{}"
|
||||
|
||||
[auth]
|
||||
username = "{}"
|
||||
password = "{}"
|
||||
# oauth2_token = "{}"
|
||||
# password = "{}"
|
||||
oauth2_token = "{}"
|
||||
|
28
src/main.rs
28
src/main.rs
@ -26,7 +26,7 @@ struct SetupArgs {
|
||||
username: String,
|
||||
/// Specify the botpassword of the bot
|
||||
#[arg(long, env = "MW_BOTPASSWORD")]
|
||||
botpassword: String,
|
||||
botpassword: Option<String>,
|
||||
/// Specify the OAuth2 token of the bot
|
||||
#[arg(long, env = "MW_OAUTH2")]
|
||||
oauth2_token: String,
|
||||
@ -47,16 +47,26 @@ enum Action {
|
||||
Run,
|
||||
}
|
||||
|
||||
fn read_config_template() -> Result<String, std::io::Error> {
|
||||
std::fs::read_to_string(CONFIG_TEMPLATE_PATH).or(Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("Unable to find {}; did you execute the script from the same directory?", CONFIG_TEMPLATE_PATH))))
|
||||
}
|
||||
|
||||
fn fill_config_template(config_template: String, args: SetupArgs) -> String {
|
||||
formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword.unwrap_or("".into()), args.oauth2_token).unwrap()
|
||||
}
|
||||
|
||||
// Fix permissions on UNIX-like systems, since mwbot-rs doesn't like to read configs with loose permissions.
|
||||
fn constrain_unix_permissions(path: &PathBuf) -> Result<(), std::io::Error> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))
|
||||
}
|
||||
|
||||
fn setup(args: SetupArgs) -> Result<(), std::io::Error> {
|
||||
let config_template = std::fs::read_to_string(CONFIG_TEMPLATE_PATH).or(Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("Unable to find {}; did you execute the script from the same directory?", CONFIG_TEMPLATE_PATH))))?;
|
||||
let filled_in_config = formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword, args.oauth2_token).unwrap();
|
||||
let config_template = read_config_template()?;
|
||||
let filled_in_config = fill_config_template(config_template, args);
|
||||
let path = get_bot_config_path();
|
||||
std::fs::write(&path, filled_in_config).unwrap();
|
||||
// Fix permissions on UNIX-like systems, since mwbot-rs doesn't like to read configs with loose permissions.
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))?;
|
||||
}
|
||||
std::fs::write(&path, filled_in_config)?;
|
||||
constrain_unix_permissions(&path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user