Skip to content

Commit

Permalink
release: v1
Browse files Browse the repository at this point in the history
  • Loading branch information
megatank58 committed Oct 2, 2022
1 parent 1178111 commit ebc88bd
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 63 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ jobs:
name: oxup-darwin
steps:
- uses: actions/checkout@master
- run: rustup toolchain install stable --profile minimal

- uses: Swatinem/rust-cache@v2
with:
shared-key: ""
key: ""
env-vars: ""
workspaces: ""
cache-on-failure: ""
- name: Compile and release
uses: rust-build/rust-build.action@v1.3.2
env:
Expand Down
9 changes: 9 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.

tasks:
- init: cargo build
command: cargo watch -x run


9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[package]
name = "oxup"
version = "0.1.0"
version = "1.0.0"
edition = "2021"

[profile.release]
strip = true
opt-level = "z"

[dependencies]
regex = "1"
colored = "2.0.0"
regex = "1"
28 changes: 20 additions & 8 deletions src/installers/linux.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::shell_command;
use crate::{info, shell, success};
use colored::Colorize;
use regex::Regex;
use std::fs::{copy, remove_file};

pub fn install_l() {
let mut s = shell_command(
let mut s = shell!(
"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();
let vre = Regex::new(r"v(?P<version>\d.\d.\d)").unwrap();

s = re
.captures(&s)
Expand All @@ -18,15 +20,23 @@ pub fn install_l() {
.as_str()
.to_string();

println!("downloading release from {}...", &s);
let v = vre
.captures(&s)
.unwrap()
.name("version")
.unwrap()
.as_str()
.to_string();

info![format!("Downloading oxido version {}", &v)];

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

println!("unpacking release...");
info!["Unpacking package"];

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

println!("moving to $HOME/.oxido/bin...");
info!["Moving package"];

copy(
"oxido",
Expand All @@ -36,4 +46,6 @@ pub fn install_l() {

remove_file("oxido").unwrap();
remove_file("oxido-linux.tar.gz").unwrap();

success!["Oxido has been installed!"];
}
29 changes: 21 additions & 8 deletions src/installers/macos.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::shell_command;
use crate::{info, shell, success};
use colored::Colorize;
use regex::Regex;
use std::fs::{copy, remove_file};

pub fn install_m() {
let mut s = shell_command(
let mut s = shell!(
"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>.*darwin.zip)\"").unwrap();
let vre = Regex::new(r"v(?P<version>\d.\d.\d)").unwrap();

s = re
.captures(&s)
Expand All @@ -17,15 +20,23 @@ pub fn install_m() {
.as_str()
.to_string();

println!("downloading release from {}...", &s);
let v = vre
.captures(&s)
.unwrap()
.name("version")
.unwrap()
.as_str()
.to_string();

info![format!("Downloading oxido version {}", &v)];

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

println!("unpacking release...");
info!["Unpacking package"];

shell_command("unzip", vec!["oxido-darwin.zip"]);
shell!("unzip", vec!["oxido-darwin.zip"]);

println!("moving to $HOME/.oxido/bin...");
info!["Moving package"];

copy(
"oxido",
Expand All @@ -34,4 +45,6 @@ pub fn install_m() {
.unwrap();
remove_file("oxido").unwrap();
remove_file("oxido-darwin.zip").unwrap();

success!["Oxido has been installed!"];
}
35 changes: 26 additions & 9 deletions src/installers/windows.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use crate::{info, shell, success};
use colored::Colorize;
use regex::Regex;

use crate::shell_command;

pub fn install_w() {
let mut s = shell_command(
let mut s = shell!(
"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();
let vre = Regex::new(r"v(?P<version>\d.\d.\d)").unwrap();

s = re
.captures(&s)
Expand All @@ -18,13 +19,29 @@ pub fn install_w() {
.as_str()
.to_string();

shell_command("wget", vec![&s]);
let v = vre
.captures(&s)
.unwrap()
.name("version")
.unwrap()
.as_str()
.to_string();

info![format!("Downloading oxido version {}", &v)];

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

info!["Unpacking package"];

shell!("unzip", vec!["oxido-windows.gnu.zip"]);

info!["Moving package"];

shell_command("unzip", vec!["oxido-windows.gnu.zip"]);
shell!("mkdir", vec![r"C:\bin"]);

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

shell_command("move", vec![r"oxido.exe C:\oxido"]);
success!["Oxido has been installed!"];

shell_command("setx", vec!["PATH \"C:\\oxido;%PATH%\""]);
shell!("setx", vec!["PATH \"C:\\oxido;%PATH%\""]);
}
60 changes: 47 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ mod installers;
mod setup;
mod uninstallers;

use setup::{windows::setup_w, linux::setup_l, macos::setup_m};
use uninstallers::{linux::uninstall_l, macos::uninstall_m, windows::uninstall_w};
use std::env::{args, consts::OS};

use colored::Colorize;

use crate::installers::{linux::install_l, macos::install_m, windows::install_w};
use std::{
env::{args, consts::OS},
process::Command,
};
use installers::{linux::install_l, macos::install_m, windows::install_w};
use setup::{linux::setup_l, macos::setup_m, windows::setup_w};
use uninstallers::{linux::uninstall_l, macos::uninstall_m, windows::uninstall_w};

const HELP_MESSAGE: &str = "
Oxup is a tool for managing installations and packages of oxido.
Expand Down Expand Up @@ -38,14 +37,14 @@ fn main() {
let args: Vec<String> = args().collect();

if args.len() == 1 {
println!("oxup: missing overand\n{}", HELP_MESSAGE);
info!["{HELP_MESSAGE}"];
std::process::exit(1)
}

let command = args[1].as_str();

match command {
"help" => println!("{}", HELP_MESSAGE),
"help" => println!("{HELP_MESSAGE}"),
"install" | "update" => {
let mut os = OS;
if args.contains(&String::from("-L")) {
Expand Down Expand Up @@ -94,14 +93,49 @@ fn main() {
_ => setup_l(),
}
}
"version" => println!("{}", VERSION),
"version" => println!("{VERSION}"),
_ => {
println!("oxup: missing overand\n{}", HELP_MESSAGE);
println!("{HELP_MESSAGE}");
std::process::exit(1)
}
}
}

fn shell_command(name: &str, args: Vec<&str>) -> String {
String::from_utf8(Command::new(name).args(args).output().unwrap().stdout).unwrap()
#[macro_use]
mod macros {

#[macro_export]
macro_rules! shell {
($name:expr, $args:expr) => {
String::from_utf8(
std::process::Command::new($name)
.args($args)
.output()
.unwrap()
.stdout,
)
.unwrap()
};
}

#[macro_export]
macro_rules! info {
($message:expr) => {
println!("{} {}", "=>".blue().bold(), $message);
};
}

#[macro_export]
macro_rules! error {
($message:expr) => {
println!("{} {}", "=>".red().bold(), $message);
};
}

#[macro_export]
macro_rules! success {
($message:expr) => {
println!("{} {}", "=>".green().bold(), $message)
};
}
}
10 changes: 5 additions & 5 deletions src/setup/linux.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use colored::Colorize;
use std::fs::{copy, create_dir, metadata, remove_file, write};

use crate::success;

pub fn setup_l() {
if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() {
if metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_err() {
create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap();
create_dir(format!("{}/.oxido/bin", std::env::var("HOME").unwrap())).unwrap();
}
Expand Down Expand Up @@ -36,8 +39,5 @@ esac
remove_file("oxup-linux.tar.gz").unwrap();
}

println!(
"created {}",
format!("{}/.oxido", std::env::var("HOME").unwrap())
)
success![format!("Created {}/.oxido", std::env::var("HOME").unwrap())]
}
11 changes: 5 additions & 6 deletions src/setup/macos.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::fs::{create_dir, metadata, write, remove_file, copy};
use crate::success;
use colored::Colorize;
use std::fs::{copy, create_dir, metadata, remove_file, write};

pub fn setup_m() {
if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() {
if metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_err() {
create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap();
create_dir(format!("{}/.oxido/bin", std::env::var("HOME").unwrap())).unwrap();
}
Expand Down Expand Up @@ -36,8 +38,5 @@ esac
remove_file("oxup-darwin.zip").unwrap();
}

println!(
"created {}",
format!("{}/.oxido", std::env::var("HOME").unwrap())
)
success![format!("Created {}/.oxido", std::env::var("HOME").unwrap())]
}
14 changes: 6 additions & 8 deletions src/setup/windows.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::fs::{create_dir, metadata, remove_file, copy};
use crate::info;
use colored::Colorize;
use std::fs::{copy, create_dir, metadata, remove_file};

pub fn setup_w() {
if !metadata("C:\\bin\\oxido").is_ok() {
if metadata("C:\\bin\\oxido").is_err() {
create_dir("C:\\bin\\oxido").unwrap();
println!("created directory C:\\bin\\oxido");
info!["Created directory C:\\bin\\oxido"];
}

copy(
"oxup.exe",
"C:\\bin\\oxido\\oxup.exe",
)
.unwrap();
copy("oxup.exe", "C:\\bin\\oxido\\oxup.exe").unwrap();
remove_file("oxup.exe").unwrap();
remove_file("oxup-windows.zip").unwrap();
}
11 changes: 10 additions & 1 deletion src/uninstallers/linux.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
use crate::success;
use colored::Colorize;

pub fn uninstall_l() {
std::fs::remove_file(format!("{}/.oxido/bin/oxido", std::env::var("HOME").unwrap())).unwrap();
std::fs::remove_file(format!(
"{}/.oxido/bin/oxido",
std::env::var("HOME").unwrap()
))
.unwrap();

success!["Oxido has been uninstalled"];
}
11 changes: 10 additions & 1 deletion src/uninstallers/macos.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
use crate::success;
use colored::Colorize;

pub fn uninstall_m() {
std::fs::remove_file(format!("{}/.oxido/bin/oxido", std::env::var("HOME").unwrap())).unwrap();
std::fs::remove_file(format!(
"{}/.oxido/bin/oxido",
std::env::var("HOME").unwrap()
))
.unwrap();

success!["Oxido has been uninstalled"];
}
Loading

0 comments on commit ebc88bd

Please sign in to comment.