Skip to content

Commit

Permalink
Add ldd --version check for Linux (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
TH3-S4LM0N authored Oct 18, 2022
1 parent c1df0ef commit c4ce52b
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod platform_specific;
#[cfg(target_os = "windows")]
use platform_specific::windows;

use platform_specific::linux;

use serde::{Deserialize, Serialize};
use sysinfo::SystemExt;
use zip::ZipArchive;
Expand Down Expand Up @@ -40,6 +42,21 @@ pub fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, an
Ok(mod_version_number.to_string())
}

// I intend to add more linux related stuff to check here, so making a func
// for now tho it only checks `ldd --version`
// - salmon

pub fn linux_checks_librs() -> bool {
let mut linux_compatible: bool = true; // a variable that starts true and will be set to false if any of the checks arent met

// check `ldd --version` to see if glibc is up to date for northstar proton
let lddv = linux::check_glibc_v();
if lddv < 2.33 { linux_compatible = false };

return linux_compatible;
}


/// Attempts to find the game install location
pub fn find_game_install_location() -> Result<GameInstall, anyhow::Error> {
// Attempt parsing Steam library directly
Expand Down
15 changes: 13 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use app::{
check_is_flightcore_outdated, check_is_valid_game_path, check_northstar_running,
check_origin_running, convert_release_candidate_number, find_game_install_location,
get_enabled_mods, get_host_os, get_log_list, get_northstar_version_number, install_northstar,
launch_northstar, set_mod_enabled_status, GameInstall,
launch_northstar, set_mod_enabled_status, GameInstall, linux_checks_librs
};

mod repair_and_verify;
Expand Down Expand Up @@ -87,7 +87,8 @@ fn main() {
get_enabled_mods_caller,
set_mod_enabled_status_caller,
disable_all_but_core_caller,
is_debug_mode
is_debug_mode,
linux_checks
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down Expand Up @@ -117,6 +118,16 @@ fn is_debug_mode() -> bool {
return cfg!(debug_assertions);
}

#[tauri::command]
/// Returns true if linux compatible
fn linux_checks() -> bool {
if get_host_os() == "windows" {
false
} else {
linux_checks_librs()
}
}

#[tauri::command]
/// Returns the current version number as a string
fn get_version_number() -> String {
Expand Down
63 changes: 63 additions & 0 deletions src-tauri/src/platform_specific/linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Linux specific code

use std::process::Command;
use regex::Regex;

pub fn check_glibc_v() -> f32 {
let out = Command::new("/bin/ldd")
.arg("--version")
.output()
.expect("failed to run 'ldd --version'");

// parse the output down to just the first line
let lddva = String::from_utf8_lossy(&out.stdout);
let lddvl: Vec<&str> = lddva.split('\n').collect();
let lddvlo = &lddvl[0];
let reg = Regex::new(r"(2.\d{2}$)").unwrap();
for caps in reg.captures_iter(lddvlo) {
return caps.get(1).unwrap().as_str().parse::<f32>().unwrap(); // theres prolly a better way ijdk how tho
}
return 0.0; // this shouldnt ever be reached but it has to be here
}

/*
Outputs of ldd --verssion from distros, all we care about is the first line so trimmed, also removed all duplicates
Thanks tony
Distros not included: AmazonLinux, Gentoo, Kali, Debian before 11, Oracle Linux, Scientific Linux, Slackware, Mageia, Neurodebian, RHEL 8 and 9 (Same as AlmaLinux), RockyLinux (Same as AlmaLinux), Ubuntu before 20.04
AlmaLinux 8
ldd (GNU libc) 2.35
Centos Stream 8
ldd (GNU libc) 2.28
Centos Stream 9
ldd (GNU libc) 2.34
Centos 7
ldd (GNU libc) 2.17
Debian 11
ldd (Debian GLIBC 2.31-13+deb11u4) 2.31
Debian Testing
ldd (Debian GLIBC 2.35-1) 2.35
Debian Unstable
ldd (Debian GLIBC 2.35-3) 2.35
Fedora 37
ldd (GNU libc) 2.36
Opensuse Leap
ldd (GNU libc) 2.31
Ubuntu 20.04
ldd (Ubuntu GLIBC 2.31-0ubuntu9.9) 2.31
Ubuntu 22.04
ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35
Ubuntu 22.10
ldd (Ubuntu GLIBC 2.36-0ubuntu2) 2.36
*/
3 changes: 3 additions & 0 deletions src-tauri/src/platform_specific/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#[cfg(target_os = "windows")]
pub mod windows;

pub mod linux;

22 changes: 22 additions & 0 deletions src-vue/src/views/DeveloperView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
Panic button
</el-button>

<el-button type="primary" @click="checkLinuxCompatibility">
Check NSProton Compatibility
</el-button>

<el-button type="primary" @click="toggleReleaseCandidate">
Toggle Release Candidate
</el-button>
Expand Down Expand Up @@ -43,6 +47,24 @@ export default defineComponent({
position: 'bottom-right'
});
},
async checkLinuxCompatibility() {
let LinuxCompatible = await invoke("linux_checks");
if (!LinuxCompatible) {
ElNotification({
title: 'Not linux compatible',
message: 'GLIBC is not version 2.33 or greater',
type: 'error',
position: 'bottom-right'
});
} else {
ElNotification({
title: 'Linux compatible',
message: 'No error reported',
type: 'success',
position: 'bottom-right'
});
}
},
async toggleReleaseCandidate() {
// Flip between RELEASE and RELEASE_CANDIDATE
this.$store.state.release_canal = this.$store.state.release_canal === ReleaseCanal.RELEASE
Expand Down

0 comments on commit c4ce52b

Please sign in to comment.