From 5ab28ff7763733b72c2b5687d836581e2468eed7 Mon Sep 17 00:00:00 2001 From: Megatank58 Date: Thu, 6 Oct 2022 09:31:32 +0000 Subject: [PATCH] feat: install script --- README.md | 39 ++--------------------------------- install.sh | 25 ++++++++++++++++++++++ src/init.rs | 8 ++++---- src/install.rs | 56 ++++++++++---------------------------------------- src/setup.rs | 6 +----- 5 files changed, 43 insertions(+), 91 deletions(-) create mode 100755 install.sh diff --git a/README.md b/README.md index fe0d8e2..6d066d7 100644 --- a/README.md +++ b/README.md @@ -4,46 +4,11 @@ Oxup is a tool for managing installations and packages of oxido. ## Installation -### Windows - -```sh -wget https://github.com/oxidite/oxup/releases/latest/download/oxup-windows.zip -unzip oxup-windows.zip -oxup.exe setup -setx PATH "C:\oxido;%PATH%" -``` - -### Linux - -```bash -wget https://github.com/oxidite/oxup/releases/latest/download/oxup-linux.tar.gz && tar -xf oxup-linux.tar.gz && ./oxup setup && rm -rf oxup-linux.tar.gz -``` -#### Bash -```bash -echo '. "$HOME/.oxido/env"' >> $HOME/.bashrc -``` - -#### Zsh -```zsh -echo '. "$HOME/.oxido/env"' >> $HOME/.zshrc -``` - -### Macos - ```bash -wget https://github.com/oxidite/oxup/releases/latest/download/oxup-darwin.zip && unzip oxup-darwin.zip && ./oxup setup && rm -rf oxup-darwin.zip -``` -#### Bash -```bash -echo '. "$HOME/.oxido/env"' >> $HOME/.bashrc -``` - -#### Zsh -```zsh -echo '. "$HOME/.oxido/env"' >> $HOME/.zshrc +curl sh.megatank58.tech/oxup | sh ``` -Then you can restart your shell and use oxido. +Then you can restart your shell and install oxido. ## Usage diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..076bec7 --- /dev/null +++ b/install.sh @@ -0,0 +1,25 @@ +BLUE='\033[0;34m' +NONE='\033[0m' +PREFIX="${BLUE}=>${NONE} " +echo -e "${PREFIX}Downloading oxup" + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + wget -q https://github.com/oxidic/oxup/releases/latest/download/oxup + chmod +x oxup + ./oxup setup +elif [[ "$OSTYPE" == "darwin"* ]]; then + wget -q https://github.com/oxidic/oxup/releases/latest/download/oxup-darwin + chmod +x oxup-darwin + ./oxup-darwin setup +else + wget -q https://github.com/oxidic/oxup/releases/latest/download/oxup.exe + ./oxup.exe setup +fi + +if [[ $SHELL == *bash ]]; then + echo '. "$HOME/.oxido/env"' >> $HOME/.bashrc +elif [[ $SHELL == *zsh ]]; then + echo '. "$HOME/.oxido/env"' >> $HOME/.zshrc +else + echo -e "${PREFIX}Add the following lines to your shell configuration to add oxup to PATH: \`. \"$HOME/.oxido/env\"\`" +fi \ No newline at end of file diff --git a/src/init.rs b/src/init.rs index 77b8f08..7aa3c8d 100644 --- a/src/init.rs +++ b/src/init.rs @@ -3,16 +3,16 @@ use std::fs::{create_dir_all, write}; use crate::success; pub fn init(name: String) { - let default_function = -"fn main() { + let default_function = "fn main() { print(\"Hello world!\"); } "; let metadata = format!( -"[package] + "[package] name = {name} version = 0.1.0 -"); +" + ); create_dir_all(format!("{name}/src")).unwrap(); write(format!("{name}/src/main.ox"), default_function).unwrap(); diff --git a/src/install.rs b/src/install.rs index 34b7ff0..36c365c 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,6 +1,4 @@ use crate::{info, success}; -use flate2::bufread::GzDecoder; - use reqwest::{ header::{HeaderMap, USER_AGENT}, Client, @@ -29,9 +27,9 @@ pub async fn install(os: OS) -> Result<(), Box> { let result: ReleaseData = response.json().await?; let filter = match os { - OS::Mac => "oxido-darwin.zip", - OS::Linux => "oxido-linux.tar.gz", - OS::Windows => "oxido-windows.zip", + OS::Mac => "oxido-darwin", + OS::Linux => "oxido", + OS::Windows => "oxido.exe", }; let url: String = result @@ -45,50 +43,18 @@ pub async fn install(os: OS) -> Result<(), Box> { let response = client.get(&url).headers(headers.clone()).send().await?; let bytes = response.bytes().await?; - let reader = std::io::Cursor::new(bytes); info!["Moving package"]; - match os { - OS::Linux => { - #[cfg(target_os = "linux")] - { - let tarfile = GzDecoder::new(reader); - let mut archive = tar::Archive::new(tarfile); - archive.unpack(format!( - "{}/.oxido/bin", - std::env::var("HOME").unwrap() - ))?; - } - } - OS::Mac | OS::Windows => { - #[cfg(target_os = "macos")] - #[cfg(target_os = "windows")] - { - let mut zip = zip::ZipArchive::new(reader).unwrap(); - - let name = if os == OS::Windows { - String::from(r"oxido.exe") - } else { - String::from("oxido") - }; - - let dir = if os == OS::Mac { - format!("{}/.oxido/bin", std::env::var("HOME").unwrap()) - } else { - String::from(r"C:\bin") - }; - - let mut file_zip = zip.by_name(&name).unwrap(); - let mut file_buf: Vec = Vec::new(); - file_zip.read_to_end(&mut file_buf)?; - - std::fs::create_dir_all(&dir)?; - let path = std::path::Path::new(&dir).join(name); - std::fs::write(path, file_buf)?; + std::fs::write( + match os { + OS::Windows => String::from(r"C:\bin"), + _ => { + format!("{}/.oxido/bin", std::env::var("HOME").unwrap()) } - } - } + }, + bytes, + )?; success!["Oxido has been installed!"]; diff --git a/src/setup.rs b/src/setup.rs index ed28e0e..c501a50 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -12,7 +12,6 @@ pub fn setup(os: OS) { copy("oxup.exe", "C:\\bin\\oxido\\oxup.exe").unwrap(); remove_file("oxup.exe").unwrap(); - remove_file("oxup-windows.zip").unwrap(); } OS::Mac | OS::Linux => { if metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_err() { @@ -45,11 +44,8 @@ pub fn setup(os: OS) { .unwrap(); remove_file("oxup").unwrap(); } - if metadata("./oxup-darwin.zip").is_ok() { - remove_file("oxup-darwin.zip").unwrap(); - } - success![format!("Created {}/.oxido", std::env::var("HOME").unwrap())] + success![format!("Created {}/.oxido", std::env::var("HOME").unwrap())]; } } }