diff --git a/src/installers/linux.rs b/src/installers/linux.rs index 821ee74..bcab180 100644 --- a/src/installers/linux.rs +++ b/src/installers/linux.rs @@ -1,4 +1,5 @@ -use crate::{shell_command}; +use std::fs::{copy, metadata, remove_file, create_dir}; +use crate::shell_command; use regex::Regex; pub fn install_l() { @@ -23,12 +24,20 @@ pub fn install_l() { println!("Unpacking release..."); - shell_command("tar", vec!["-xf", "oxido*.tar.gz"]); + shell_command("tar", vec!["-xf", "oxido-linux.tar.gz"]); println!("Moving to $HOME/.oxido..."); - shell_command("mkdir", vec!["$HOME/.oxido"]); - shell_command("mv", vec!["oxido* $HOME/.oxido"]); - - println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it"); + if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() { + create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap(); + } + copy( + "oxido", + format!("{}/.oxido/oxido", std::env::var("HOME").unwrap()), + ) + .unwrap(); + remove_file("oxido").unwrap(); + remove_file("oxido-linux.tar.gz").unwrap(); + + println!("Oxup installed successfully!\nRun 'echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc' and restart your terminal to use it"); } diff --git a/src/installers/macos.rs b/src/installers/macos.rs index 1091856..801efc5 100644 --- a/src/installers/macos.rs +++ b/src/installers/macos.rs @@ -1,6 +1,6 @@ -use crate::{shell_command}; +use std::fs::{copy, metadata, remove_file, create_dir}; +use crate::shell_command; use regex::Regex; - pub fn install_m() { let mut s = shell_command( "curl", @@ -23,12 +23,20 @@ pub fn install_m() { println!("Unpacking release..."); - shell_command("unzip", vec!["oxido*.darwin.zip"]); + shell_command("unzip", vec!["oxido-darwin.zip"]); println!("Moving to $HOME/.oxido..."); - shell_command("mkdir", vec!["$HOME/.oxido"]); - shell_command("mv", vec!["oxido* $HOME/.oxido"]); - - println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it"); + if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() { + create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap(); + } + copy( + "oxido", + format!("{}/.oxido/oxido", std::env::var("HOME").unwrap()), + ) + .unwrap(); + remove_file("oxido").unwrap(); + remove_file("oxido-darwin.zip").unwrap(); + + println!("Oxup installed successfully!\nRun 'echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc' and restart your terminal to use it"); } diff --git a/src/installers/windows.rs b/src/installers/windows.rs index a4b2a66..8f057f8 100644 --- a/src/installers/windows.rs +++ b/src/installers/windows.rs @@ -20,7 +20,7 @@ pub fn install_w() { shell_command("wget", vec![&s]); - shell_command("unzip", vec!["oxido*.gnu.zip"]); + shell_command("unzip", vec!["oxido-windows.gnu.zip"]); shell_command("mkdir", vec![r"C:\bin"]); diff --git a/src/uninstallers/linux.rs b/src/uninstallers/linux.rs index a3697c5..544359b 100644 --- a/src/uninstallers/linux.rs +++ b/src/uninstallers/linux.rs @@ -1,5 +1,3 @@ -use crate::shell_command; - pub fn uninstall_l() { - shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]); + std::fs::remove_file(format!("{}/.oxido/oxido", std::env::var("HOME").unwrap())).unwrap(); } diff --git a/src/uninstallers/macos.rs b/src/uninstallers/macos.rs index 566b738..0d16b43 100644 --- a/src/uninstallers/macos.rs +++ b/src/uninstallers/macos.rs @@ -1,5 +1,3 @@ -use crate::shell_command; - pub fn uninstall_m() { - shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]); + std::fs::remove_file(format!("{}/.oxido/oxido", std::env::var("HOME").unwrap())).unwrap(); }