2021-08-28 20:36:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-08-29 23:11:41 +00:00
|
|
|
set -eo pipefail
|
2021-08-28 20:36:52 +00:00
|
|
|
|
2021-08-29 23:11:41 +00:00
|
|
|
branch=$1
|
|
|
|
if [ -z "$branch" ]; then
|
|
|
|
echo "Type the name of the branch you would like to deploy: "
|
|
|
|
read branch
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Deploying branch $branch..."
|
|
|
|
|
|
|
|
do_as() {
|
|
|
|
sudo -u $1 --preserve-env=PATH bash -s
|
|
|
|
}
|
2021-08-28 20:36:52 +00:00
|
|
|
|
2021-08-29 23:11:41 +00:00
|
|
|
do_as hmn <<SCRIPT
|
2021-08-28 20:36:52 +00:00
|
|
|
set -euo pipefail
|
2021-08-29 23:11:41 +00:00
|
|
|
cd /home/hmn/hmn
|
|
|
|
git fetch --all
|
|
|
|
git reset --hard origin/$branch
|
|
|
|
go build -o /home/hmn/bin/hmn src/main.go
|
2021-08-28 20:36:52 +00:00
|
|
|
SCRIPT
|
|
|
|
|
2021-08-29 23:11:41 +00:00
|
|
|
echo "Running migrations..."
|
2021-08-29 20:20:29 +00:00
|
|
|
systemctl stop hmn
|
2021-08-29 23:11:41 +00:00
|
|
|
do_as hmn <<'SCRIPT'
|
2021-08-28 20:36:52 +00:00
|
|
|
set -euo pipefail
|
2021-08-29 20:20:29 +00:00
|
|
|
/home/hmn/bin/hmn migrate
|
2021-08-28 20:36:52 +00:00
|
|
|
SCRIPT
|
2021-08-29 20:20:29 +00:00
|
|
|
systemctl start hmn
|