Skip to content

Commit

Permalink
chore:creating curl and check-sums scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
urizennnn committed Jul 28, 2024
1 parent 8ca5de7 commit 236d4b7
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 1 deletion.
40 changes: 40 additions & 0 deletions check-sum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Directory containing your CLI binaries
BINARY_DIR="./bin"

# Output file for checksums
CHECKSUM_FILE="your-cli-checksums.txt"

# Ensure the binary directory exists
if [ ! -d "$BINARY_DIR" ]; then
echo "Error: Binary directory not found: $BINARY_DIR"
exit 1
fi

# Change to the binary directory
cd "$BINARY_DIR" || exit 1

# Remove any existing checksum file
rm -f "$CHECKSUM_FILE"

# Generate checksums for all binaries
for file in your-cli-*; do
if [ -f "$file" ]; then
if command -v sha256sum > /dev/null 2>&1; then
# Linux
sha256sum "$file" >> "$CHECKSUM_FILE"
elif command -v shasum > /dev/null 2>&1; then
# macOS
shasum -a 256 "$file" >> "$CHECKSUM_FILE"
else
echo "Error: No suitable checksum tool found (sha256sum or shasum)"
exit 1
fi
fi
done

echo "Checksums have been saved to $CHECKSUM_FILE"

# Display the contents of the checksum file
cat "$CHECKSUM_FILE"
2 changes: 2 additions & 0 deletions express-cli-check-sum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2e98285ca2857bae5e3ee42aec8237bde21470bd8a92295a73822903a2ff65d3 bin/linux
20cf988344455b84159eca537f021873b4100f2df89f0951e736d3d82b1c22fb bin/windows.exe
99 changes: 99 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash

BASE_URL="https://github.com/urizennnn/express-cli/releases/download/v2.4.5"
CHECKSUM_URL="https://example.com/express-cli/express-cli-check-sum.txt"


OS="$(uname -s)"
ARCH="$(uname -m)"


case "$OS" in
Linux*)
OS_SUFFIX="linux"
TARGET_DIR="/usr/local/bin"
SHA256SUM="sha256sum"
;;
Darwin*)
OS_SUFFIX="macos"
TARGET_DIR="/usr/local/bin"
SHA256SUM="shasum -a 256"
;;
CYGWIN*|MINGW*|MSYS_NT*)
OS_SUFFIX="windows.exe"
TARGET_DIR="/c/Windows/System32"
SHA256SUM="sha256sum"
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac


case "$ARCH" in
x86_64|amd64) ARCH_SUFFIX="amd64" ;;
arm64|aarch64) ARCH_SUFFIX="arm64" ;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac


FILENAME="express-cli-${OS_SUFFIX}-${ARCH_SUFFIX}"
FULL_URL="${BASE_URL}/express-cli-${OS_SUFFIX}-${ARCH_SUFFIX}"
if [ "$OS_SUFFIX" == "windows.exe" ]; then
TARGET_FILE="express-cli.exe"
else
TARGET_FILE="express-cli"
fi


TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR" || exit 1


echo "Downloading $TARGET_FILE from $FULL_URL..."
if ! curl -fsSL "$FULL_URL" -o "$FILENAME"; then
echo "Failed to download the binary. Please check your internet connection and try again."
exit 1
fi


echo "Downloading checksums..."
if ! curl -fsSL "$CHECKSUM_URL" -o checksums.txt; then
echo "Failed to download checksums. Please check your internet connection and try again."
exit 1
fi


echo "Verifying checksum..."
EXPECTED_CHECKSUM=$(grep "$FILENAME" checksums.txt | awk '{print $1}')
ACTUAL_CHECKSUM=$($SHA256SUM "$FILENAME" | awk '{print $1}')

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
echo "Checksum verification failed. The downloaded file may be corrupted or tampered with."
exit 1
fi

echo "Checksum verified successfully."


if [ "$OS_SUFFIX" != "windows.exe" ]; then
chmod +x "$FILENAME"
fi


if [ "$OS_SUFFIX" == "windows.exe" ]; then
mv "$FILENAME" "$TARGET_DIR/$TARGET_FILE"
else
sudo mv "$FILENAME" "$TARGET_DIR/$TARGET_FILE"
fi


cd - || exit 1
rm -rf "$TEMP_DIR"

echo "express-cli has been installed successfully to $TARGET_DIR/$TARGET_FILE!"

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@urizen/express-cli",
"version": "2.4.5",
"version": "2.4.6",
"license": "MIT",
"bin": {
"express": "bin/linux"
Expand Down

0 comments on commit 236d4b7

Please sign in to comment.