diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-03-06 14:36:48 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-03-16 12:54:27 +0100 |
| commit | bf5de2975055790e0dd319324b5342f11b6e92e3 (patch) | |
| tree | aea9ae4b5ec9b122de73376ee3d56ea1812fa54a | |
| parent | a5b4f1a85679693f2546f4ebc7ea94f287ce1175 (diff) | |
| download | mullvadvpn-bf5de2975055790e0dd319324b5342f11b6e92e3.tar.xz mullvadvpn-bf5de2975055790e0dd319324b5342f11b6e92e3.zip | |
Placeholder tool for managing Mullvad daemon setup
| -rw-r--r-- | Cargo.lock | 15 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | mullvad-setup/Cargo.toml | 33 | ||||
| -rw-r--r-- | mullvad-setup/build.rs | 18 | ||||
| -rw-r--r-- | mullvad-setup/src/main.rs | 51 | ||||
| -rwxr-xr-x | version_metadata.sh | 3 |
6 files changed, 121 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock index 0a43069b74..22ed06c8d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1386,6 +1386,21 @@ dependencies = [ ] [[package]] +name = "mullvad-setup" +version = "2020.3.0" +dependencies = [ + "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "err-derive 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mullvad-ipc-client 0.1.0", + "mullvad-paths 0.1.0", + "talpid-core 0.1.0", + "talpid-types 0.1.0", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winres 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "mullvad-tests" version = "0.1.0" dependencies = [ diff --git a/Cargo.toml b/Cargo.toml index c25bc54279..bbaaee503a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "mullvad-daemon", "mullvad-cli", + "mullvad-setup", "mullvad-problem-report", "mullvad-ipc-client", "mullvad-jni", diff --git a/mullvad-setup/Cargo.toml b/mullvad-setup/Cargo.toml new file mode 100644 index 0000000000..b467a7b174 --- /dev/null +++ b/mullvad-setup/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "mullvad-setup" +version = "2020.3.0" +authors = ["Mullvad VPN"] +description = "Tool used to manage daemon setup" +license = "GPL-3.0" +edition = "2018" +publish = false + +[[bin]] +name = "mullvad-setup" +path = "src/main.rs" + +[dependencies] +clap = "2.32" +env_logger = "0.7" +err-derive = "0.2.1" + +mullvad-ipc-client = { path = "../mullvad-ipc-client" } +mullvad-paths = { path = "../mullvad-paths" } +talpid-core = { path = "../talpid-core" } +talpid-types = { path = "../talpid-types" } + +[target.'cfg(windows)'.build-dependencies] +winres = "0.1" +winapi = "0.3" + +[package.metadata.winres] +ProductName = "Mullvad VPN" +CompanyName = "Mullvad VPN AB" +LegalCopyright = "(c) 2020 Mullvad VPN AB" +InternalName = "mullvad-setup" +OriginalFilename = "mullvad-setup.exe" diff --git a/mullvad-setup/build.rs b/mullvad-setup/build.rs new file mode 100644 index 0000000000..8cdd992c7c --- /dev/null +++ b/mullvad-setup/build.rs @@ -0,0 +1,18 @@ +use std::{env, fs, path::PathBuf}; + +fn main() { + let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + let product_version = env!("CARGO_PKG_VERSION").replacen(".0", "", 1); + fs::write(out_dir.join("product-version.txt"), &product_version).unwrap(); + + #[cfg(windows)] + { + let mut res = winres::WindowsResource::new(); + res.set("ProductVersion", &product_version); + res.set_language(winapi::um::winnt::MAKELANGID( + winapi::um::winnt::LANG_ENGLISH, + winapi::um::winnt::SUBLANG_ENGLISH_US, + )); + res.compile().expect("Unable to generate windows resources"); + } +} diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs new file mode 100644 index 0000000000..9034d7c1f7 --- /dev/null +++ b/mullvad-setup/src/main.rs @@ -0,0 +1,51 @@ +use clap::{crate_authors, crate_description, crate_name, SubCommand}; +use std::process; +use talpid_types::ErrorExt; + +pub const PRODUCT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/product-version.txt")); + +#[derive(err_derive::Error, Debug)] +pub enum Error { +} + +fn main() { + env_logger::init(); + + let subcommands = vec![ + SubCommand::with_name("prepare-restart") + .about("Move a running daemon into a blocking state and save its target state"), + SubCommand::with_name("reset-firewall") + .about("Remove any firewall rules introduced by the daemon"), + ]; + + let app = clap::App::new(crate_name!()) + .version(PRODUCT_VERSION) + .author(crate_authors!()) + .about(crate_description!()) + .setting(clap::AppSettings::SubcommandRequiredElseHelp) + .global_settings(&[ + clap::AppSettings::DisableHelpSubcommand, + clap::AppSettings::VersionlessSubcommands, + ]) + .subcommands(subcommands); + + let matches = app.get_matches(); + let result = match matches.subcommand_name().expect("Subcommand has no name") { + "prepare-restart" => prepare_restart(), + "reset-firewall" => reset_firewall(), + _ => unreachable!("No command matched"), + }; + + if let Err(e) = result { + eprintln!("{}", e.display_chain()); + process::exit(1); + } +} + +fn prepare_restart() -> Result<(), Error> { + Ok(()) +} + +fn reset_firewall() -> Result<(), Error> { + Ok(()) +} diff --git a/version_metadata.sh b/version_metadata.sh index 55f5df631b..93344bba40 100755 --- a/version_metadata.sh +++ b/version_metadata.sh @@ -39,6 +39,7 @@ case "$1" in mullvad-daemon/Cargo.toml \ mullvad-cli/Cargo.toml \ mullvad-problem-report/Cargo.toml \ + mullvad-setup/Cargo.toml \ talpid-openvpn-plugin/Cargo.toml # Windows C++ @@ -67,6 +68,7 @@ EOF mv mullvad-daemon/Cargo.toml.bak mullvad-daemon/Cargo.toml || true mv mullvad-cli/Cargo.toml.bak mullvad-cli/Cargo.toml || true mv mullvad-problem-report/Cargo.toml.bak mullvad-problem-report/Cargo.toml || true + mv mullvad-setup/Cargo.toml.bak mullvad-setup/Cargo.toml || true mv talpid-openvpn-plugin/Cargo.toml.bak talpid-openvpn-plugin/Cargo.toml || true # Windows C++ mv dist-assets/windows/version.h.bak dist-assets/windows/version.h || true @@ -83,6 +85,7 @@ EOF rm mullvad-daemon/Cargo.toml.bak || true rm mullvad-cli/Cargo.toml.bak || true rm mullvad-problem-report/Cargo.toml.bak || true + rm mullvad-setup/Cargo.toml.bak || true rm talpid-openvpn-plugin/Cargo.toml.bak || true # Windows C++ rm dist-assets/windows/version.h.bak || true |
