Skip to content

Instantly share code, notes, and snippets.

@vzool
Last active September 22, 2020 07:57
Show Gist options
  • Select an option

  • Save vzool/cbdd59ded81a231c76659ebca3c67fab to your computer and use it in GitHub Desktop.

Select an option

Save vzool/cbdd59ded81a231c76659ebca3c67fab to your computer and use it in GitHub Desktop.
Bash script to build all commands wanted inside Go project work with modules
#!/bin/bash
# Store current Workingspace
CurrentDir="$(pwd)"
# Tools list
ARRAY=(
# Command:URL(without https://)
"gen:github.com/clipperhouse/gen"
)
for tool in "${ARRAY[@]}" ; do
Command=${tool%%:*}
URL=${tool#*:}
# Variable to count good steps
goodSteps=1
echo "Creating $Command tool..."
# Remove tool folder
rm -rf "/tmp/$Command" && ((goodSteps=goodSteps+1))
# Clone
git clone "https://$URL" "/tmp/$Command" && ((goodSteps=goodSteps+1))
# Move to tool source code
cd "/tmp/$Command" && ((goodSteps=goodSteps+1))
# Build the tool
go build && ((goodSteps=goodSteps+1))
# Go back to Workingspace
cd $CurrentDir && ((goodSteps=goodSteps+1))
# Copy the tool inside Workingspace
cp "/tmp/$Command/$Command" . && ((goodSteps=goodSteps+1))
# Remove temporary folder
rm -rf "/tmp/$Command" && ((goodSteps=goodSteps+1))
# Make tool executable
chmod +x "$Command" && ((goodSteps=goodSteps+1))
# Create git ignore files if not exists
touch .gitignore && ((goodSteps=goodSteps+1))
# Ignore tool from git history
grep -qxF "$Command" .gitignore || echo "$Command" >> .gitignore && ((goodSteps=goodSteps+1))
# Add this update to the history if updated
git add .gitignore && ((goodSteps=goodSteps+1))
echo "------------------------------------------"
if [[ "$goodSteps" == 12 ]]; then
echo "$Command tool build - [OK]".
else
echo "$Command tool build .. FIALED .."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment