-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·189 lines (173 loc) · 5.64 KB
/
install.sh
File metadata and controls
executable file
·189 lines (173 loc) · 5.64 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# Description:
# Installation script for `git-conceal` (https://github.com/Automattic/git-conceal)
#
# The script downloads the `git-conceal` binary from GitHub releases for the current platform and architecture
# and installs it on the system.
#
# The script supports macOS (Intel and ARM), Linux (x86_64), and Windows (x86_64).
#
# Usage:
# To install git-conceal, run:
# curl -fsSL https://raw.githubusercontent.com/Automattic/git-conceal/trunk/install.sh | bash
#
# To install to a custom directory:
# curl -fsSL https://raw.githubusercontent.com/Automattic/git-conceal/trunk/install.sh | bash -s -- --prefix /custom/path
#
# Or download and run manually:
# curl -fsSL https://raw.githubusercontent.com/Automattic/git-conceal/trunk/install.sh -o install.sh
# bash install.sh [--prefix /custom/path]
#
set -euo pipefail
# Parse command line arguments
CUSTOM_PREFIX=""
while [[ $# -gt 0 ]]; do
case $1 in
--prefix)
CUSTOM_PREFIX="$2"
shift 2
;;
--prefix=*)
CUSTOM_PREFIX="${1#*=}"
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--prefix /custom/path]"
exit 1
;;
esac
done
# Determine platform-specific variables
OS=$(uname -s)
ARCH=$(uname -m)
if [[ "$OS" == "MINGW"* ]] || [[ "$OS" == "MSYS"* ]] || [[ "$OS" == "CYGWIN"* ]]; then
EXECUTABLE_NAME="git-conceal.exe"
INSTALL_CMD="/usr/bin/install"
IS_WINDOWS=true
else
EXECUTABLE_NAME="git-conceal"
INSTALL_CMD="install"
IS_WINDOWS=false
fi
# Map platform and architecture to Rust target triple format
case "$OS" in
Darwin)
case "$ARCH" in
arm64)
TARGET_TRIPLE="aarch64-apple-darwin"
;;
x86_64)
TARGET_TRIPLE="x86_64-apple-darwin"
;;
*)
echo "Unsupported architecture on macOS: $ARCH"
exit 2
;;
esac
;;
Linux)
case "$ARCH" in
x86_64)
TARGET_TRIPLE="x86_64-unknown-linux-gnu"
;;
aarch64|arm64)
TARGET_TRIPLE="aarch64-unknown-linux-gnu"
;;
*)
echo "Unsupported architecture on Linux: $ARCH"
exit 2
;;
esac
;;
MINGW*|MSYS*|CYGWIN*)
case "$ARCH" in
x86_64)
TARGET_TRIPLE="x86_64-pc-windows-gnu"
;;
*)
echo "Unsupported architecture on Windows: $ARCH"
exit 2
;;
esac
;;
*)
echo "Unsupported operating system: $OS"
exit 2
;;
esac
# Get the latest release tag from GitHub API
LATEST_RELEASE_URL="https://api.github.com/repos/Automattic/git-conceal/releases/latest"
RELEASE_INFO=$(curl --location --silent "$LATEST_RELEASE_URL")
if [[ -z "$RELEASE_INFO" ]]; then
echo "Failed to fetch release information from GitHub"
exit 1
fi
# Extract the version (tag_name) from the release info
VERSION=$(echo "$RELEASE_INFO" | jq -r '.tag_name // empty')
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "null" ]]; then
echo "Failed to extract version from release information"
exit 1
fi
# Construct the asset name
if [[ "$IS_WINDOWS" == "true" ]]; then
ASSET_NAME="git-conceal-${TARGET_TRIPLE}-${VERSION}.exe"
else
ASSET_NAME="git-conceal-${TARGET_TRIPLE}-${VERSION}"
fi
# Determine the install directory based on platform
if [[ -n "$CUSTOM_PREFIX" ]]; then
# Use custom prefix if provided
INSTALL_DIR="$CUSTOM_PREFIX"
else
if [[ "$IS_WINDOWS" == "true" ]]; then
# For Windows, try to use a directory in PATH or user's local bin
if [[ -n "${LOCALAPPDATA:-}" ]]; then
INSTALL_DIR="$LOCALAPPDATA/Programs/git-conceal"
else
INSTALL_DIR="$HOME/.local/bin"
fi
else
# For Unix-like systems, try /usr/local/bin first, fallback to ~/.local/bin
if [[ -w "/usr/local/bin" ]]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="$HOME/.local/bin"
fi
fi
fi
# Create temp directory for download
TEMP_DIR=$(mktemp -d)
trap "rm -rf '$TEMP_DIR'" EXIT
# Download the binary to temp directory
DOWNLOAD_URL="https://github.com/Automattic/git-conceal/releases/download/${VERSION}/${ASSET_NAME}"
TEMP_BINARY="$TEMP_DIR/$EXECUTABLE_NAME"
echo "Downloading $ASSET_NAME from GitHub releases..."
if ! curl --location --silent --fail --output "$TEMP_BINARY" "$DOWNLOAD_URL"; then
echo "Failed to download $ASSET_NAME from $DOWNLOAD_URL"
exit 1
fi
# Install the binary in INSTALL_DIR
INSTALL_PATH="$INSTALL_DIR/$EXECUTABLE_NAME"
echo "Installing $EXECUTABLE_NAME to $INSTALL_PATH..."
"$INSTALL_CMD" -d "$INSTALL_DIR"
"$INSTALL_CMD" -m 755 "$TEMP_BINARY" "$INSTALL_PATH"
# Remove quarantine attribute on macOS
if [[ "$OS" == "Darwin" ]]; then
if xattr -d com.apple.quarantine "$INSTALL_PATH" 2>/dev/null || true; then
echo "Removed quarantine attribute from $INSTALL_PATH"
fi
fi
# Verify installation
if [[ -f "$INSTALL_PATH" ]] && [[ -x "$INSTALL_PATH" ]]; then
echo "Successfully installed git-conceal to $INSTALL_PATH"
if [[ "$INSTALL_DIR" == "$HOME/.local/bin" ]] && [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
echo ""
echo "Note: $INSTALL_DIR is not in your PATH."
echo "Add the following to your shell configuration file (~/.bashrc, ~/.zshrc, etc.):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
else
echo "Installation failed: $INSTALL_PATH is not executable"
exit 1
fi