Skip to content

Commit

Permalink
Installation script added, switch to single thread tokio and updatede…
Browse files Browse the repository at this point in the history
…d deps
neculai-stanciu committed Feb 13, 2021
1 parent 2bbdd0a commit 935b608
Showing 10 changed files with 197 additions and 105 deletions.
171 changes: 171 additions & 0 deletions .ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/bin/bash

INSTALL_DIR="$HOME/.jvc"
RELEASE="latest"
OS="$(uname -s)"

# Parse Flags
parse_args() {
while [[ $# -gt 0 ]]; do
key="$1"

case $key in
-d | --install-dir)
INSTALL_DIR="$2"
shift # past argument
shift # past value
;;
-s | --skip-shell)
SKIP_SHELL="true"
shift # past argument
;;
-r | --release)
RELEASE="$2"
shift # past release argument
shift # past release value
;;
*)
echo "Unrecognized argument $key"
exit 1
;;
esac
done
}

set_filename() {
if [ "$OS" == "Linux" ]; then
FILENAME="jvc-linux-amd64"
elif [ "$OS" == "Darwin" ]; then
FILENAME="jvc-macos-amd64"
echo "Downloading the latest jvc binary from GitHub..."
else
echo "OS $OS is not supported."
exit 1
fi
}

download_jvc() {
if [ "$RELEASE" == "latest" ]; then
URL="https://github.com/neculai-stanciu/jvc/releases/latest/download/$FILENAME"
else
URL="https://github.com/neculai-stanciu/jvc/releases/download/$RELEASE/$FILENAME"
fi

DOWNLOAD_DIR=$(mktemp -d)

echo "Downloading $URL..."

mkdir -p "$INSTALL_DIR" &>/dev/null

if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME"; then
echo "Download failed. Check that the release/filename are correct."
exit 1
fi

if [ -f "$DOWNLOAD_DIR/$FILENAME" ]; then
mv "$DOWNLOAD_DIR/$FILENAME" "$INSTALL_DIR/jvc"
else
echo "Cannot find $FILENAME in path $DOWNLOAD_DIR"
exit 2
fi

chmod u+x "$INSTALL_DIR/jvc"
}

check_dependencies() {
echo "Checking dependencies for the installation script..."

echo -n "Checking availability of curl... "
if hash curl 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi

echo -n "Checking availability of unzip... "
if hash unzip 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi

if [ "$USE_HOMEBREW" = "true" ]; then
echo -n "Checking availability of Homebrew (brew)... "
if hash brew 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
fi

if [ "$SHOULD_EXIT" = "true" ]; then
exit 1
fi
}

ensure_containing_dir_exists() {
local CONTAINING_DIR
CONTAINING_DIR="$(dirname "$1")"
if [ ! -d "$CONTAINING_DIR" ]; then
echo " >> Creating directory $CONTAINING_DIR"
mkdir -p "$CONTAINING_DIR"
fi
}

setup_shell() {
CURRENT_SHELL="$(basename "$SHELL")"

if [ "$CURRENT_SHELL" == "zsh" ]; then
CONF_FILE=${ZDOTDIR:-$HOME}/.zshrc
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Zsh. Appending the following to $CONF_FILE:"
echo ""
echo ' # jvc'
echo ' export PATH='"$INSTALL_DIR"':$PATH'
echo ' eval "`jvc env`"'

echo '' >>$CONF_FILE
echo '# jvc' >>$CONF_FILE
echo 'export PATH='$INSTALL_DIR':$PATH' >>$CONF_FILE
echo 'eval "`jvc env`"' >>$CONF_FILE

elif [ "$CURRENT_SHELL" == "bash" ]; then
if [ "$OS" == "Darwin" ]; then
CONF_FILE=$HOME/.profile
else
CONF_FILE=$HOME/.bashrc
fi
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Bash. Appending the following to $CONF_FILE:"
echo ""
echo ' # jvc'
echo ' export PATH='"$INSTALL_DIR"':$PATH'
echo ' eval "`jvc env`"'

echo '' >>$CONF_FILE
echo '# jvc' >>$CONF_FILE
echo 'export PATH='"$INSTALL_DIR"':$PATH' >>$CONF_FILE
echo 'eval "`jvc env`"' >>$CONF_FILE

else
echo "Could not infer shell type. Please set up manually."
echo "Current shell is $CURRENT_SHELL"
exit 1
fi

echo ""
echo "In order to apply the changes, open a new terminal or run the following command:"
echo ""
echo " source $CONF_FILE"
}

parse_args "$@"
set_filename
check_dependencies
download_jvc
if [ "$SKIP_SHELL" != "true" ]; then
setup_shell
fi
2 changes: 1 addition & 1 deletion .github/workflows/create_new_tag.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bump version, create new tag and release point
name: create-tag

on:
push:
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Build and upload binaries to release jvc"
name: release-jvc

on:
repository_dispatch:
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -4,4 +4,3 @@
todo.md
0
maven.http
/.ci
99 changes: 7 additions & 92 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[package]
name = "jvc"
version = "0.1.20"
version = "0.1.12"
authors = ["Stanciu Neculai <neculai.stanciu@outlook.com>"]
edition = "2018"
description = "A simple tool that help with java versions."
license = "MIT"
repository= "https://github.com/neculai-stanciu/jvc"

[[bin]]
name = "jvc"
@@ -18,7 +21,7 @@ path = "src/jvc-init.rs"
structopt = "0.3.21"

# async runtime
tokio = { version = "1.1.1", features = ["full"] }
tokio = { version = "1.2.0", features = ["macros", "rt", "net", "io-util", "fs"] }
async-trait = "0.1.42"

# error handling
@@ -33,7 +36,7 @@ reqwest = { version = "0.11", features = ["json"] }
colored = "2.0.0"
# json serialization
serde = { version = "1.0.123", features = ["derive"] }
serde_json = "1.0.61"
serde_json = "1.0.62"
chrono = { version = "0.4.19", features = ["serde"] }
# temp dir
tempdir = "0.3.7"
@@ -53,7 +56,6 @@ dirs = "3.0.1"
csv = "1.1.5"
winreg= "0.8.0"


[profile.dev]
opt-level = 0
debug = true
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# jvc: Java versions controller
## Documentation
# jvc: java versions controller

A tool to handle java versions.
![Amount of downloads](https://img.shields.io/github/downloads/neculai-stanciu/jvc/total.svg?style=flat)
![Issues opened](https://img.shields.io/github/issues/neculai-stanciu/jvc)

A tool to handle java versions.

<!-- Badges -->
## Installation

## Supported shells
3 changes: 3 additions & 0 deletions src/commands/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -74,6 +74,9 @@ impl Executor for Setup {
let shell_path_as_str = shell_path
.to_str()
.ok_or(anyhow!("Cannot set shell path."))?;

debug!("Create a JVC_SHELL_PATH {}", shell_path_as_str);

let base_dir = config.get_base_dir_or_default();
let jvc_dir_as_str = base_dir
.to_str()
2 changes: 1 addition & 1 deletion src/jvc-init.rs
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ async fn set_persistent_path(value: &str) -> Result<()> {
Ok(())
}

#[tokio::main]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let start_time = Instant::now();
let args: Cli = Cli::from_args();
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ fn init_logging(log_level: &LogLevel) {
.init();
}

#[tokio::main]
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let start_time = Instant::now();

0 comments on commit 935b608

Please sign in to comment.