Skip to content

Commit

Permalink
Merge pull request #14 from titanom/feat/install-script
Browse files Browse the repository at this point in the history
feat: add install script
  • Loading branch information
nyarthan committed Sep 18, 2023
2 parents 60cd105 + 97efac0 commit c619352
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 14 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
args: -- -D warnings

build-linux:
name: Build for x86_64-unknown-linux-gnu
name: Build for x86_64-unknown-linux-musl
needs: check
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
Expand All @@ -53,19 +53,21 @@ jobs:
profile: minimal
toolchain: stable
override: true
target: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-musl

- name: Build for x86_64-unknown-linux-gnu
- run: sudo apt-get update && sudo apt install musl-tools

- name: Build for x86_64-unknown-linux-musl
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target x86_64-unknown-linux-gnu
args: --release --target x86_64-unknown-linux-musl

- name: Store build artifact
uses: actions/upload-artifact@v3
with:
name: x86_64-unknown-linux-gnu
path: ./target/x86_64-unknown-linux-gnu/release/bwenv
name: x86_64-unknown-linux-musl
path: ./target/x86_64-unknown-linux-musl/release/bwenv

build-apple-silicon:
name: Build aarch64-apple-darwin
Expand Down Expand Up @@ -104,20 +106,20 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Download build artifacts for x86_64-unknown-linux-gnu
- name: Download build artifacts for x86_64-unknown-linux-musl
uses: actions/download-artifact@v3
with:
name: x86_64-unknown-linux-gnu
path: ./x86_64-unknown-linux-gnu
name: x86_64-unknown-linux-musl
path: ./x86_64-unknown-linux-musl

- name: Download build artifacts for aarch64-apple-darwin
uses: actions/download-artifact@v3
with:
name: aarch64-apple-darwin
path: ./aarch64-apple-darwin

- name: Create archive for x86_64-unknown-linux-gnu
run: zip -r -j bwenv-x86_64-unknown-linux-gnu.zip x86_64-unknown-linux-gnu/bwenv
- name: Create archive for x86_64-unknown-linux-musl
run: zip -r -j bwenv-x86_64-unknown-linux-musl.zip x86_64-unknown-linux-musl/bwenv

- name: Create archive for aarch64-apple-darwin
run: zip -r -j bwenv-aarch64-apple-darwin.zip aarch64-apple-darwin/bwenv
Expand All @@ -133,7 +135,7 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: |
./bwenv-x86_64-unknown-linux-gnu.zip
./bwenv-x86_64-unknown-linux-musl.zip
./bwenv-aarch64-apple-darwin.zip
tag_name: "v${{ steps.get_version.outputs.version }}"
name: "Release v${{ steps.get_version.outputs.version }}"
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bwenv"
version = "0.1.4"
version = "0.1.5"
edition = "2021"

[dependencies]
Expand All @@ -15,3 +15,4 @@ simple_logger = { version = "4.2.0", default-features = false, features = [
tokio = { version = "1.32.0", features = ["full"] }
toml = "0.7.6"
uuid = "1.4.1"
openssl = { version = "0.10", features = ["vendored"] }
109 changes: 109 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash

set -e

RELEASE="latest"
OS="$(uname -s)"

if [ -d "$HOME/.bwenv" ]; then
INSTALL_DIR="$HOME/.bwenv"
elif [ -n "$XDG_DATA_HOME" ]; then
INSTALL_DIR="$XDG_DATA_HOME/bwenv"
elif [ "$OS" = "Darwin" ]; then
INSTALL_DIR="$HOME/Library/Application Support/bwenv"
else
INSTALL_DIR="$HOME/.local/share/bwenv"
fi

FILENAME=bwenv-x86_64-unknown-linux-musl

download_bwenv() {
URL="https://github.com/titanom/bwenv/releases/latest/download/$FILENAME.zip"

DOWNLOAD_DIR=$(mktemp -d)

echo "Downloading $URL..."

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

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

unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"

if [ -f "$DOWNLOAD_DIR/bwenv" ]; then
mv "$DOWNLOAD_DIR/bwenv" "$INSTALL_DIR/bwenv"
else
mv "$DOWNLOAD_DIR/$FILENAME/bwenv" "$INSTALL_DIR/bwenv"
fi

chmod u+x "$INSTALL_DIR/bwenv"
}

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 [ "$SHOULD_EXIT" = "true" ]; then
echo "Not installing bwenv due to missing dependencies."
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" = "bash" ]; then
CONF_FILE=$HOME/.bashrc
ensure_containing_dir_exists "$CONF_FILE"
echo "Installing for Bash. Appending the following to $CONF_FILE:"
echo ""
echo ' # bwenv'
echo ' export PATH="'"$INSTALL_DIR"':$PATH"'

echo '' >>$CONF_FILE
echo '# bwenv' >>$CONF_FILE
echo 'export PATH="'"$INSTALL_DIR"':$PATH"' >>$CONF_FILE

else
echo "Could not infer shell type. Please set up manually."
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"
}

check_dependencies
download_bwenv
if [ "$SKIP_SHELL" != "true" ]; then
setup_shell
fi

0 comments on commit c619352

Please sign in to comment.