-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
67 lines (54 loc) · 1.61 KB
/
install.sh
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
#!/bin/bash
USER_REPO="ysawa0/create-python-app"
BINARY_NAME="cpa"
TARGET_DIR="$HOME/bin"
# Determine OS type and corresponding download asset name
OS_TYPE=""
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS_TYPE="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS_TYPE="macOS"
else
echo "Unsupported operating system."
exit 1
fi
# Prepare the binary and zip names
ZIP_NAME="$BINARY_NAME-$OS_TYPE.zip"
ZIP_PATH="$TARGET_DIR/$ZIP_NAME"
# Fetch the latest release data from GitHub API
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/$USER_REPO/releases/latest |
grep "browser_download_url.*$OS_TYPE.zip" |
cut -d '"' -f 4)
# Check if the download URL was found
if [ -z "$DOWNLOAD_URL" ]; then
echo "No release found for $OS_TYPE"
exit 1
fi
# Create the target directory if it doesn't exist
mkdir -p "$TARGET_DIR"
# Download the zip file
curl -L -o "$ZIP_PATH" "$DOWNLOAD_URL" || {
echo "Failed to download the release"
exit 1
}
# Unzip the binary to the target directory
unzip -o "$ZIP_PATH" -d "$TARGET_DIR" || {
echo "Failed to unzip the release"
exit 1
}
# Assume the binary is named $BINARY_NAME inside the zip
BINARY_PATH="$TARGET_DIR/$BINARY_NAME"
# Give execute permissions to the binary
chmod +x "$BINARY_PATH" || {
echo "Failed to set execute permissions on the binary"
exit 1
}
# Remove the downloaded zip
rm "$ZIP_PATH"
# # Optionally, append the target directory to PATH if it's not already there
if [[ ":$PATH:" != *":$TARGET_DIR:"* ]]; then
echo "export PATH=\$PATH:$TARGET_DIR" >>~/.bashrc
echo "export PATH=\$PATH:$TARGET_DIR" >>~/.zshrc
echo "$TARGET_DIR added to PATH"
fi
echo "cpa installed to $BINARY_PATH"