diff --git a/docs/binary.md b/docs/binary.md index 68fcd89..b6c44e8 100644 --- a/docs/binary.md +++ b/docs/binary.md @@ -2,7 +2,7 @@ ## Setup -1. Install `make` and `wget` if not already +1. Install `bash`, `make` and `wget` if not already 2. Run setup script @@ -19,12 +19,6 @@ export SETUP_CODEMIRROR=0 ``` - Setup: - - ```shell - wget -qO- https://6uo.me/go-proxy-setup-binary | sudo bash - ``` - What it does: - Download source file and binary into /opt/go-proxy/$VERSION diff --git a/setup-binary.sh b/setup-binary.sh index 305eded..d01a146 100644 --- a/setup-binary.sh +++ b/setup-binary.sh @@ -1,9 +1,10 @@ -#!/bin/sh +#!/bin/bash set -e REPO_URL=https://github.com/yusing/go-proxy BIN_URL="${REPO_URL}/releases/download/${VERSION}/go-proxy" SRC_URL="${REPO_URL}/archive/refs/tags/${VERSION}.tar.gz" APP_ROOT="/opt/go-proxy/${VERSION}" +LOG_FILE="/tmp/go-proxy-setup.log" if [ -z "$VERSION" ] || [ "$VERSION" = "latest" ]; then VERSION_URL="${REPO_URL}/raw/main/version.txt" @@ -30,28 +31,28 @@ fi dl_source() { cd /tmp echo "Downloading go-proxy source ${VERSION}" - wget -c "${SRC_URL}" -O go-proxy.tar.gz 2>&1 - echo "Done" + wget -c "${SRC_URL}" -O go-proxy.tar.gz &> $LOG_FILE if [ $? -gt 0 ]; then echo "Source download failed, check your internet connection and version number" exit 1 fi + echo "Done" echo "Extracting go-proxy source ${VERSION}" - tar xzf go-proxy.tar.gz 2>&1 + tar xzf go-proxy.tar.gz &> $LOG_FILE if [ $? -gt 0 ]; then echo "failed to untar go-proxy.tar.gz" exit 1 fi rm go-proxy.tar.gz - mkdir -p $(dirname $APP_ROOT) - mv "go-proxy-${VERSION}" $APP_ROOT - cd $APP_ROOT + mkdir -p "$(dirname "${APP_ROOT}")" + mv "go-proxy-${VERSION}" "$APP_ROOT" + cd "$APP_ROOT" echo "Done" } dl_binary() { mkdir -p bin echo "Downloading go-proxy binary ${VERSION}" - wget -c "${BIN_URL}" -O bin/go-proxy 2>&1 + wget -c "${BIN_URL}" -O bin/go-proxy &> $LOG_FILE if [ $? -gt 0 ]; then echo "Binary download failed, check your internet connection and version number" exit 1 @@ -60,14 +61,14 @@ dl_binary() { echo "Done" } setup() { - make setup + make setup &> $LOG_FILE if [ $? -gt 0 ]; then echo "make setup failed" exit 1 fi # SETUP_CODEMIRROR = 1 if [ "$SETUP_CODEMIRROR" != "0" ]; then - make setup-codemirror || echo "make setup-codemirror failed, ignored" + make setup-codemirror &> $LOG_FILE || echo "make setup-codemirror failed, ignored" fi } @@ -82,12 +83,12 @@ if ! command -v systemctl is-system-running > /dev/null 2>&1; then echo "systemctl not found, skipping systemd setup" exit 0 fi -systemctl-failed() { +systemctl_failed() { echo "Failed to enable and start go-proxy" systemctl status go-proxy exit 1 } -mkdir -p /etc/systemd/system +echo "Setting up systemd service" cat < /etc/systemd/system/go-proxy.service [Unit] Description=go-proxy reverse proxy @@ -107,6 +108,7 @@ TimeoutStopSec=5s [Install] WantedBy=multi-user.target EOF -systemctl daemon-reload || systemctl-failed -systemctl enable --now go-proxy || systemctl-failed +systemctl daemon-reload &>$LOG_FILE || systemctl_failed +systemctl enable --now go-proxy &>$LOG_FILE || systemctl_failed +echo "Done" echo "Setup complete" \ No newline at end of file