Skip to content

Commit

Permalink
fix: install from binary directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
nimish-ks committed Aug 27, 2024
1 parent 16d33a5 commit b12ba3a
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,22 @@ verify_checksum() {
local file="$1"
local checksum_url="$2"
local checksum_file="$TMPDIR/checksum.sha256"

wget_download "$checksum_url" "$checksum_file"

local expected_checksum=$(cat "$checksum_file" | awk '{print $1}')
local computed_checksum=$(sha256sum "$file" | awk '{print $1}')

if [[ "$expected_checksum" != "$computed_checksum" ]]; then
echo "Checksum verification failed for $file!"
exit 1
fi

while IFS= read -r line; do
local expected_checksum=$(echo "$line" | awk '{print $1}')
local target_file=$(echo "$line" | awk '{print $2}')

if [[ -e "$target_file" ]]; then
local computed_checksum=$(sha256sum "$target_file" | awk '{print $1}')

if [[ "$expected_checksum" != "$computed_checksum" ]]; then
echo "Checksum verification failed for $target_file!"
exit 1
fi
fi
done < "$checksum_file"
}

has_sudo_access() {
Expand All @@ -79,39 +85,26 @@ install_from_binary() {
x86_64)
ZIP_URL="$BASE_URL/v$VERSION/phase_cli_linux_amd64_$VERSION.zip"
CHECKSUM_URL="$BASE_URL/v$VERSION/phase_cli_linux_amd64_$VERSION.sha256"
EXTRACT_DIR="Linux-binary/phase"
;;
aarch64)
ZIP_URL="$BASE_URL/v$VERSION/phase_cli_linux_arm64_$VERSION.zip"
CHECKSUM_URL="$BASE_URL/v$VERSION/phase_cli_linux_arm64_$VERSION.sha256"
EXTRACT_DIR="phase_cli_release_$VERSION/Linux-binary/phase"
;;
*)
echo "Unsupported architecture: $ARCH. This script supports x86_64 and arm64."
exit 1
;;
esac

ZIP_FILE="$TMPDIR/phase_cli_${ARCH}_$VERSION.zip"
wget_download $ZIP_URL $ZIP_FILE

verify_checksum "$ZIP_FILE" "$CHECKSUM_URL"
wget_download "$ZIP_URL" "$TMPDIR/phase_cli_${ARCH}_$VERSION.zip"
unzip "$TMPDIR/phase_cli_${ARCH}_$VERSION.zip" -d "$TMPDIR"

unzip -o $ZIP_FILE -d $TMPDIR

if [ "$ARCH" = "aarch64" ]; then
BINARY_PATH="$TMPDIR/phase_cli_linux_arm64_$VERSION/phase_cli_release_$VERSION/Linux-binary/phase/phase"
INTERNAL_DIR_PATH="$TMPDIR/phase_cli_linux_arm64_$VERSION/phase_cli_release_$VERSION/Linux-binary/phase/*internal"
else
BINARY_PATH=$(find $TMPDIR -name "phase" -type f)
INTERNAL_DIR_PATH=$(find $TMPDIR -name "_internal" -type d)
fi

if [ ! -f "$BINARY_PATH" ] || [ ! -d "$INTERNAL_DIR_PATH" ]; then
echo "Failed to find 'phase' binary or '*internal' directory in the extracted contents."
echo "BINARY_PATH: $BINARY_PATH"
echo "INTERNAL_DIR_PATH: $INTERNAL_DIR_PATH"
exit 1
fi
BINARY_PATH="$TMPDIR/$EXTRACT_DIR/phase"
INTERNAL_DIR_PATH="$TMPDIR/$EXTRACT_DIR/_internal"

verify_checksum "$BINARY_PATH" "$CHECKSUM_URL"
chmod +x "$BINARY_PATH"

if ! has_sudo_access; then
Expand Down

0 comments on commit b12ba3a

Please sign in to comment.