Improve installer
This commit is contained in:
parent
7a2424a84e
commit
1a8f883e21
1 changed files with 89 additions and 27 deletions
116
install
116
install
|
@ -1,42 +1,104 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
REPO="neurocyte/flow"
|
install_dir="/usr/local/bin"
|
||||||
INSTALL_DIR="/usr/local/bin"
|
add_alias=0
|
||||||
|
nightly=0
|
||||||
|
|
||||||
# detect os and architecture
|
# parse command-line arguments for alias option only
|
||||||
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
for arg in "$@"; do
|
||||||
if [ "$OS" = "darwin" ]; then
|
case "$arg" in
|
||||||
OS="macos"
|
--alias|-a)
|
||||||
|
add_alias=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# prompt for nightly build option if interactive
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
printf "do you want to install a Nightly build? [y/N]: "
|
||||||
|
read answer_nightly
|
||||||
|
if [ "$answer_nightly" = "y" ] || [ "$answer_nightly" = "Y" ]; then
|
||||||
|
nightly=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ARCH="$(uname -m)"
|
if [ "$nightly" -eq 1 ]; then
|
||||||
case "$ARCH" in
|
repo="neurocyte/flow-nightly"
|
||||||
x86_64) ARCH="x86_64" ;;
|
else
|
||||||
arm64) ARCH="aarch64" ;;
|
repo="neurocyte/flow"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# detect os and architecture
|
||||||
|
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||||
|
if [ "$os" = "darwin" ]; then
|
||||||
|
os="macos"
|
||||||
|
fi
|
||||||
|
|
||||||
|
arch="$(uname -m)"
|
||||||
|
case "$arch" in
|
||||||
|
x86_64) arch="x86_64" ;;
|
||||||
|
arm64) arch="aarch64" ;;
|
||||||
|
i686) arch="x86" ;;
|
||||||
|
i386) arch="x86" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# get latest version tag from github releases api
|
# get latest version tag from github releases api
|
||||||
VERSION=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | cut -d'"' -f4)
|
version=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep '"tag_name":' | cut -d'"' -f4)
|
||||||
[ -z "$VERSION" ] && { echo "failed to fetch latest version"; exit 1; }
|
[ -z "$version" ] && { echo "failed to fetch latest version"; exit 1; }
|
||||||
|
|
||||||
# construct download url
|
# construct download url
|
||||||
FILENAME="flow-$VERSION-$OS-$ARCH"
|
# note: nightly assets are named like "flow-<version>-<os>-<arch>.<ext>"
|
||||||
EXT="tar.gz"
|
filename="flow-$version-$os-$arch"
|
||||||
[ "$OS" = "windows" ] && EXT="zip"
|
ext="tar.gz"
|
||||||
URL="https://github.com/$REPO/releases/download/$VERSION/$FILENAME.$EXT"
|
if [ "$os" = "windows" ]; then
|
||||||
|
ext="zip"
|
||||||
|
fi
|
||||||
|
url="https://github.com/$repo/releases/download/$version/$filename.$ext"
|
||||||
|
|
||||||
echo "downloading flow $VERSION..."
|
if [ "$nightly" -eq 1 ]; then
|
||||||
curl -L "$URL" -o "/tmp/$FILENAME.$EXT"
|
echo "downloading NIGHTLY build $version..."
|
||||||
|
|
||||||
echo "installing flow..."
|
|
||||||
if [ "$EXT" = "tar.gz" ]; then
|
|
||||||
tar -xzf "/tmp/$FILENAME.$EXT" -C "$INSTALL_DIR"
|
|
||||||
else
|
else
|
||||||
unzip -o "/tmp/$FILENAME.$EXT" -d "$INSTALL_DIR"
|
echo "downloading flow $version..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x "$INSTALL_DIR/flow"
|
curl -fL "$url" -o "/tmp/$filename.$ext"
|
||||||
rm "/tmp/$FILENAME.$EXT"
|
|
||||||
echo "flow installed successfully!"
|
# simple file size check (adjust threshold if needed)
|
||||||
|
filesize=$(stat -c%s "/tmp/$filename.$ext" 2>/dev/null || stat -f%z "/tmp/$filename.$ext")
|
||||||
|
if [ "$filesize" -lt 100 ]; then
|
||||||
|
echo "downloaded file appears to be invalid (size: ${filesize} bytes)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "installing $( [ "$nightly" -eq 1 ] && echo 'NIGHTLY build' || echo 'flow')..."
|
||||||
|
if [ "$ext" = "tar.gz" ]; then
|
||||||
|
tar -xzf "/tmp/$filename.$ext" -C "$install_dir"
|
||||||
|
else
|
||||||
|
unzip -o "/tmp/$filename.$ext" -d "$install_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x "$install_dir/flow"
|
||||||
|
rm "/tmp/$filename.$ext"
|
||||||
|
echo "$( [ "$nightly" -eq 1 ] && echo 'NIGHTLY build' || echo 'flow') installed successfully!"
|
||||||
|
|
||||||
|
create_alias() {
|
||||||
|
if [ -e "$install_dir/f" ]; then
|
||||||
|
echo "warning: existing file or alias detected at $install_dir/f, overwriting..."
|
||||||
|
rm -f "$install_dir/f"
|
||||||
|
fi
|
||||||
|
ln -s "$install_dir/flow" "$install_dir/f"
|
||||||
|
echo "alias 'f' created successfully!"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$add_alias" -eq 1 ]; then
|
||||||
|
create_alias
|
||||||
|
elif [ -t 0 ]; then
|
||||||
|
printf "do you want to create an alias 'f' for 'flow'? [y/N]: "
|
||||||
|
read answer_alias
|
||||||
|
if [ "$answer_alias" = "y" ] || [ "$answer_alias" = "Y" ]; then
|
||||||
|
create_alias
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue