generated from jucasoliveira/terminalGPT
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from warpy-ai/15-create-an-installation-script
15 create an installation script
- Loading branch information
Showing
8 changed files
with
223 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ name = "tgs" | |
version = "0.1.0" | ||
authors = ["Lucas Oliveira <[email protected]>"] | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
@@ -37,3 +38,4 @@ regex = "1.5.5" | |
term = "0.7.0" | ||
duct = "0.13.6" | ||
tokio = { version = "1", features = ["full"] } | ||
fs_extra = "1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// build.rs | ||
use std::env; | ||
use std::fs; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
println!("cargo:warning=CWD is {:?}", env::current_dir().unwrap()); | ||
println!( | ||
"cargo:warning=CARGO_MANIFEST_DIR is {:?}", | ||
env::var("CARGO_MANIFEST_DIR").unwrap() | ||
); | ||
|
||
let output_path = get_output_path(); | ||
|
||
println!("cargo:warning=Calculated build path: {:?}", output_path); | ||
|
||
let input_path = | ||
Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("crates/tgs_t5_finetunned/"); | ||
|
||
if let Ok(context) = env::var("CUSTOM_BUILD_CONTEXT") { | ||
if context == "run" { | ||
// Special handling for `cargo run` | ||
println!("Handling for cargo run"); | ||
} | ||
} | ||
|
||
// Define the destination paths | ||
let model_dest = input_path.join("model"); | ||
|
||
let joinable_path = output_path.unwrap(); | ||
let out_model_dest = joinable_path.join("model"); | ||
let script_dest = input_path.join("inference_model.py"); | ||
println!("Attempting to copy from: {}", script_dest.display()); | ||
let out_dest = joinable_path.join("inference_model.py"); | ||
|
||
// Copy model directory and inference_model.py to the target directory | ||
fs::copy(script_dest, out_dest).expect("Failed to copy inference_model.py"); | ||
|
||
// Note: For directory copying, consider using a crate like `fs_extra` | ||
copy_dir_all(model_dest, out_model_dest).expect("Failed to copy model directory"); | ||
} | ||
|
||
fn get_output_path() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> { | ||
//<root or manifest path>/target/<profile>/ | ||
let manifest_dir_string = std::path::PathBuf::from(std::env::var("OUT_DIR")?); | ||
let build_type = env::var("PROFILE").unwrap(); | ||
|
||
let mut target_dir = None; | ||
let mut sub_path = manifest_dir_string.as_path(); | ||
|
||
while let Some(parent) = sub_path.parent() { | ||
if parent.ends_with(&build_type) { | ||
target_dir = Some(parent); | ||
break; | ||
} | ||
sub_path = parent; | ||
} | ||
let target_dir = target_dir.ok_or("not found")?; | ||
Ok(target_dir.to_path_buf()) | ||
} | ||
|
||
fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> { | ||
fs::create_dir_all(&dst)?; | ||
for entry in fs::read_dir(src)? { | ||
let entry = entry?; | ||
let ty = entry.file_type()?; | ||
if ty.is_dir() { | ||
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; | ||
} else { | ||
fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# Ensure the script fails on error | ||
set -euo pipefail | ||
|
||
# Define the GitHub repository | ||
REPO="warpy-ai/tgs" | ||
|
||
# Check if a version argument was provided | ||
if [ "$#" -eq 1 ]; then | ||
VERSION="$1" | ||
echo "User specified version: $VERSION" | ||
else | ||
# Fetch the latest release tag from the GitHub API | ||
VERSION=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | ||
echo "No version specified, using latest: $VERSION" | ||
fi | ||
|
||
# Define variables | ||
INSTALL_DIR="/usr/local/bin" | ||
TMP_DIR=$(mktemp -d) | ||
|
||
# Function to identify the OS and architecture, then construct the download URL | ||
set_download_url() { | ||
OS=$(uname -s) | ||
ARCH=$(uname -m) | ||
BASE_URL="https://github.com/$REPO/releases/download/$VERSION" | ||
|
||
case "$OS" in | ||
"Darwin") | ||
case "$ARCH" in | ||
"arm64") | ||
# Apple Silicon | ||
FILE_NAME="tgs-${VERSION}-aarch64-apple-darwin.tar.gz" | ||
;; | ||
"x86_64") | ||
# Intel Mac | ||
FILE_NAME="tgs-${VERSION}-x86_64-apple-darwin.tar.gz" | ||
;; | ||
*) | ||
echo "Unsupported architecture: $ARCH" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
"Linux") | ||
# Assuming x86_64 for Linux, adjust if supporting other architectures | ||
FILE_NAME="tgs-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" | ||
;; | ||
*) | ||
echo "Unsupported operating system: $OS" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
BIN_URL="${BASE_URL}/${FILE_NAME}" | ||
} | ||
|
||
# Download and install | ||
download_and_install() { | ||
echo "Downloading $BIN_URL" | ||
curl -L $BIN_URL -o "$TMP_DIR/build.tar.gz" | ||
|
||
echo "Extracting..." | ||
tar -xzvf "$TMP_DIR/build.tar.gz" -C "$TMP_DIR" | ||
|
||
echo "Installing..." | ||
# Assuming the binary name is 'tgs', adjust if necessary | ||
mv "$TMP_DIR/tgs" "$INSTALL_DIR" | ||
|
||
echo "Cleanup..." | ||
rm -rf "$TMP_DIR" | ||
|
||
echo "Installation completed successfully." | ||
} | ||
|
||
# Main | ||
set_download_url | ||
download_and_install |