Skip to content

Commit

Permalink
Regressed dep and fixed other (#421)
Browse files Browse the repository at this point in the history
* Regressed dep and fixed other

* Update Makefile.toml
  • Loading branch information
mbround18 authored Aug 21, 2021
1 parent cf41ad0 commit f9c64a9
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 280 deletions.
333 changes: 125 additions & 208 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Dockerfile.odin
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ FROM mbround18/cargo-make:latest as cargo-make
# ------------------ #
# -- Odin Builder -- #
# ------------------ #
FROM rust as builder
FROM rust:1.54 as builder
WORKDIR /data/odin
COPY . .
# Copy over the cached dependencies
COPY --from=cacher /data/odin/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
COPY --from=cargo-make /usr/local/bin/cargo-make /usr/local/bin/cargo-make
RUN cargo-make make -p production release
COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/
COPY --from=cargo-make /usr/local/bin/cargo-make /usr/local/cargo/bin
RUN /usr/local/cargo/bin/cargo make -p production release

# ------------------ #
# -- Odin Runtime -- #
Expand Down
4 changes: 2 additions & 2 deletions src/odin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "odin"
version = "1.4.0"
version = "1.4.1"
authors = ["mbround18"]
edition = "2018"
license = "BSD-3-Clause License"
Expand Down Expand Up @@ -30,7 +30,7 @@ path = "lib.rs"
handlebars = "4"
dotenv = "0.15.0"
log = "0.4.14"
clap = { version = "3.0.0-beta.2", features = ["yaml"] }
clap = { version = "2.33.3" , features = ["yaml"] }
which = "4.2.2"
serde = { version = "1.0", features = ["derive"], default_features = false }
sysinfo = { version = "0.18.2", default_features = false }
Expand Down
54 changes: 27 additions & 27 deletions src/odin/cli.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: odin
version: "stub"
author: mbround18
about: Installs and Runs Valheim
help: Installs and Runs Valheim
args:
- run_as_root:
long: run-as-root
Expand All @@ -18,11 +18,11 @@ args:
short: r
global: true
long: dry-run
about: Will output the commands that it intends to run.
help: Will output the commands that it intends to run.

subcommands:
- configure:
about: >
help: >
Initializes Odin with its configuration variables.
version: "1.0"
Expand All @@ -31,76 +31,76 @@ subcommands:
- server_executable:
long: server-executable
value_name: SERVER_EXECUTABLE_PATH
about: Sets the servers executable path.
help: Sets the servers executable path.
takes_value: true
default_value: ./valheim_server.x86_64
- name:
short: n
long: name
value_name: NAME
about: Sets the name of the server, (Can be set with ENV variable NAME)
help: Sets the name of the server, (Can be set with ENV variable NAME)
takes_value: true
- port:
short: p
long: port
value_name: PORT
about: Sets the port of the server, (Can be set with ENV variable PORT)
help: Sets the port of the server, (Can be set with ENV variable PORT)
takes_value: true
- world:
short: w
long: world
value_name: WORLD
about: Sets the world of the server, (Can be set with ENV variable WORLD)
help: Sets the world of the server, (Can be set with ENV variable WORLD)
takes_value: true
- password:
short: s
long: password
value_name: PASSWORD
about: Sets the password of the server, (Can be set with ENV variable PASSWORD)
help: Sets the password of the server, (Can be set with ENV variable PASSWORD)
takes_value: true
- public:
short: o
long: public
value_name: PUBLIC
about: Sets the public state of the server, (Can be set with ENV variable PUBLIC)
help: Sets the public state of the server, (Can be set with ENV variable PUBLIC)
takes_value: true
- install:
about: >
help: >
Installs Valheim with steamcmd
version: "2.1"
author: mbround18
- start:
about: >
help: >
Starts Valheim
version: "2.0"
author: mbround18
- stop:
about: >
help: >
Stops Valheim
version: "1.1"
author: mbround18
- backup:
about: >
help: >
Backups the current saves to a specific location
version: "1.0"
author: mbround18
args:
- INPUT_DIR:
about: Directory to back up
help: Directory to back up
required: true
index: 1
- OUTPUT_FILE:
about: Sets the output file to use
help: Sets the output file to use
required: true
index: 2
- update:
version: "1.0"
author: LovecraftianHorror
about: >
help: >
Attempts to update an existing Valheim server installation. By
default this involves checking for an update, if an update is
available, the server will be shut down, updated, and brought back online
Expand All @@ -111,7 +111,7 @@ subcommands:
- check:
long: check
short: c
about: >
help: >
Check for a server update, exiting with 0 if one is available
and 10 if the server is up to date.
Expand All @@ -120,64 +120,64 @@ subcommands:
- force:
long: force
short: f
about: >
help: >
Force an update attempt, even if no update is detected.
conflicts_with:
- check
- notify:
about: >
help: >
Sends a notification to the provided webhook.
version: "1.1"
author: mbround18
args:
- MESSAGE:
about: Message to send to the webhook.
help: Message to send to the webhook.
required: true

- TITLE:
long: title
required: false
takes_value: true
about: >
help: >
Title of the message block (required by discord & generic webhook, automatically supplied, default: "Broadcast")
- webhook_url:
long: webhook
value_name: WEBHOOK_URL
takes_value: true
about: >
help: >
Sets the webhook to send a notification to, (Can be set with ENV variable WEBHOOK_URL)
- mod:install:
about: >
help: >
Installs a mod from a given source by downloading the zip file and then extracting it.
Supported platforms are Nexus (with premium account and API key), GitHub, and any other direct download source.
version: "1.0"
author: mbround18
args:
- URL:
about: Url of the mod to download and install
help: Url of the mod to download and install
required: true
index: 1
- status:
about: >
help: >
Prints out the status of your server with information about current players, mod support, and a few other details.
Note: If your server has PUBLIC set to 0 it will not be able to be queried!
version: "1.0"
author: mbround18
args:
- json:
about: Print out as json
help: Print out as json
required: false
takes_value: false
long: json
short: j
- address:
about: Search for server information based on address
help: Search for server information based on address
required: false
takes_value: true
long: address
2 changes: 1 addition & 1 deletion src/odin/commands/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn invoke(args: &ArgMatches) {
.unwrap_or("Test Notification")
.to_string(),
);
let webhook_url = parse_arg_variable(&args, "WEBHOOK_URL", "");
let webhook_url = parse_arg_variable(args, "WEBHOOK_URL", "");
let notification = NotificationMessage {
author: get_server_name(),
event_type: EventType {
Expand Down
2 changes: 1 addition & 1 deletion src/odin/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn parse_address(args: &ArgMatches) -> Result<SocketAddrV4, AddrParseError> {

pub fn invoke(args: &ArgMatches) {
let output_json = args.is_present("json");
let address = parse_address(&args).unwrap_or_else(|_| {
let address = parse_address(args).unwrap_or_else(|_| {
let addr = fetch_var("ADDRESS", args.value_of("address").unwrap());
error!("Failed to parse supplied address! {}", addr);
exit(1)
Expand Down
31 changes: 17 additions & 14 deletions src/odin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ fn main() {
let yaml = load_yaml!("cli.yaml");
let app = App::from(yaml)
.version(constants::VERSION)
.setting(AppSettings::SubcommandRequired);
.setting(AppSettings::SubcommandRequired)
.setting(AppSettings::ArgRequiredElseHelp);
let matches = app.get_matches();
let debug_mode = matches.is_present("debug") || environment::fetch_var("DEBUG_MODE", "0").eq("1");

Expand All @@ -32,23 +33,25 @@ fn main() {
}

logger::initialize_logger(debug_mode).unwrap();
debug!("Debug mode enabled!");
if let Some((command_name, _)) = matches.subcommand() {
debug!("Launching {} command...", command_name);
};
match matches.subcommand().expect("Subcommand is required") {
("configure", sub_m) => commands::configure::invoke(sub_m),
if debug_mode {
debug!("Debug mode enabled!");
}
let command_name = matches.subcommand();
debug!("Launching {} command...", command_name.0);

match matches.subcommand() {
("configure", sub_m) => commands::configure::invoke(sub_m.unwrap()),
("install", _) => handle_exit_status(
commands::install::invoke(constants::GAME_ID),
"Successfully installed Valheim!".to_string(),
),
("start", sub_m) => commands::start::invoke(sub_m),
("stop", sub_m) => commands::stop::invoke(sub_m),
("backup", sub_m) => commands::backup::invoke(sub_m),
("notify", sub_m) => commands::notify::invoke(sub_m),
("update", sub_m) => commands::update::invoke(sub_m),
("mod:install", sub_m) => commands::install_mod::invoke(sub_m),
("status", sub_m) => commands::status::invoke(sub_m),
("start", sub_m) => commands::start::invoke(sub_m.unwrap()),
("stop", sub_m) => commands::stop::invoke(sub_m.unwrap()),
("backup", sub_m) => commands::backup::invoke(sub_m.unwrap()),
("notify", sub_m) => commands::notify::invoke(sub_m.unwrap()),
("update", sub_m) => commands::update::invoke(sub_m.unwrap()),
("mod:install", sub_m) => commands::install_mod::invoke(sub_m.unwrap()),
("status", sub_m) => commands::status::invoke(sub_m.unwrap()),
_ => {
panic!("No Command Launched!");
} // Either no subcommand or one not tested for...
Expand Down
2 changes: 1 addition & 1 deletion src/odin/mods/bepinex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl BepInExEnvironment {
&self.doorstop_invoke_dll,
];
let expected_state = true;
let output = checks.iter().all(|ref v| path_exists(&v) == expected_state);
let output = checks.iter().all(|v| path_exists(v) == expected_state);
if output {
debug!("Yay! looks like we found all the required files for BepInEx to run! <3")
} else {
Expand Down
22 changes: 11 additions & 11 deletions src/odin/mods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,36 @@ impl ZipExt for ZipArchive<File> {
Err(_) => continue,
};

let mut outpath = dst_dir.as_ref().join(filepath);
let mut out_path = dst_dir.as_ref().join(filepath);

debug!("Extracting file: {:?}", outpath);
debug!("Extracting file: {:?}", out_path);

if file.name().ends_with('/') {
fs::create_dir_all(&outpath)?;
fs::create_dir_all(&out_path)?;
} else {
if let Some(p) = outpath.parent() {
if let Some(p) = out_path.parent() {
if !p.exists() {
fs::create_dir_all(&p)?;
}
}

// Don't overwrite old cfg files
if outpath.extension().unwrap_or_default() == "cfg" && outpath.exists() {
if out_path.extension().unwrap_or_default() == "cfg" && out_path.exists() {
debug!("File is config with already exiting destination! Adding '.new'");
outpath = outpath.with_extension("cfg.new");
out_path = out_path.with_extension("cfg.new");
}

let mut outfile = File::create(&outpath)?;
let mut outfile = File::create(&out_path)?;
io::copy(&mut file, &mut outfile)?;
debug!("Extracted file {:?}", outpath);
debug!("Extracted file {:?}", out_path);
}

// Get and Set permissions
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
if let Some(mode) = file.unix_mode() {
fs::set_permissions(&outpath, fs::Permissions::from_mode(mode))?;
fs::set_permissions(&out_path, fs::Permissions::from_mode(mode))?;
}
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ impl ValheimMod {
self.staging_location
));
}
if let Ok(parsed_url) = Url::parse(&download_url) {
if let Ok(parsed_url) = Url::parse(download_url) {
match reqwest::blocking::get(parsed_url) {
Ok(mut response) => {
if !SUPPORTED_FILE_TYPES.contains(&self.file_type.as_str()) {
Expand All @@ -262,7 +262,7 @@ impl ValheimMod {

let file_name = parse_file_name(
&Url::parse(&self.url).unwrap(),
format!("{}.{}", get_md5_hash(&download_url), &self.file_type).as_str(),
format!("{}.{}", get_md5_hash(download_url), &self.file_type).as_str(),
);
self.staging_location = self.staging_location.join(file_name);
debug!("Downloading to: {:?}", self.staging_location);
Expand Down
2 changes: 1 addition & 1 deletion src/odin/notifications/enums/notification_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl std::str::FromStr for NotificationEvent {
::std::result::Result::Ok(Broadcast)
} else {
let status = parts[1];
let event_status = EventStatus::from_str(&status).unwrap();
let event_status = EventStatus::from_str(status).unwrap();
match event {
"Update" => ::std::result::Result::Ok(Update(event_status)),
"Start" => ::std::result::Result::Ok(Start(event_status)),
Expand Down
Loading

0 comments on commit f9c64a9

Please sign in to comment.