Skip to content

Commit

Permalink
feat: install script
Browse files Browse the repository at this point in the history
  • Loading branch information
megatank58 committed Oct 6, 2022
1 parent 895dac7 commit 5ab28ff
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 91 deletions.
39 changes: 2 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
56 changes: 11 additions & 45 deletions src/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{info, success};
use flate2::bufread::GzDecoder;

use reqwest::{
header::{HeaderMap, USER_AGENT},
Client,
Expand Down Expand Up @@ -29,9 +27,9 @@ pub async fn install(os: OS) -> Result<(), Box<dyn std::error::Error>> {
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
Expand All @@ -45,50 +43,18 @@ pub async fn install(os: OS) -> Result<(), Box<dyn std::error::Error>> {

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<u8> = 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!"];

Expand Down
6 changes: 1 addition & 5 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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())];
}
}
}

0 comments on commit 5ab28ff

Please sign in to comment.