Skip to content

Commit

Permalink
fix: path
Browse files Browse the repository at this point in the history
  • Loading branch information
megatank58 committed Jun 22, 2022
1 parent 01ca8e8 commit 8923830
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
oxido
oxido*
target
Cargo.lock
bin
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ wget https://github.com/oxidite/oxup/releases/latest/download/oxup-linux.tar.gz
tar -xf oxup-linux.tar.gz
mkdir $HOME/.oxido
mv oxup $HOME/.oxido
export PATH=$PATH:$HOME/.oxido
echo "export PATH=$PATH:$HOME/.oxido" >> $HOME/.bashrc
export PATH="$HOME/.oxido:$PATH"
echo "export PATH="$HOME/.oxido:$PATH"" >> $HOME/.bashrc
```

### Macos
Expand All @@ -33,8 +33,8 @@ wget https://github.com/oxidite/oxup/releases/latest/download/oxup-darwin.zip
unzip oxup-darwin.zip
mkdir $HOME/.oxido
mv oxup $HOME/.oxido
export PATH=$PATH:$HOME/.oxido
echo "export PATH=$PATH:$HOME/.oxido" >> $HOME/.bashrc
export PATH="$HOME/.oxido:$PATH"
echo "export PATH="$HOME/.oxido:$PATH"" >> $HOME/.bashrc
```

## Usage
Expand Down
33 changes: 18 additions & 15 deletions src/installers/linux.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
use crate::{shell_command};
use regex::Regex;
use crate::{shell_command, current_shell};

pub fn install_l() {

let mut s = shell_command(
"curl",
vec![
"https://api.github.com/repositories/500013933/releases/latest",
],
vec!["https://api.github.com/repositories/500013933/releases/latest"],
);

let re = Regex::new("\"browser_download_url\":.\"(?P<url>.*tar.gz)\"").unwrap();

s = re.captures(&s).unwrap().name("url").unwrap().as_str().to_string();
s = re
.captures(&s)
.unwrap()
.name("url")
.unwrap()
.as_str()
.to_string();

println!("Downloading release from {}...", &s);

shell_command("wget", vec![&s]);

println!("Unpacking release...");

shell_command("tar", vec!["-xf", "oxido*.tar.gz"]);

println!("Moving to $HOME/.oxido...");

shell_command("mkdir", vec!["$HOME/.oxido"]);
shell_command("mv", vec!["oxido* $HOME/.oxido"]);
shell_command("export", vec!["PATH:$HOME/.oxido"]);

if current_shell() == "bash" {
shell_command("echo", vec!["\"export PATH:$HOME/.oxido\" >> $HOME/.bashrc"]);
} else if current_shell() == "zsh" {
shell_command("echo", vec!["\"export PATH:$HOME/.oxido\" >> $HOME/.zshrc"]);
}

}

println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it");
}
15 changes: 8 additions & 7 deletions src/installers/macos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{shell_command, current_shell};
use crate::{shell_command};
use regex::Regex;

pub fn install_m() {
Expand All @@ -17,17 +17,18 @@ pub fn install_m() {
.as_str()
.to_string();

println!("Downloading release from {}...", &s);

shell_command("wget", vec![&s]);

println!("Unpacking release...");

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"]);
shell_command("export", vec!["PATH:$HOME/.oxido"]);

if current_shell() == "bash" {
shell_command("echo", vec!["\"export PATH:$HOME/.oxido\" >> $HOME/.bashrc"]);
} else if current_shell() == "zsh" {
shell_command("echo", vec!["\"export PATH:$HOME/.oxido\" >> $HOME/.zshrc"]);
}
println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it");
}
4 changes: 2 additions & 2 deletions src/installers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod linux;
pub mod macos;
pub mod windows;
pub mod macos;
pub mod windows;
16 changes: 10 additions & 6 deletions src/installers/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ use crate::shell_command;
pub fn install_w() {
let mut s = shell_command(
"curl",
vec![
"https://api.github.com/repositories/500013933/releases/latest",
],
vec!["https://api.github.com/repositories/500013933/releases/latest"],
);

let re = Regex::new("\"browser_download_url\":.\"(?P<url>.*gnu.zip)\"").unwrap();

s = re.captures(&s).unwrap().name("url").unwrap().as_str().to_string();
s = re
.captures(&s)
.unwrap()
.name("url")
.unwrap()
.as_str()
.to_string();

shell_command("wget", vec![&s]);

Expand All @@ -21,6 +25,6 @@ pub fn install_w() {
shell_command("mkdir", vec![r"C:\bin"]);

shell_command("move", vec![r"oxido.exe C:\oxido"]);

shell_command("setx", vec!["PATH \"C:\\oxido;%PATH%\""]);
}
}
13 changes: 3 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod installers;
mod uninstallers;

use uninstallers::{windows::uninstall_w, linux::uninstall_l, macos::uninstall_m};
use uninstallers::{linux::uninstall_l, macos::uninstall_m, windows::uninstall_w};

use crate::installers::{linux::install_l, macos::install_m, windows::install_w};
use std::{
Expand Down Expand Up @@ -34,7 +34,6 @@ const VERSION: &str = "v1.0.0";
fn main() {
let args: Vec<String> = args().collect();


if args.len() == 1 {
println!("oxup: missing overand\n{}", HELP_MESSAGE);
std::process::exit(1)
Expand All @@ -59,8 +58,7 @@ fn main() {
"macos" => install_m(),
_ => install_l(),
}
println!("OK");
},
}
"uninstall" => {
let mut os = OS;
if args.contains(&String::from("-L")) {
Expand All @@ -76,8 +74,7 @@ fn main() {
"macos" => uninstall_m(),
_ => uninstall_l(),
}
println!("OK")
},
}
"version" => println!("{}", VERSION),
_ => {
println!("oxup: missing overand\n{}", HELP_MESSAGE);
Expand All @@ -89,7 +86,3 @@ fn main() {
fn shell_command(name: &str, args: Vec<&str>) -> String {
String::from_utf8(Command::new(name).args(args).output().unwrap().stdout).unwrap()
}

fn current_shell() -> String {
shell_command("echo", vec!["$SHELL"]).split("/").last().unwrap().to_string()
}
2 changes: 1 addition & 1 deletion src/uninstallers/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use crate::shell_command;

pub fn uninstall_l() {
shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]);
}
}
2 changes: 1 addition & 1 deletion src/uninstallers/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use crate::shell_command;

pub fn uninstall_m() {
shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]);
}
}
4 changes: 2 additions & 2 deletions src/uninstallers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod linux;
pub mod macos;
pub mod windows;
pub mod macos;
pub mod windows;
2 changes: 1 addition & 1 deletion src/uninstallers/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use crate::shell_command;

pub fn uninstall_w() {
shell_command("rm", vec![r"C:\bin\oxido"]);
}
}

0 comments on commit 8923830

Please sign in to comment.