Skip to content

Commit

Permalink
feat: add mac support for hacky script (#1)
Browse files Browse the repository at this point in the history
Signed-off-by: Zoran Zorica <[email protected]>
  • Loading branch information
zzorica authored Mar 27, 2024
1 parent f1a6cb2 commit bea79a9
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions hack/replace-name.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
#!/bin/bash

# Check for macOS using system information
if [[ $(uname -s) == "Darwin" ]]; then
SED_CMD="gsed"
if ! command -v gsed &>/dev/null; then
echo "gsed is not installed. It is required for this script to function properly."
echo "Would you like to install gsed using Homebrew? (y/N)"
read -r response

if [[ $response =~ ^([Yy])$ ]]; then
# Install gsed with Homebrew (if available)
if command -v brew &>/dev/null; then
brew install gsed
else
echo "Homebrew is not installed. Please install gsed manually or another package manager."
fi
exit 1
else
echo "Exiting script as gsed is required."
exit 1
fi
fi
echo "gsed is installed. Proceeding..."
else
SED_CMD="sed"
fi

# Print and get input for repository name
echo -n "URL of your repository (without https://): "
read repositoryUrl
read -r repositoryUrl

# Print and get input for provider name
echo -n "Name of the provider (e.g. Docker Provider): "
read providerName
read -r providerName

# Replace ocurrences of github.com/daytonaio/daytona-provider-sample with the repository name
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec sed -i "s|github.com/daytonaio/daytona-provider-sample|$repositoryUrl|g" {} +
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec $SED_CMD -i "s|github.com/daytonaio/daytona-provider-sample|$repositoryUrl|g" {} +
echo "Replaced github.com/daytonaio/daytona-provider-sample with $repositoryUrl"

# Replace occurrences of "provider-sample" with formatted provider name
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec sed -i "s/provider-sample/$(echo "$providerName" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')/g" {} +
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec $SED_CMD -i "s/provider-sample/$(echo "$providerName" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')/g" {} +
echo "Replaced provider-sample with $(echo "$providerName" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')"

# Replace ocurrences of "SampleProvider" with the provider name
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec sed -i "s/SampleProvider/$(echo "$providerName" | tr -d ' ')/g" {} +
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec $SED_CMD -i "s/SampleProvider/$(echo "$providerName" | tr -d ' ')/g" {} +
echo "Replaced SampleProvider with $(echo "$providerName" | tr -d ' ')"

# Replace occurrences of "Provider Sample" with the provider name
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec sed -i "s/Provider Sample/$providerName/g" {} +
echo "Replaced Provider Sample with $providerName"
find . -type d \( -name "hack" -o -name ".git" \) -prune -o -type f -exec $SED_CMD -i "s/Provider Sample/$providerName/g" {} +
echo "Replaced Provider Sample with $providerName"

0 comments on commit bea79a9

Please sign in to comment.