应文浩wenhao.ying@xiaobao100.com e25ac591a7 init easy-code
2026-04-06 07:24:24 +08:00

56 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
REPO="free-code/free-code"
INSTALL_DIR="${HOME}/.free-code/bin"
echo "Installing free-code..."
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "${OS}" in
darwin) OS="osx" ;;
linux) OS="linux" ;;
*) echo "Unsupported OS: ${OS}"; exit 1 ;;
esac
case "${ARCH}" in
x86_64|amd64) ARCH="x64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: ${ARCH}"; exit 1 ;;
esac
RID="${OS}-${ARCH}"
BINARY_NAME="free-code"
if [ "${OS}" = "win" ]; then
BINARY_NAME="free-code.exe"
fi
mkdir -p "${INSTALL_DIR}"
echo "Downloading ${RID} binary..."
echo "Building from source..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
dotnet publish "${SCRIPT_DIR}/../src/FreeCode/FreeCode.csproj" \
-c Release \
-r "${RID}" \
/p:PublishAot=true \
/p:PublishSingleFile=true \
/p:PublishTrimmed=true \
-o "${INSTALL_DIR}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}" 2>/dev/null || true
echo "Adding to PATH..."
PROFILE_FILES=("${HOME}/.bashrc" "${HOME}/.zshrc" "${HOME}/.profile")
for PROFILE in "${PROFILE_FILES[@]}"; do
if [ -f "${PROFILE}" ] && ! grep -q "${INSTALL_DIR}" "${PROFILE}" 2>/dev/null; then
printf 'export PATH="%s:$PATH"\n' "${INSTALL_DIR}" >> "${PROFILE}"
echo "Added to ${PROFILE}"
fi
done
echo "Installation complete. Run 'source ~/.bashrc' or start a new terminal."