150 lines
3.8 KiB
Bash
Executable file
150 lines
3.8 KiB
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
install_dir="${PREFIX:-/usr/local}/bin"
|
|
tmp_path="${TMPDIR:-/tmp}"
|
|
add_alias=${ALIAS:-0}
|
|
nightly=${NIGHTLY:-0}
|
|
verify=${VERIFY:-0}
|
|
local=${LOCAL:-0}
|
|
|
|
while true; do
|
|
case "${1}" in
|
|
-a | --alias)
|
|
add_alias=1
|
|
shift 1
|
|
;;
|
|
-n | --nightly)
|
|
nightly=1
|
|
shift 1
|
|
;;
|
|
-p | --prefix)
|
|
install_dir=/$2
|
|
shift 2
|
|
;;
|
|
-V | --verify)
|
|
verify=1
|
|
shift 1
|
|
;;
|
|
-l | --local)
|
|
local=1
|
|
shift 1
|
|
;;
|
|
--)
|
|
shift 1
|
|
break
|
|
;;
|
|
*) break ;;
|
|
esac
|
|
done
|
|
|
|
# prompt for nightly build option if interactive
|
|
if [ "$nightly" -eq 0 ] && [ -t 0 ]; then
|
|
printf "do you want to install a Nightly build? [y/N]: "
|
|
read -r answer_nightly
|
|
if [ "$answer_nightly" = "y" ] || [ "$answer_nightly" = "Y" ]; then
|
|
nightly=1
|
|
fi
|
|
fi
|
|
|
|
if [ "$nightly" -eq 1 ]; then
|
|
repo="neurocyte/flow-nightly"
|
|
else
|
|
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
|
|
|
|
# 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)
|
|
[ -z "$version" ] && {
|
|
echo "failed to fetch latest version"
|
|
exit 1
|
|
}
|
|
|
|
# construct download url
|
|
# note: nightly assets are named like "flow-<version>-<os>-<arch>.<ext>"
|
|
filename="flow-$version-$os-$arch"
|
|
ext="tar.gz"
|
|
if [ "$os" = "windows" ]; then
|
|
ext="zip"
|
|
fi
|
|
url="https://github.com/$repo/releases/download/$version/$filename.$ext"
|
|
|
|
if [ "$nightly" -eq 1 ]; then
|
|
echo "downloading NIGHTLY build $version..."
|
|
else
|
|
echo "downloading flow $version..."
|
|
fi
|
|
|
|
curl -fL "$url" -o "$tmp_path/$filename.$ext"
|
|
|
|
# simple file size check (adjust threshold if needed)
|
|
filesize=$(stat -c%s "$tmp_path/$filename.$ext" 2>/dev/null || stat -f%z "$tmp_path/$filename.$ext")
|
|
if [ "$filesize" -lt 100 ]; then
|
|
echo "downloaded file appears to be invalid (size: ${filesize} bytes)"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$verify" -eq 0 ] && [ -t 0 ]; then
|
|
printf "do you want to download and verify the gpg signature? [y/N]: "
|
|
read -r answer_verify
|
|
if [ "$answer_verify" = "y" ] || [ "$answer_verify" = "Y" ]; then
|
|
verify=1
|
|
fi
|
|
fi
|
|
|
|
if [ "$verify" -eq 1 ]; then
|
|
curl -fL "$url.sig" -o "$tmp_path/$filename.$ext.sig"
|
|
curl -fL 'https://flow-control.dev/public.gpg' -o "$tmp_path/flow-control-public.gpg"
|
|
gpg --no-default-keyring --keyring "$tmp_path/flow-control-public.gpg" --verify "$tmp_path/$filename.$ext.sig" "$tmp_path/$filename.$ext"
|
|
|
|
if [ "$local" -eq 1 ]; then
|
|
gpg --verify "$tmp_path/$filename.$ext.sig" "$tmp_path/$filename.$ext"
|
|
fi
|
|
|
|
rm "$tmp_path/flow-control-public.gpg"
|
|
rm "$tmp_path/$filename.$ext.sig"
|
|
fi
|
|
|
|
echo "installing $([ "$nightly" -eq 1 ] && echo 'NIGHTLY build' || echo 'flow')..."
|
|
if [ "$ext" = "tar.gz" ]; then
|
|
tar -xzf "$tmp_path/$filename.$ext" -C "$install_dir"
|
|
else
|
|
unzip -o "$tmp_path/$filename.$ext" -d "$install_dir"
|
|
fi
|
|
|
|
chmod +x "$install_dir/flow"
|
|
rm "$tmp_path/$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 ] && [ "$add_alias" -eq 0 ]; then
|
|
printf "do you want to create an alias 'f' for 'flow'? [y/N]: "
|
|
read -r answer_alias
|
|
if [ "$answer_alias" = "y" ] || [ "$answer_alias" = "Y" ]; then
|
|
create_alias
|
|
fi
|
|
fi
|