Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #337 #808

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 263 additions & 100 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Dockerfile.odin
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN cargo chef prepare --recipe-path recipe.json
# ------------------ #
FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} as cacher
WORKDIR /data/odin
RUN apt-get update && apt-get install -y cmake
COPY --from=planner /data/odin/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json

Expand All @@ -24,6 +25,7 @@ RUN cargo chef cook --release --recipe-path recipe.json
FROM rust:${RUST_VERSION} as builder
WORKDIR /data/odin
COPY . .
RUN apt-get update && apt-get install -y cmake
# Copy over the cached dependencies
COPY --from=cacher /data/odin/target target
COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<a href="https://github.com/mbround18/valheim-docker/actions/workflows/docker-release.yml"><img src="https://img.shields.io/github/actions/workflow/status/mbround18/valheim-docker/docker-release.yml?label=Docker&style=for-the-badge" alt=""></a>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

## Table of Contents
Expand Down
4 changes: 4 additions & 0 deletions src/huginn/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod routes;

use log::info;
use odin::utils::is_root::is_root;
use odin::{logger::initialize_logger, server::ServerInfo, utils::environment::fetch_var};
use std::net::SocketAddrV4;
use std::str::FromStr;
Expand All @@ -14,6 +15,9 @@ fn fetch_info() -> ServerInfo {

#[tokio::main]
async fn main() {
if is_root() {
panic!("You must run this executable without root permissions");
}
// Logger
let debug_mode = fetch_var("DEBUG_MODE", "0").eq("1");
initialize_logger(debug_mode).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions src/odin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ tar = "0.4"
flate2 = "1.0"
inflections = "1.1.1"
md5 = "0.7"
reqwest = { version = "0.11", default_features = false, features = ["blocking", "json", "rustls-tls"] }
reqwest = { version = "0.12.4", default_features = false, features = ["blocking", "json", "rustls-tls"] }
chrono = "0.4"
zip = { version = "0.6" }
zip = { version = "1.1.0" }
fs_extra = "1.3"
glob = "0.3"
a2s = "0.5"
serde_with = "3"
regex = "1"
users = "0.11.0"


[dev-dependencies]
once_cell = "1"
Expand Down
5 changes: 5 additions & 0 deletions src/odin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::commands::configure::Modifiers;
use crate::executable::handle_exit_status;
use crate::logger::debug_mode;
use crate::messages::about;
use crate::utils::is_root::is_root;

mod cli;
pub mod commands;
Expand All @@ -25,6 +26,10 @@ pub mod traits;
pub mod utils;

fn main() {
if is_root() {
panic!("You must run this executable without root permissions");
}

dotenv().ok();

use cli::{Cli, Commands};
Expand Down
7 changes: 4 additions & 3 deletions src/odin/mods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ impl ZipExt for ZipArchive<File> {
fn extract_sub_dir_custom<P: AsRef<Path>>(&mut self, dst_dir: P, sub_dir: &str) -> ZipResult<()> {
for i in 0..self.len() {
let mut file = self.by_index(i)?;
let filepath = match file
let enclosed = match file
.enclosed_name()
.ok_or(ZipError::InvalidArchive("Invalid file path"))?
.strip_prefix(sub_dir)
.ok_or(ZipError::InvalidArchive("Invalid file path"))
{
Ok(path) => path,
Err(_) => continue,
};

let filepath = enclosed.strip_prefix(sub_dir).unwrap();

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

debug!("Extracting file: {:?}", out_path);
Expand Down
9 changes: 9 additions & 0 deletions src/odin/utils/is_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use users::{get_current_uid, get_user_by_uid};

pub fn is_root() -> bool {
let current_uid = get_current_uid();
match get_user_by_uid(current_uid) {
Some(user) => user.uid() == 0,
None => panic!("Failed to get user information."),
}
}
1 change: 1 addition & 0 deletions src/odin/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod common_paths;
pub mod environment;
pub mod fetch_public_ip_address;
pub mod is_root;
pub mod parse_truthy;

pub use fetch_public_ip_address::fetch_public_address;
Expand Down
Loading