Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
feat: setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
tomanagle committed Aug 28, 2023
1 parent ecd3f01 commit 8a97f32
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
## Getting started
1. Clone the repo
1. Run `go mod tidy`
1. Fine and replace `github.com/tomdoestech/goth` with your own module name
1. Create a .env file for local development with a base64 encoded `JWT_PRIVATE_KEY` and a base64 encoded `JWT_PUBLIC_KEY`
1. Find and replace `github.com/tomdoestech/goth` with your own module name
1. Download `Air` - https://github.com/cosmtrek/air
1. Run `air` to start the dev server

The `JWT_PRIVATE_KEY` and `JWT_PUBLIC_KEY` are base64 encoded to eliminate issues with formatting the keys. You can use keys that aren't base64 encoded by updating `internal/config/config.go` and removing the decode functionality.

## Contributing
Contributions are welcome. Please open an issue to discuss your idea before opening a PR unless it's a fix for a bug or a typo.

Expand Down
43 changes: 43 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash


generateKeys(){
# Generate private key
openssl genpkey -algorithm RSA -out private_key.pem

# Extract public key from private key and base64 encode
openssl rsa -pubout -in private_key.pem | base64 -w 0 > public_key.base64

# Base64 encode private key
base64 -w 0 private_key.pem > private_key.base64

# Create .env file and store encoded keys
echo "JWT_PRIVATE_KEY=$(cat public_key.base64)" > .env
echo "" >> .env
echo "JWT_PUBLIC_KEY=$(cat private_key.base64)" >> .env

# Clean up temporary files
rm public_key.base64 private_key.base64 private_key.pem

echo "generated keys"
}

generateKeys


replace_module_name() {
echo "Enter your module name (e.g., github.com/yourusername/yourmodule):"
read new_module_name

if [[ -z "$new_module_name" ]]; then
echo "Module name cannot be empty."
exit 1
fi

# Replace old module name with the new one in all files
find . -type f -exec sed -i "s/github\.com\/tomdoestech\/goth/$new_module_name/g" {} +

echo "Module name replaced in all files."
}

replace_module_name

0 comments on commit 8a97f32

Please sign in to comment.