Skip to content

Commit 8e6bab8

Browse files
committed
refactor: refactor binary download and installation workflow
- Add use of a temporary directory for downloads and clean up when done - Download the binary to the temporary directory before moving it to the install location - Improve file handling by renaming and moving the binary in one step Signed-off-by: appleboy <[email protected]>
1 parent 7ca52b0 commit 8e6bab8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

install.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
set -euo pipefail
44

5+
# Create temp directory for downloads.
6+
TMPDIR="$(mktemp -d)"
7+
function cleanup() {
8+
rm -rf "${TMPDIR}"
9+
}
10+
trap cleanup EXIT INT TERM
11+
512
APP=CodeGPT
613

714
RED='\033[0;31m'
@@ -53,12 +60,14 @@ function download_and_install() {
5360
CLIENT_BINARY="CodeGPT-${VERSION}-${CLIENT_PLATFORM}-${CLIENT_ARCH}"
5461
print_message info "Downloading ${CLIENT_BINARY} from ${DOWNLOAD_URL_PREFIX}"
5562
mkdir -p "$INSTALL_DIR" || log_error "Failed to create directory: $INSTALL_DIR" 5
56-
TARGET="$INSTALL_DIR/${CLIENT_BINARY}"
63+
64+
# Use temp dir for download
65+
TARGET="${TMPDIR}/${CLIENT_BINARY}"
5766

5867
curl -# -fSL --retry 5 --keepalive-time 2 ${INSECURE_OPTION} "${DOWNLOAD_URL_PREFIX}/${CLIENT_BINARY}" -o "${TARGET}"
5968
chmod +x "${TARGET}" || log_error "Failed to set executable permission on: ${TARGET}" 7
60-
# Rename the binary to codegpt
61-
mv "${TARGET}" "${INSTALL_DIR}/codegpt" || log_error "Failed to rename ${TARGET} to ${INSTALL_DIR}/codegpt" 8
69+
# Move the binary to install dir and rename to codegpt
70+
mv "${TARGET}" "${INSTALL_DIR}/codegpt" || log_error "Failed to move ${TARGET} to ${INSTALL_DIR}/codegpt" 8
6271
# show the version
6372
print_message info "Installed ${ORANGE}${CLIENT_BINARY}${NC} to ${GREEN}${INSTALL_DIR}${NC}"
6473
print_message info "Run ${ORANGE}codegpt version${NC} to show the version"

0 commit comments

Comments
 (0)