From 1b5d9a6d989202cce85c9986e7985aeeb56f0bb1 Mon Sep 17 00:00:00 2001 From: SapphireGaze Date: Wed, 13 Nov 2024 22:34:15 -0800 Subject: [PATCH] Added Makefile & Scripts: - Added makefile - Added install and uninstall scripts --- .gitignore | 3 ++- go.mod | 7 ++++-- go.sum | 17 +++++++++++++ install.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 8 ++++++ uninstall.sh | 33 +++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 3 deletions(-) create mode 100755 install.sh create mode 100644 makefile create mode 100755 uninstall.sh diff --git a/.gitignore b/.gitignore index 13470b7..0e30f44 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .DS_Store .vscode -config.yaml \ No newline at end of file +config.yaml +discord-gorp \ No newline at end of file diff --git a/go.mod b/go.mod index 5e2b475..3e30465 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,13 @@ module github.com/sapphiregaze/discord-gorp go 1.22.7 +require ( + github.com/gorilla/websocket v1.5.3 + github.com/spf13/viper v1.19.0 +) + require ( github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/gorilla/websocket v1.5.3 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect @@ -15,7 +19,6 @@ require ( github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect diff --git a/go.sum b/go.sum index 961c8bc..4f80d2c 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,21 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -13,6 +23,10 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= @@ -35,6 +49,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= @@ -49,6 +64,8 @@ golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8338ab6 --- /dev/null +++ b/install.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Variables +BINARY_NAME="discord-gorp" +BINARY_PATH="$HOME/.local/bin/$BINARY_NAME" +SERVICE_NAME="discord-gorp.service" +SERVICE_PATH="$HOME/.config/systemd/user/$SERVICE_NAME" + +# Check if `make` is installed +if ! command -v make &> /dev/null; then + echo "Error: 'make' is not installed. Please install it and try again." + exit 1 +fi + +# Check if `go` is installed +if ! command -v go &> /dev/null; then + echo "Error: 'go' is not installed. Please install it and try again." + exit 1 +fi + +# Build the binary +echo "Building binary with make..." +if ! make; then + echo "Error: Failed to build the binary." + exit 1 +fi + +# Ensure ~/.local/bin exists and is in PATH +mkdir -p "$HOME/.local/bin" +export PATH="$HOME/.local/bin:$PATH" + +# Check if the binary file exists in the current directory +if [ ! -f "./$BINARY_NAME" ]; then + echo "Error: $BINARY_NAME binary not found in the current directory." + exit 1 +fi + +# Copy the binary to ~/.local/bin +cp "./$BINARY_NAME" "$BINARY_PATH" +chmod +x "$BINARY_PATH" +echo "Copied $BINARY_NAME to $BINARY_PATH" + +# Ensure systemd user directory exists +mkdir -p "$(dirname "$SERVICE_PATH")" + +# Create the systemd service file +cat < "$SERVICE_PATH" +[Unit] +Description=Discord Gorp Service +After=network.target + +[Service] +ExecStart=$BINARY_PATH +Restart=on-failure + +[Install] +WantedBy=default.target +EOF + +echo "Created systemd service file at $SERVICE_PATH" + +# Reload systemd user daemon to register the new service +systemctl --user daemon-reload + +# Enable and start the service +systemctl --user enable --now "$SERVICE_NAME" + +echo "Service $SERVICE_NAME has been installed and started." +echo "You can check the status with: systemctl --user status $SERVICE_NAME" diff --git a/makefile b/makefile new file mode 100644 index 0000000..705ca8b --- /dev/null +++ b/makefile @@ -0,0 +1,8 @@ +discord-gorp: + @go build ./cmd/discord-gorp/ +run: + @go run ./cmd/discord-gorp/ +test: + @go test ./... +clean: + @rm ./discord-gorp \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..bad5e22 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Variables +BINARY_NAME="discord-gorp" +BINARY_PATH="$HOME/.local/bin/$BINARY_NAME" +SERVICE_NAME="discord-gorp.service" +SERVICE_PATH="$HOME/.config/systemd/user/$SERVICE_NAME" + +# Stop and disable the systemd service if it is running +echo "Stopping and disabling the $SERVICE_NAME service..." +systemctl --user stop "$SERVICE_NAME" 2>/dev/null +systemctl --user disable "$SERVICE_NAME" 2>/dev/null + +# Remove the systemd service file +if [ -f "$SERVICE_PATH" ]; then + echo "Removing the systemd service file at $SERVICE_PATH..." + rm "$SERVICE_PATH" +else + echo "No systemd service file found at $SERVICE_PATH." +fi + +# Reload systemd daemon to remove the service reference +systemctl --user daemon-reload + +# Remove the binary from ~/.local/bin +if [ -f "$BINARY_PATH" ]; then + echo "Removing the binary at $BINARY_PATH..." + rm "$BINARY_PATH" +else + echo "No binary found at $BINARY_PATH." +fi + +echo "Uninstallation complete."