Skip to content

Commit

Permalink
feat: add install sh
Browse files Browse the repository at this point in the history
  • Loading branch information
luhc228 committed Jun 3, 2024
1 parent 9a6663b commit 1743b33
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
118 changes: 118 additions & 0 deletions shell/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

# This file is based on: https://github.com/Schniz/fnm/blob/master/.ci/install.sh

set -e

VERSION="cli-v0.0.0-beta.5"
OS="$(uname -s)"

case "${OS}" in
MINGW* | Win*) OS="Windows" ;;
esac

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

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

case $key in
--install)
COMMAND="install"
shift # past argument
;;
--list)
COMMAND="list"
shift # past argument
;;
--manifest)
MANIFEST_PATH="$2"
shift # past argument
shift # past value
;;
*)
echo "Unrecognized argument $key"
exit 1
;;
esac
done
}

set_filename() {
if [ "$OS" = "Linux" ]; then
# TODO: Support Linux
# Based on https://stackoverflow.com/a/45125525
case "$(uname -m)" in
arm | armv7*)
FILENAME="toolkit-linux-arm32"
;;
aarch* | armv8*)
FILENAME="toolkit-linux-arm64"
;;
*)
FILENAME="toolkit-linux"
esac
elif [ "$OS" = "Darwin" ]; then
case "$(uname -m)" in
arm64)
FILENAME="toolkit-macOS-aarch64"
;;
*)
FILENAME="toolkit-macOS-x86_64"
esac
elif [ "$OS" = "Windows" ]; then
FILENAME="toolkit-Windows-x86_64"
else
echo "OS $OS is not supported."
echo "If you think that's a bug - please file an issue"
exit 1
fi
}

download_toolkit() {
URL="https://github.com/apptools-lab/AppToolkit/releases/download/$VERSION/$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/toolkit" ]; then
mv "$DOWNLOAD_DIR/toolkit" "$INSTALL_DIR/toolkit"
else
mv "$DOWNLOAD_DIR/$FILENAME/toolkit" "$INSTALL_DIR/toolkit"
fi

chmod u+x "$INSTALL_DIR/toolkit"
}

setup_shell() {
if [ -z "$MANIFEST_PATH" ]; then
"$INSTALL_DIR/toolkit" $COMMAND
else
"$INSTALL_DIR/toolkit" $COMMAND --manifest "$MANIFEST_PATH"
fi
}

parse_args "$@"
set_filename
download_toolkit
setup_shell
11 changes: 11 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub struct Cli {
pub enum Commands {
#[command(name = "install", about = "Install toolkits.")]
Install(InstallOpts),
// TODO: Implement the command
// #[command(name = "list", about = "Show the toolkits Details.")]
// List(ListOpts),
}

#[derive(Parser, Debug)]
Expand All @@ -22,3 +25,11 @@ pub struct InstallOpts {
)]
pub manifest: String,
}

#[derive(Parser, Debug)]
pub struct GitSSHOpts {
#[arg(long)]
user_name: String,
#[arg(long)]
user_email: String,
}

0 comments on commit 1743b33

Please sign in to comment.