Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install script improvements #785

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh

# Function to check for required commands
check_command() {
command -v "$1" >/dev/null 2>&1 || { echo >&2 "Error: $1 is required but not installed."; exit 1; }
}

# Check for required commands
check_command curl
check_command wget
check_command sha256sum || check_command sha1sum

# Set checksum command based on availability
CHECKSUM_CMD=sha256sum
if ! command -v $CHECKSUM_CMD >/dev/null 2>&1; then
CHECKSUM_CMD=sha1sum
fi

# Function to download and verify a file
download_and_verify() {
URL=$1
EXPECTED_CHECKSUM=$2
TEMP_FILE=$(mktemp)

# Download the file
if command -v curl >/dev/null 2>&1; then
curl -L -o "$TEMP_FILE" "$URL"
else
wget -O "$TEMP_FILE" "$URL"
fi

# Verify the checksum
if [ "$($CHECKSUM_CMD "$TEMP_FILE" | awk '{print $1}')" != "$EXPECTED_CHECKSUM" ]; then
echo "Checksum verification failed!"
rm -f "$TEMP_FILE"
exit 1
fi

echo "Download and verification successful!"
# Continue with installation...
}

# Example usage
download_and_verify "https://example.com/file" "expectedchecksumvalue"

# Cleanup
rm -f "$TEMP_FILE"
echo "Installation completed successfully!"
Loading