-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·76 lines (61 loc) · 2.47 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·76 lines (61 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -e
REPO="dsecurity49/safe-migrate"
BIN_NAME="safe-migrate"
echo "Detecting operating system and architecture..."
# Detect OS
OS="$(uname -s)"
case "${OS}" in
Linux*) OS_TARGET="unknown-linux-musl";;
Darwin*) OS_TARGET="apple-darwin";;
*) echo "Unsupported OS: ${OS}. Please compile from source."; exit 1;;
esac
# Detect Architecture
ARCH="$(uname -m)"
case "${ARCH}" in
x86_64|amd64) ARCH_TARGET="x86_64";;
aarch64|arm64) ARCH_TARGET="aarch64";;
*) echo "Unsupported architecture: ${ARCH}. Please compile from source."; exit 1;;
esac
TARGET="${ARCH_TARGET}-${OS_TARGET}"
echo "Target detected: ${TARGET}"
echo "Fetching latest release version..."
# Get latest release tag from GitHub API
VERSION=$(curl -sL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "Error: Failed to fetch the latest version. Check your internet connection or GitHub API limits."
exit 1
fi
DOWNLOAD_URL="https://github.com/dsecurity49/safe-migrate/releases/download/${VERSION}/${BIN_NAME}-${TARGET}.tar.gz"
TMP_DIR=$(mktemp -d)
TAR_FILE="${TMP_DIR}/${BIN_NAME}.tar.gz"
echo "Downloading ${BIN_NAME} ${VERSION}..."
curl -sL "$DOWNLOAD_URL" -o "$TAR_FILE"
if ! grep -q "gzip compressed data" <(file "$TAR_FILE"); then
echo "Error: Downloaded file is not a valid archive. The release might still be building on GitHub Actions. Try again in a few minutes."
exit 1
fi
echo "Extracting archive..."
tar -xzf "$TAR_FILE" -C "$TMP_DIR"
# Determine install location based on permissions
if [ -w "/usr/local/bin" ] || sudo -n true 2>/dev/null; then
INSTALL_DIR="/usr/local/bin"
echo "Moving binary to ${INSTALL_DIR}..."
sudo mv "${TMP_DIR}/${BIN_NAME}" "${INSTALL_DIR}/${BIN_NAME}"
sudo chmod +x "${INSTALL_DIR}/${BIN_NAME}"
else
INSTALL_DIR="${HOME}/.local/bin"
echo "No sudo privileges detected. Installing to ${INSTALL_DIR}..."
mkdir -p "${INSTALL_DIR}"
mv "${TMP_DIR}/${BIN_NAME}" "${INSTALL_DIR}/${BIN_NAME}"
chmod +x "${INSTALL_DIR}/${BIN_NAME}"
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo "Note: ${INSTALL_DIR} is not in your PATH. You may need to add it."
fi
fi
# Cleanup
rm -rf "$TMP_DIR"
echo "----------------------------------------"
echo "${BIN_NAME} ${VERSION} installed successfully!"
echo "Run 'safe-migrate --help' to get started."
echo "----------------------------------------"