aboutsummaryrefslogtreecommitdiffstats
path: root/make-hyperbola.sh
diff options
context:
space:
mode:
Diffstat (limited to 'make-hyperbola.sh')
-rw-r--r--make-hyperbola.sh134
1 files changed, 134 insertions, 0 deletions
diff --git a/make-hyperbola.sh b/make-hyperbola.sh
new file mode 100644
index 0000000..718c0f9
--- /dev/null
+++ b/make-hyperbola.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+
+# Default tag
+default_tag="v0.4.3"
+default_release="2023.09.25"
+latest_tag="latest"
+
+# Function to display help
+show_help() {
+ echo "Usage: $0 [-t TAG] [-h]"
+ echo " -t TAG Specify the tag (default: $default_tag)"
+ echo " -r VERSION Specify the release version (default: $default_release)"
+ echo " -h Show this help"
+}
+
+# Process command line options
+while getopts ":t:h" opt; do
+ case $opt in
+ r)
+ release="$OPTARG"
+ ;;
+ t)
+ tag="$OPTARG"
+ ;;
+ h)
+ show_help && exit 0
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ show_help && exit 1
+ ;;
+ :)
+ echo "Option -$OPTARG requires an argument." >&2
+ show_help && exit 1
+ ;;
+ esac
+done
+
+# Use default tag if not specified
+tag="${tag:-$default_tag}"
+
+# Use default release version if not specified
+release="${release:-$default_release}"
+
+# Working directory
+script_dir="$(cd "$(dirname "$0")" && pwd)"
+
+# Check if files exist in the current directory
+if [[ ! -e "$script_dir/hyperbola-bootstrap-i686.tar.gz" || ! -e "$script_dir/hyperbola-bootstrap-x86_64.tar.gz" ]]; then
+ echo "Downloading files for version $release..."
+
+ # Download files from the provided link
+ wget -P "$script_dir" "https://archive.fridu.us/hyperbola/iso/$release/hyperbola-bootstrap-i686.tar.gz"
+ wget -P "$script_dir" "https://archive.fridu.us/hyperbola/iso/$release/hyperbola-bootstrap-x86_64.tar.gz"
+
+ echo "Files downloaded successfully for version $release."
+else
+ echo "Files already exist in the current directory. No download is required."
+fi
+
+# Logout docker
+docker logout > /dev/null 2>&1
+
+# Prompt user for credentials
+if [[ -z "$DOCKER_USERNAME" ]]; then
+ read -p "Enter your Docker Hub username: " DOCKER_USERNAME
+fi
+
+if [[ -z "$DOCKER_PASSWORD" ]]; then
+ read -sp "Enter your Docker Hub password: " DOCKER_PASSWORD
+ echo
+fi
+
+# Log in to Docker Hub
+echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
+
+# Build the images
+docker build --no-cache --platform=linux/amd64 --tag "$DOCKER_USERNAME/hyperbola:$tag-amd64" -f Dockerfile.amd64 .
+docker build --no-cache --platform=linux/386 --tag "$DOCKER_USERNAME/hyperbola:$tag-386" -f Dockerfile.386 .
+
+# Push the images to Docker Hub
+docker push "$DOCKER_USERNAME/hyperbola:$tag-amd64"
+docker push "$DOCKER_USERNAME/hyperbola:$tag-386"
+
+# Create and push the manifest for the specified tag
+docker manifest create "$DOCKER_USERNAME/hyperbola:$tag" \
+ --amend "$DOCKER_USERNAME/hyperbola:$tag-amd64" \
+ --amend "$DOCKER_USERNAME/hyperbola:$tag-386"
+
+docker manifest push "$DOCKER_USERNAME/hyperbola:$tag"
+
+# Create and push the manifest for "latest"
+docker manifest create "$DOCKER_USERNAME/hyperbola:$latest_tag" \
+ --amend "$DOCKER_USERNAME/hyperbola:$tag-amd64" \
+ --amend "$DOCKER_USERNAME/hyperbola:$tag-386"
+
+docker manifest push "$DOCKER_USERNAME/hyperbola:$latest_tag"
+
+# Get the token
+token=$(curl -s -H 'Content-Type: application/json' -X POST -H 'Content-Type: application/json' -d "{\"username\":\"$DOCKER_USERNAME\", \"password\":\"$DOCKER_PASSWORD\"}" "https://hub.docker.com/v2/users/login/" | jq -r .token)
+
+# Function to perform a curl with retries
+function curl_with_retry() {
+ local url="$1"
+ local retries=3 # Number of retries
+ local delay=5 # Delay between retries in seconds
+
+ for ((i = 0; i < retries; i++)); do
+ response=$(curl -s -X DELETE -H "Authorization: JWT $token" "$url")
+ if [ $? -eq 0 ]; then
+ echo "$response"
+ return 0
+ else
+ echo "Attempt $((i+1)) failed. Retrying in $delay seconds..."
+ sleep $delay
+ fi
+ done
+
+ echo "All attempts failed. Curl command with URL '$url' has failed."
+ return 1
+}
+
+# Delete tags on Docker Hub
+if curl_with_retry "https://hub.docker.com/v2/repositories/$DOCKER_USERNAME/hyperbola/tags/$tag-amd64/"; then
+ echo "Tag $tag-amd64 deleted successfully."
+else
+ echo "Failed to delete tag $tag-amd64."
+fi
+
+if curl_with_retry "https://hub.docker.com/v2/repositories/$DOCKER_USERNAME/hyperbola/tags/$tag-386/"; then
+ echo "Tag $tag-386 deleted successfully."
+else
+ echo "Failed to delete tag $tag-386."
+fi