Compare commits
No commits in common. "d2c2f09ec38e94067dfc5eb669a9d8f7434ab6c7" and "dec35b4c8f0f79aa90f958761edcbd0d45ca5ee1" have entirely different histories.
d2c2f09ec3
...
dec35b4c8f
@ -4,5 +4,5 @@ rest_url = "{}"
|
|||||||
|
|
||||||
[auth]
|
[auth]
|
||||||
username = "{}"
|
username = "{}"
|
||||||
# password = "{}"
|
password = "{}"
|
||||||
oauth2_token = "{}"
|
# oauth2_token = "{}"
|
||||||
|
28
src/main.rs
28
src/main.rs
@ -26,7 +26,7 @@ struct SetupArgs {
|
|||||||
username: String,
|
username: String,
|
||||||
/// Specify the botpassword of the bot
|
/// Specify the botpassword of the bot
|
||||||
#[arg(long, env = "MW_BOTPASSWORD")]
|
#[arg(long, env = "MW_BOTPASSWORD")]
|
||||||
botpassword: Option<String>,
|
botpassword: String,
|
||||||
/// Specify the OAuth2 token of the bot
|
/// Specify the OAuth2 token of the bot
|
||||||
#[arg(long, env = "MW_OAUTH2")]
|
#[arg(long, env = "MW_OAUTH2")]
|
||||||
oauth2_token: String,
|
oauth2_token: String,
|
||||||
@ -47,26 +47,16 @@ enum Action {
|
|||||||
Run,
|
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> {
|
fn setup(args: SetupArgs) -> Result<(), std::io::Error> {
|
||||||
let config_template = read_config_template()?;
|
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 = fill_config_template(config_template, args);
|
let filled_in_config = formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword, args.oauth2_token).unwrap();
|
||||||
let path = get_bot_config_path();
|
let path = get_bot_config_path();
|
||||||
std::fs::write(&path, filled_in_config)?;
|
std::fs::write(&path, filled_in_config).unwrap();
|
||||||
constrain_unix_permissions(&path)?;
|
// 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))?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user