|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Script to edit cask files with specified parameters |
| 5 | +# Usage: edit-cask.sh --cask <cask_name> --binary <binary_path> [--tap <tap_name>] <TAG> |
| 6 | + |
| 7 | +# Initialize variables |
| 8 | +CASK_NAME="" |
| 9 | +BINARY_PATH="" |
| 10 | +TAG="" |
| 11 | +TAP="redis/redis" |
| 12 | + |
| 13 | +# Function to display usage |
| 14 | +usage() { |
| 15 | + echo "Usage: $0 --cask <cask_name> --binary <binary_path> [--tap <tap_name>] <TAG>" |
| 16 | + echo "" |
| 17 | + echo "Arguments:" |
| 18 | + echo " --cask <cask_name> Name of the cask to edit (e.g., redis, redis-rc)" |
| 19 | + echo " --binary <binary_path> Path to the binary package" |
| 20 | + echo " --tap <tap_name> Optional. Homebrew tap name (default: redis/redis)" |
| 21 | + echo " <TAG> Version tag (positional argument)" |
| 22 | + echo "" |
| 23 | + echo "Examples:" |
| 24 | + echo " $0 --cask redis --binary redis-ce-8.2.3-arm64.zip 8.2.3" |
| 25 | + echo " $0 --cask redis --binary redis-ce-8.2.3-arm64.zip --tap redis/redis 8.2.3" |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +edit_cask_file(){ |
| 30 | + tag=$1 |
| 31 | + binary_path=$2 |
| 32 | + tap=$3 |
| 33 | + cask_name=$4 |
| 34 | + |
| 35 | + casks_path="$(brew --repository $tap)/Casks/${cask_name}.rb" |
| 36 | + |
| 37 | + # Change version |
| 38 | + sed -i '' "s/version \"[^\"]*\"/version \"$tag\"/" $casks_path |
| 39 | + # change url to file:// |
| 40 | + sed -i '' "s|url \".*\"|url \"file://$binary_path\"|" $casks_path |
| 41 | + # Remove sha256 verification since it's local testing |
| 42 | + sed -i '' '/sha256 arm:/,/intel:.*"$/d' $casks_path |
| 43 | + #temporary remove conflicts_with |
| 44 | + sed -i '' '/conflicts_with/d' $casks_path |
| 45 | + |
| 46 | +} |
| 47 | + |
| 48 | +# Parse command line arguments |
| 49 | +while [[ $# -gt 0 ]]; do |
| 50 | + case $1 in |
| 51 | + --cask) |
| 52 | + CASK_NAME="$2" |
| 53 | + shift 2 |
| 54 | + ;; |
| 55 | + --binary) |
| 56 | + BINARY_PATH="$2" |
| 57 | + shift 2 |
| 58 | + ;; |
| 59 | + --tap) |
| 60 | + TAP="$2" |
| 61 | + shift 2 |
| 62 | + ;; |
| 63 | + -h|--help) |
| 64 | + usage |
| 65 | + ;; |
| 66 | + -*) |
| 67 | + echo "Error: Unknown option: $1" |
| 68 | + usage |
| 69 | + ;; |
| 70 | + *) |
| 71 | + # Positional argument - assume it's the TAG |
| 72 | + if [ -z "$TAG" ]; then |
| 73 | + TAG="$1" |
| 74 | + else |
| 75 | + echo "Error: Unexpected argument: $1" |
| 76 | + usage |
| 77 | + fi |
| 78 | + shift |
| 79 | + ;; |
| 80 | + esac |
| 81 | +done |
| 82 | + |
| 83 | +# Validate required arguments |
| 84 | +if [ -z "$CASK_NAME" ]; then |
| 85 | + echo "Error: --cask argument is required" |
| 86 | + usage |
| 87 | +fi |
| 88 | + |
| 89 | +if [ -z "$BINARY_PATH" ]; then |
| 90 | + echo "Error: --binary argument is required" |
| 91 | + usage |
| 92 | +fi |
| 93 | + |
| 94 | +if [ -z "$TAG" ]; then |
| 95 | + echo "Error: TAG argument is required" |
| 96 | + usage |
| 97 | +fi |
| 98 | + |
| 99 | +edit_cask_file $TAG $BINARY_PATH $TAP $CASK_NAME |
| 100 | + |
| 101 | +echo "Cask editing completed successfully" |
0 commit comments