1+ #! /bin/sh
2+ #
3+ # This script downloads and installs the latest binary release of gitx.
4+ # It detects the user's OS and architecture to download the correct binary.
5+ #
6+ # Usage:
7+ # curl -sSL https://raw.githubusercontent.com/gitxtui/gitx/master/install.sh | bash
8+
9+ set -e
10+
11+ # The GitHub repository in the format "owner/repo".
12+ REPO=" gitxtui/gitx"
13+ INSTALL_DIR=" /usr/local/bin"
14+
15+ # Get the operating system.
16+ get_os () {
17+ case " $( uname -s) " in
18+ Linux* ) OS=' linux' ;;
19+ Darwin* ) OS=' darwin' ;;
20+ * )
21+ echo " Unsupported operating system: $( uname -s) "
22+ exit 1
23+ ;;
24+ esac
25+ echo " $OS "
26+ }
27+
28+ # Get the architecture.
29+ get_arch () {
30+ case " $( uname -m) " in
31+ x86_64|amd64) ARCH=' amd64' ;;
32+ aarch64|arm64) ARCH=' arm64' ;;
33+ * )
34+ echo " Unsupported architecture: $( uname -m) "
35+ exit 1
36+ ;;
37+ esac
38+ echo " $ARCH "
39+ }
40+
41+ # Get the latest release tag from the GitHub API.
42+ get_latest_release () {
43+ curl --silent " https://api.github.com/repos/$REPO /releases/latest" |
44+ grep ' "tag_name":' |
45+ sed -E ' s/.*"([^"]+)".*/\1/'
46+ }
47+
48+ main () {
49+ OS=$( get_os)
50+ ARCH=$( get_arch)
51+ VERSION=$( get_latest_release)
52+
53+ if [ -z " $VERSION " ]; then
54+ echo " Error: Could not find the latest release version for $REPO ."
55+ exit 1
56+ fi
57+
58+ # Construct the archive filename and download URL.
59+ VERSION_NUM=$( echo " $VERSION " | sed ' s/v//' )
60+ FILENAME=" gitx_${VERSION_NUM} _${OS} _${ARCH} .tar.gz"
61+ DOWNLOAD_URL=" https://github.com/$REPO /releases/download/${VERSION} /${FILENAME} "
62+
63+ # Download and extract the binary.
64+ echo " Downloading gitx ${VERSION} for ${OS} /${ARCH} ..."
65+ TEMP_DIR=$( mktemp -d)
66+ # Download to a temporary directory.
67+ curl -sSL -o " $TEMP_DIR /$FILENAME " " $DOWNLOAD_URL "
68+
69+ echo " Installing gitx to ${INSTALL_DIR} ..."
70+ # Extract the archive.
71+ tar -xzf " $TEMP_DIR /$FILENAME " -C " $TEMP_DIR "
72+
73+ # Move the binary to the installation directory.
74+ # Use sudo if the directory is not writable by the current user.
75+ if [ -w " $INSTALL_DIR " ]; then
76+ mv " $TEMP_DIR /gitx" " ${INSTALL_DIR} /gitx"
77+ else
78+ echo " Root permission is required to install gitx to ${INSTALL_DIR} "
79+ sudo mv " $TEMP_DIR /gitx" " ${INSTALL_DIR} /gitx"
80+ fi
81+
82+ # Clean up the temporary directory.
83+ rm -rf " $TEMP_DIR "
84+
85+ echo " "
86+ echo " gitx has been installed successfully!"
87+ echo " Run 'gitx' to get started."
88+ }
89+
90+ # Run the main function.
91+ main
0 commit comments