mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +02:00
update default repo to main
This commit is contained in:
parent
2504510c61
commit
281523ee06
3 changed files with 120 additions and 120 deletions
|
@ -73,7 +73,7 @@ Setup DNS Records point to machine which runs `GoDoxy`, e.g.
|
||||||
2. Run setup script inside the directory, or [set up manually](#manual-setup)
|
2. Run setup script inside the directory, or [set up manually](#manual-setup)
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/yusing/go-proxy/v0.9/scripts/setup.sh)"
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/yusing/go-proxy/main/scripts/setup.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Start the container `docker compose up -d` and wait for it to be ready
|
3. Start the container `docker compose up -d` and wait for it to be ready
|
||||||
|
@ -86,15 +86,15 @@ Setup DNS Records point to machine which runs `GoDoxy`, e.g.
|
||||||
|
|
||||||
1. Make `config` directory then grab `config.example.yml` into `config/config.yml`
|
1. Make `config` directory then grab `config.example.yml` into `config/config.yml`
|
||||||
|
|
||||||
`mkdir -p config && wget https://raw.githubusercontent.com/yusing/go-proxy/v0.9/config.example.yml -O config/config.yml`
|
`mkdir -p config && wget https://raw.githubusercontent.com/yusing/go-proxy/main/config.example.yml -O config/config.yml`
|
||||||
|
|
||||||
2. Grab `.env.example` into `.env`
|
2. Grab `.env.example` into `.env`
|
||||||
|
|
||||||
`wget https://raw.githubusercontent.com/yusing/go-proxy/v0.9/.env.example -O .env`
|
`wget https://raw.githubusercontent.com/yusing/go-proxy/main/.env.example -O .env`
|
||||||
|
|
||||||
3. Grab `compose.example.yml` into `compose.yml`
|
3. Grab `compose.example.yml` into `compose.yml`
|
||||||
|
|
||||||
`wget https://raw.githubusercontent.com/yusing/go-proxy/v0.9/compose.example.yml -O compose.yml`
|
`wget https://raw.githubusercontent.com/yusing/go-proxy/main/compose.example.yml -O compose.yml`
|
||||||
|
|
||||||
### Folder structrue
|
### Folder structrue
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
2. 在目錄內運行安裝腳本,或[手動安裝](#手動安裝)
|
2. 在目錄內運行安裝腳本,或[手動安裝](#手動安裝)
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/yusing/go-proxy/v0.9/scripts/setup.sh)"
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/yusing/go-proxy/main/scripts/setup.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 啟動容器 `docker compose up -d` 並等待就緒
|
3. 啟動容器 `docker compose up -d` 並等待就緒
|
||||||
|
@ -86,15 +86,15 @@
|
||||||
|
|
||||||
1. 建立 `config` 目錄,然後將 `config.example.yml` 下載到 `config/config.yml`
|
1. 建立 `config` 目錄,然後將 `config.example.yml` 下載到 `config/config.yml`
|
||||||
|
|
||||||
`mkdir -p config && wget https://raw.githubusercontent.com/yusing/go-proxy/v0.9/config.example.yml -O config/config.yml`
|
`mkdir -p config && wget https://raw.githubusercontent.com/yusing/go-proxy/main/config.example.yml -O config/config.yml`
|
||||||
|
|
||||||
2. 將 `.env.example` 下載到 `.env`
|
2. 將 `.env.example` 下載到 `.env`
|
||||||
|
|
||||||
`wget https://raw.githubusercontent.com/yusing/go-proxy/v0.9/.env.example -O .env`
|
`wget https://raw.githubusercontent.com/yusing/go-proxy/main/.env.example -O .env`
|
||||||
|
|
||||||
3. 將 `compose.example.yml` 下載到 `compose.yml`
|
3. 將 `compose.example.yml` 下載到 `compose.yml`
|
||||||
|
|
||||||
`wget https://raw.githubusercontent.com/yusing/go-proxy/v0.9/compose.example.yml -O compose.yml`
|
`wget https://raw.githubusercontent.com/yusing/go-proxy/main/compose.example.yml -O compose.yml`
|
||||||
|
|
||||||
### 資料夾結構
|
### 資料夾結構
|
||||||
|
|
||||||
|
|
224
scripts/setup.sh
224
scripts/setup.sh
|
@ -1,46 +1,46 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e # Exit on error
|
set -e # Exit on error
|
||||||
|
|
||||||
# Detect download tool
|
# Detect download tool
|
||||||
if command -v curl >/dev/null 2>&1; then
|
if command -v curl >/dev/null 2>&1; then
|
||||||
DOWNLOAD_TOOL="curl"
|
DOWNLOAD_TOOL="curl"
|
||||||
DOWNLOAD_CMD="curl -fsSL -o"
|
DOWNLOAD_CMD="curl -fsSL -o"
|
||||||
elif command -v wget >/dev/null 2>&1; then
|
elif command -v wget >/dev/null 2>&1; then
|
||||||
DOWNLOAD_TOOL="wget"
|
DOWNLOAD_TOOL="wget"
|
||||||
DOWNLOAD_CMD="wget -qO"
|
DOWNLOAD_CMD="wget -qO"
|
||||||
else
|
else
|
||||||
read -p "Neither curl nor wget is installed, install curl? (y/n): " INSTALL
|
read -p "Neither curl nor wget is installed, install curl? (y/n): " INSTALL
|
||||||
if [ "$INSTALL" == "y" ]; then
|
if [ "$INSTALL" == "y" ]; then
|
||||||
install_pkg "curl"
|
install_pkg "curl"
|
||||||
else
|
else
|
||||||
echo "Error: Neither curl nor wget is installed. Please install one of them and try again."
|
echo "Error: Neither curl nor wget is installed. Please install one of them and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Using ${DOWNLOAD_TOOL} for downloads"
|
echo "Using ${DOWNLOAD_TOOL} for downloads"
|
||||||
|
|
||||||
get_default_branch() {
|
# get_default_branch() {
|
||||||
local repo="$1" # Format: owner/repo
|
# local repo="$1" # Format: owner/repo
|
||||||
local branch
|
# local branch
|
||||||
|
|
||||||
if [ "$DOWNLOAD_TOOL" = "curl" ]; then
|
# if [ "$DOWNLOAD_TOOL" = "curl" ]; then
|
||||||
branch=$(curl -sL "https://api.github.com/repos/${repo}" | grep -o '"default_branch": *"[^"]*"' | cut -d'"' -f4)
|
# branch=$(curl -sL "https://api.github.com/repos/${repo}" | grep -o '"default_branch": *"[^"]*"' | cut -d'"' -f4)
|
||||||
elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
|
# elif [ "$DOWNLOAD_TOOL" = "wget" ]; then
|
||||||
branch=$(wget -qO- "https://api.github.com/repos/${repo}" | grep -o '"default_branch": *"[^"]*"' | cut -d'"' -f4)
|
# branch=$(wget -qO- "https://api.github.com/repos/${repo}" | grep -o '"default_branch": *"[^"]*"' | cut -d'"' -f4)
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
if [ -z "$branch" ]; then
|
# if [ -z "$branch" ]; then
|
||||||
echo "main" # Fallback to 'main' if detection fails
|
# echo "main" # Fallback to 'main' if detection fails
|
||||||
else
|
# else
|
||||||
echo "$branch"
|
# echo "$branch"
|
||||||
fi
|
# fi
|
||||||
}
|
# }
|
||||||
|
|
||||||
# Environment variables with defaults
|
# Environment variables with defaults
|
||||||
REPO="yusing/go-proxy"
|
REPO="yusing/go-proxy"
|
||||||
BRANCH=${BRANCH:-$(get_default_branch "$REPO")}
|
BRANCH=${BRANCH:-"main"}
|
||||||
REPO_URL="https://github.com/$REPO"
|
REPO_URL="https://github.com/$REPO"
|
||||||
WIKI_URL="${REPO_URL}/wiki"
|
WIKI_URL="${REPO_URL}/wiki"
|
||||||
BASE_URL="${REPO_URL}/raw/${BRANCH}"
|
BASE_URL="${REPO_URL}/raw/${BRANCH}"
|
||||||
|
@ -58,96 +58,96 @@ echo "Setting up GoDoxy"
|
||||||
echo "Branch: ${BRANCH}"
|
echo "Branch: ${BRANCH}"
|
||||||
|
|
||||||
install_pkg() {
|
install_pkg() {
|
||||||
# detect package manager
|
# detect package manager
|
||||||
if command -v apt >/dev/null 2>&1; then
|
if command -v apt >/dev/null 2>&1; then
|
||||||
apt install -y "$1"
|
apt install -y "$1"
|
||||||
elif command -v yum >/dev/null 2>&1; then
|
elif command -v yum >/dev/null 2>&1; then
|
||||||
yum install -y "$1"
|
yum install -y "$1"
|
||||||
elif command -v pacman >/dev/null 2>&1; then
|
elif command -v pacman >/dev/null 2>&1; then
|
||||||
pacman -S --noconfirm "$1"
|
pacman -S --noconfirm "$1"
|
||||||
else
|
else
|
||||||
echo "Error: No supported package manager found"
|
echo "Error: No supported package manager found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_pkg() {
|
check_pkg() {
|
||||||
local cmd="$1"
|
local cmd="$1"
|
||||||
local pkg="$2"
|
local pkg="$2"
|
||||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||||
# check if user is root
|
# check if user is root
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Error: $pkg is not installed and you are not running as root. Please install it and try again."
|
echo "Error: $pkg is not installed and you are not running as root. Please install it and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
read -p "$pkg is not installed, install it? (y/n): " INSTALL
|
read -p "$pkg is not installed, install it? (y/n): " INSTALL
|
||||||
if [ "$INSTALL" == "y" ]; then
|
if [ "$INSTALL" == "y" ]; then
|
||||||
install_pkg "$pkg"
|
install_pkg "$pkg"
|
||||||
else
|
else
|
||||||
echo "Error: $pkg is not installed. Please install it and try again."
|
echo "Error: $pkg is not installed. Please install it and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to check if file/directory exists
|
# Function to check if file/directory exists
|
||||||
has_file_or_dir() {
|
has_file_or_dir() {
|
||||||
[ -e "$1" ]
|
[ -e "$1" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to create directory
|
# Function to create directory
|
||||||
mkdir_if_not_exists() {
|
mkdir_if_not_exists() {
|
||||||
if [ ! -d "$1" ]; then
|
if [ ! -d "$1" ]; then
|
||||||
echo "Creating directory \"$1\""
|
echo "Creating directory \"$1\""
|
||||||
mkdir -p "$1"
|
mkdir -p "$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to create empty file
|
# Function to create empty file
|
||||||
touch_if_not_exists() {
|
touch_if_not_exists() {
|
||||||
if [ ! -f "$1" ]; then
|
if [ ! -f "$1" ]; then
|
||||||
echo "Creating file \"$1\""
|
echo "Creating file \"$1\""
|
||||||
touch "$1"
|
touch "$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to download file
|
# Function to download file
|
||||||
fetch_file() {
|
fetch_file() {
|
||||||
local remote_file="$1"
|
local remote_file="$1"
|
||||||
local out_file="$2"
|
local out_file="$2"
|
||||||
|
|
||||||
if has_file_or_dir "$out_file"; then
|
if has_file_or_dir "$out_file"; then
|
||||||
if [ "$remote_file" = "$out_file" ]; then
|
if [ "$remote_file" = "$out_file" ]; then
|
||||||
echo "\"$out_file\" already exists, not overwriting"
|
echo "\"$out_file\" already exists, not overwriting"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
read -p "Do you want to overwrite \"$out_file\"? (y/n): " OVERWRITE
|
read -p "Do you want to overwrite \"$out_file\"? (y/n): " OVERWRITE
|
||||||
if [ "$OVERWRITE" != "y" ]; then
|
if [ "$OVERWRITE" != "y" ]; then
|
||||||
echo "Skipping \"$remote_file\""
|
echo "Skipping \"$remote_file\""
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Downloading \"$remote_file\" to \"$out_file\""
|
echo "Downloading \"$remote_file\" to \"$out_file\""
|
||||||
if ! $DOWNLOAD_CMD "$out_file" "${BASE_URL}/${remote_file}"; then
|
if ! $DOWNLOAD_CMD "$out_file" "${BASE_URL}/${remote_file}"; then
|
||||||
echo "Error: Failed to download ${remote_file}"
|
echo "Error: Failed to download ${remote_file}"
|
||||||
rm -f "$out_file" # Clean up partial download
|
rm -f "$out_file" # Clean up partial download
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Done"
|
echo "Done"
|
||||||
}
|
}
|
||||||
|
|
||||||
ask_while_empty() {
|
ask_while_empty() {
|
||||||
local prompt="$1"
|
local prompt="$1"
|
||||||
local var_name="$2"
|
local var_name="$2"
|
||||||
local value=""
|
local value=""
|
||||||
while [ -z "$value" ]; do
|
while [ -z "$value" ]; do
|
||||||
read -p "$prompt" value
|
read -p "$prompt" value
|
||||||
if [ -z "$value" ]; then
|
if [ -z "$value" ]; then
|
||||||
echo "Error: $var_name cannot be empty, please try again"
|
echo "Error: $var_name cannot be empty, please try again"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
eval "$var_name=\"$value\""
|
eval "$var_name=\"$value\""
|
||||||
}
|
}
|
||||||
|
|
||||||
check_pkg "openssl" "openssl"
|
check_pkg "openssl" "openssl"
|
||||||
|
@ -187,20 +187,20 @@ ask_while_empty "Do you want to enable autocert? (y/n): " ENABLE_AUTOCERT
|
||||||
|
|
||||||
# quit if not using autocert
|
# quit if not using autocert
|
||||||
if [ "$ENABLE_AUTOCERT" == "y" ]; then
|
if [ "$ENABLE_AUTOCERT" == "y" ]; then
|
||||||
# ask for domain
|
# ask for domain
|
||||||
echo "Setting up autocert"
|
echo "Setting up autocert"
|
||||||
ask_while_empty "Enter domain (e.g. example.com): " DOMAIN
|
ask_while_empty "Enter domain (e.g. example.com): " DOMAIN
|
||||||
|
|
||||||
# ask for email
|
# ask for email
|
||||||
ask_while_empty "Enter email for Let's Encrypt: " EMAIL
|
ask_while_empty "Enter email for Let's Encrypt: " EMAIL
|
||||||
|
|
||||||
# ask if using cloudflare
|
# ask if using cloudflare
|
||||||
ask_while_empty "Are you using cloudflare? (y/n): " USE_CLOUDFLARE
|
ask_while_empty "Are you using cloudflare? (y/n): " USE_CLOUDFLARE
|
||||||
|
|
||||||
# ask for cloudflare api key
|
# ask for cloudflare api key
|
||||||
if [ "$USE_CLOUDFLARE" = "y" ]; then
|
if [ "$USE_CLOUDFLARE" = "y" ]; then
|
||||||
ask_while_empty "Enter cloudflare api key: " CLOUDFLARE_API_KEY
|
ask_while_empty "Enter cloudflare api key: " CLOUDFLARE_API_KEY
|
||||||
cat <<EOF >> "$CONFIG_BASE_PATH/$CONFIG_FILE_NAME"
|
cat <<EOF >>"$CONFIG_BASE_PATH/$CONFIG_FILE_NAME"
|
||||||
autocert:
|
autocert:
|
||||||
provider: cloudflare
|
provider: cloudflare
|
||||||
email: $EMAIL
|
email: $EMAIL
|
||||||
|
@ -210,10 +210,10 @@ autocert:
|
||||||
options:
|
options:
|
||||||
auth_token: "$CLOUDFLARE_API_KEY"
|
auth_token: "$CLOUDFLARE_API_KEY"
|
||||||
EOF
|
EOF
|
||||||
else
|
else
|
||||||
echo "Not using cloudflare, skipping autocert setup"
|
echo "Not using cloudflare, skipping autocert setup"
|
||||||
echo "Please refer to ${WIKI_URL}/Supported-DNS-01-Providers for more information"
|
echo "Please refer to ${WIKI_URL}/Supported-DNS-01-Providers for more information"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Setup finished"
|
echo "Setup finished"
|
||||||
|
|
Loading…
Add table
Reference in a new issue