mirror of
https://github.com/xxoommd/magic.git
synced 2025-07-04 09:42:43 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
dbd242cfb4 | ||
|
71cce2b79b | ||
|
7c13cbb324 | ||
|
7ef7b7392c | ||
|
734bb0fcb1 | ||
|
d7d36f793a | ||
|
395ee7a49e | ||
|
501cd1ff93 | ||
|
8b2517b9b1 |
@ -1,19 +1,19 @@
|
||||
alias l='ls -lhF'
|
||||
alias ll=l
|
||||
alias la='ls -AlhF'
|
||||
|
||||
export http_proxyserver="http://127.0.0.1:10809"
|
||||
|
||||
function set-proxy() {
|
||||
if [[ $1 == "on" ]]; then
|
||||
export HTTP_PROXY=$http_proxyserver
|
||||
export HTTPS_PROXY=$http_proxyserver
|
||||
elif [[ $1 == "off" ]]; then
|
||||
unset HTTP_PROXY HTTPS_PROXY
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "HTTP_PROXY=$HTTP_PROXY"
|
||||
echo "HTTPS_PROXY=$HTTPS_PROXY"
|
||||
echo
|
||||
alias l='ls -lhF'
|
||||
alias ll=l
|
||||
alias la='ls -AlhF'
|
||||
|
||||
export http_proxyserver="http://127.0.0.1:10809"
|
||||
|
||||
function set-proxy() {
|
||||
if [[ $1 == "on" ]]; then
|
||||
export HTTP_PROXY=$http_proxyserver
|
||||
export HTTPS_PROXY=$http_proxyserver
|
||||
elif [[ $1 == "off" ]]; then
|
||||
unset HTTP_PROXY HTTPS_PROXY
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "HTTP_PROXY=$HTTP_PROXY"
|
||||
echo "HTTPS_PROXY=$HTTPS_PROXY"
|
||||
echo
|
||||
}
|
298
profiles/win/profile
Normal file
298
profiles/win/profile
Normal file
@ -0,0 +1,298 @@
|
||||
alias l='ls -lhF'
|
||||
alias la='ls -AlhF'
|
||||
alias ll=l
|
||||
alias open=explorer
|
||||
|
||||
export LC_ALL=zh_CN.utf-8
|
||||
export http_proxyserver="http://127.0.0.1:10809"
|
||||
|
||||
function set_proxy() {
|
||||
if [[ $1 == "on" ]]; then
|
||||
export HTTP_PROXY=$http_proxyserver
|
||||
export HTTPS_PROXY=$http_proxyserver
|
||||
elif [[ $1 == "off" ]]; then
|
||||
unset HTTP_PROXY HTTPS_PROXY
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "HTTP_PROXY=$HTTP_PROXY"
|
||||
echo "HTTPS_PROXY=$HTTPS_PROXY"
|
||||
echo
|
||||
}
|
||||
|
||||
function _c3_tool_help() {
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo " - c3tool build|b [ARGS]"
|
||||
echo " [-u | --update-all] Updating Augustus custom resources and libs: SDL2 SDL2_mixer"
|
||||
echo " [-f | --force] Clean all and rebuild, including resources and libs"
|
||||
echo " [-r | --release] Build release version, default is debug"
|
||||
echo " - c3tool clean|c"
|
||||
echo
|
||||
}
|
||||
|
||||
function c3tool() {
|
||||
__GREEN__='\033[0;32m'
|
||||
__RED__='\033[0;31m'
|
||||
__BLUE__='\033[0;34m'
|
||||
__YELLOW__='\033[0;33m'
|
||||
__UNDERLINE__='\033[4m' # 下划线
|
||||
__RESET_COLOR__='\033[0m' # No Color
|
||||
__NC__='\033[0m' # No Color
|
||||
|
||||
# check `cmake`
|
||||
if command -v cmake &>/dev/null; then
|
||||
echo "[CHECK] cmake 已安装"
|
||||
else
|
||||
echo "[${__RED__}Err${__NC__}] cmake 未安装,请先安装 cmake"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if command -v mingw32-make &>/dev/null; then
|
||||
echo "[CHECK] mingw32-make 已安装"
|
||||
else
|
||||
echo "[${__RED__}Err${__NC__}] mingw32-make 未安装,请先安装 mingw32-make"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# check augustus or julius project folder
|
||||
if [ $(basename $PWD) == "build" ]; then
|
||||
PROJECT_DIR=$(cd .. && pwd)
|
||||
BUILD_DIR=$PWD
|
||||
else
|
||||
PROJECT_DIR=$PWD
|
||||
BUILD_DIR="$PWD/build"
|
||||
fi
|
||||
|
||||
if [ ! -f $PROJECT_DIR/CMakeLists.txt ]; then
|
||||
echo -e "[${__RED__}ERR${__NC__}] Enter '${__YELLOW__}augustus${__NC__}' or '${__YELLOW__}julius${__NC__}' project first."
|
||||
return 1
|
||||
fi
|
||||
printf "[CHECK] %-20s${__GREEN__}$PROJECT_DIR${__NC__}\n" "Project location:"
|
||||
|
||||
if [ ! -d $BUILD_DIR ]; then
|
||||
mkdir -p $BUILD_DIR
|
||||
fi
|
||||
printf "[CHECK] %-20s${__GREEN__}$BUILD_DIR${__NC__}\n" "Build location:"
|
||||
|
||||
TARGET_NAME=$(awk '/set\(SHORT_NAME/ {print $2}' $PROJECT_DIR/CMakeLists.txt | sed 's/)//g')
|
||||
printf "[CHECK] %-20s${__GREEN__}$TARGET_NAME${__NC__}\n" "Target name:"
|
||||
|
||||
if [[ $1 == "" || "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
_c3_tool_help
|
||||
return 0
|
||||
fi
|
||||
|
||||
cmd=$1 && shift
|
||||
|
||||
force=false
|
||||
update=false
|
||||
|
||||
# Parse args...
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
-u | --update)
|
||||
update=true
|
||||
;;
|
||||
-f | --force)
|
||||
force=true
|
||||
update=true
|
||||
;;
|
||||
-r | --release)
|
||||
BUILD_TYPE=release
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Execute cmd...
|
||||
case "$cmd" in
|
||||
b | build)
|
||||
if $force; then
|
||||
printf "[CLEAN] ... " && rm -rf $BUILD_DIR/* $BUILD_DIR/.* && echo "Done"
|
||||
fi
|
||||
|
||||
printf "[CHECK] %-20s${__GREEN__}$BUILD_TYPE${__NC__}\n" "CMAKE_BUILD_TYPE:"
|
||||
|
||||
# cmake
|
||||
if [[ ! -f "Makefile" ]]; then
|
||||
exec_str="cd $BUILD_DIR && cmake .. -G \"MinGW Makefiles\" > /dev/null"
|
||||
eval $exec_str
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "[${__RED__}ERR${__NC__}] Execute string: ${exec_str}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# mingw32-make
|
||||
echo "[BUILD] Start ..."
|
||||
if command -v nproc &>/dev/null; then
|
||||
makenum=$(nproc)
|
||||
else
|
||||
makenum=2
|
||||
fi
|
||||
|
||||
export CMAKE_BUILD_TYPE=${BUILD_TYPE}
|
||||
exec_str="cd $BUILD_DIR && mingw32-make -j$makenum --quiet > /dev/null"
|
||||
eval $exec_str
|
||||
if [ $? -ne 0 ]; then
|
||||
unset CMAKE_BUILD_TYPE
|
||||
echo -e "[${__RED__}ERR${__NC__}] FAIL. Execute string: ${exec_str}"
|
||||
return 1
|
||||
fi
|
||||
unset CMAKE_BUILD_TYPE
|
||||
|
||||
if $update; then
|
||||
if [[ $TARGET_NAME == "augustus" ]]; then
|
||||
printf "[UPDATE] Cleaning res..." && rm -rf assets maps && echo "Done"
|
||||
fi
|
||||
printf "[UPDATE] Cleaning libs..." && rm -f SDL2.dll SDL2_mixer.dll && echo "Done"
|
||||
fi
|
||||
|
||||
# Updating res:
|
||||
if [[ $TARGET_NAME == "augustus" ]]; then
|
||||
if [[ ! -d assets || ! -d maps ]]; then
|
||||
printf "[UPDATE] Copying assets ..." && cp -r ../res/assets . && echo "Done"
|
||||
printf "[UPDATE] Copying maps ..." && cp -r ../res/maps . && echo "Done"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Updating libs:
|
||||
if [[ ! -f SDL2.dll || ! -f SDL2_mixer.dll ]]; then
|
||||
printf "[UPDATE] Copying libs ..." && cp ../ext/SDL2/SDL2-2.32.4/x86_64-w64-mingw32/bin/SDL2.dll . &&
|
||||
cp ../ext/SDL2/SDL2_mixer-2.8.1/x86_64-w64-mingw32/bin/SDL2_mixer.dll . &&
|
||||
echo "Done"
|
||||
fi
|
||||
|
||||
echo -e "[BUILD] Build ${__GREEN__}${TARGET_NAME}${__NC__} success"
|
||||
|
||||
;;
|
||||
c | clean)
|
||||
printf "[CLEAN] ... " && rm -rf $BUILD_DIR/* $BUILD_DIR/.* && echo "Done"
|
||||
;;
|
||||
*)
|
||||
echo "[Err] Invalid cmd: $cmd"
|
||||
_c3_tool_help
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function connect() {
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
RESET_COLOR='\033[0m' # No Color
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
STR_BASH="[${GREEN}Bash${RESET_COLOR}]"
|
||||
STR_ZSH="[${GREEN}Zsh${RESET_COLOR}]"
|
||||
|
||||
STR_ERR_PREFIX="[${RED}Err${RESET_COLOR}]"
|
||||
STR_INFO_PREFIX="[${GREEN}INFO${NC}]"
|
||||
|
||||
if [[ -n "$BASH_VERSION" ]]; then
|
||||
printf "$STR_BASH Detected\n\n"
|
||||
declare -A servers
|
||||
elif [[ -n "$ZSH_VERSION" ]]; then
|
||||
printf "$STR_ZSH Detected\n\n"
|
||||
typeset -A servers
|
||||
setopt KSH_ARRAYS
|
||||
else
|
||||
echo -e "[${RED}Err${RESET_COLOR}] Running another shell. Only ${STR_BASH} or ${STR_ZSH} supported."
|
||||
return
|
||||
fi
|
||||
|
||||
servers=(
|
||||
# ["yact"]="ssh root@172.50.10.83"
|
||||
["yacloud"]="ssh -p 7189 gaohengyi@jumpserver.yacloud.net"
|
||||
["u1"]="ssh root@u1"
|
||||
["dev"]="ssh root@125.64.33.85"
|
||||
["tw"]="ssh root@tw.xmdgg.xyz"
|
||||
["hk"]="ssh root@hk.xmdgg.xyz"
|
||||
["us"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us1"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us2"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us3"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us4"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us5"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us6"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us7"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us8"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us9"]="ssh root@us.xmdgg.xyz"
|
||||
# ["us10"]="ssh root@us.xmdgg.xyz"
|
||||
)
|
||||
|
||||
servers_index=()
|
||||
if [[ -n "$BASH_VERSION" ]]; then
|
||||
for key in "${!servers[@]}"; do
|
||||
servers_index+=("$key")
|
||||
done
|
||||
elif [[ -n "$ZSH_VERSION" ]]; then
|
||||
for key in "${(k)servers[@]}"; do
|
||||
servers_index+=("$key")
|
||||
done
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
show_help=false
|
||||
server_name=""
|
||||
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
show_help=true
|
||||
elif [[ $1 =~ ^[0-9]+$ ]]; then
|
||||
server_index=$1
|
||||
server_name=${servers_index[$server_index]}
|
||||
if [ -z $server_name ]; then
|
||||
printf "${STR_ERR_PREFIX} Invalid index: $server_index\n\n"
|
||||
show_help=true
|
||||
fi
|
||||
else
|
||||
server_name=$1
|
||||
if [[ " ${servers_index[*]} " != *" $server_name "* ]]; then
|
||||
printf "${STR_ERR_PREFIX} Invalid name: $server_name"
|
||||
show_help=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if $show_help; then
|
||||
echo -e "Usage:\n"
|
||||
echo -e " - connect [${BLUE}ID${NC}] | [${BLUE}NAME${NC}]"
|
||||
echo -e "\nServers:\n"
|
||||
if [[ -n "$BASH_VERSION" ]]; then
|
||||
for i in ${!servers_index[@]}; do
|
||||
name=${servers_index[$i]}
|
||||
ssh_cmd=${servers[$name]}
|
||||
printf "${YELLOW}%2d${RESET_COLOR}|" $i
|
||||
printf "%-8s -> " $name
|
||||
printf "%s\n" "$ssh_cmd"
|
||||
done
|
||||
elif [[ -n "$ZSH_VERSION" ]]; then
|
||||
length=${#servers_index[@]}
|
||||
max=$((length-1))
|
||||
for i in {0..${max}}; do
|
||||
name=${servers_index[$i]}
|
||||
ssh_cmd=${servers[$name]}
|
||||
printf "${YELLOW}%2d${RESET_COLOR}|" $i
|
||||
printf "%-8s -> " $name
|
||||
printf "%s\n" "$ssh_cmd"
|
||||
done
|
||||
echo
|
||||
fi
|
||||
|
||||
return
|
||||
fi
|
||||
|
||||
ssh_cmd=${servers[$server_name]}
|
||||
echo -e "${STR_INFO_PREFIX} Connect to Server:"
|
||||
echo -e "${STR_INFO_PREFIX} NAME: $server_name"
|
||||
echo -e "${STR_INFO_PREFIX} CMD: ${YELLOW}$ssh_cmd${NC}"
|
||||
echo -e "${STR_INFO_PREFIX} Connecting..."
|
||||
err_msg=$(eval $ssh_cmd 2>&1 >/dev/tty)
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "${STR_ERR_PREFIX} $err_msg"
|
||||
fi
|
||||
echo
|
||||
}
|
354
scripts/connect
354
scripts/connect
@ -1,177 +1,177 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function print_err() {
|
||||
echo -e "\n[${RED}Err${NC}] $@"
|
||||
}
|
||||
|
||||
function print_info() {
|
||||
echo -e "\n[${GREEN}INFO${NC}] $@"
|
||||
}
|
||||
|
||||
declare -A servers
|
||||
servers["yact"]="ssh root@172.50.10.83"
|
||||
servers["tw"]="ssh root@tw.xmdgg.xyz"
|
||||
servers["hk"]="ssh root@hk.xmdgg.xyz"
|
||||
servers["us"]="ssh root@us.xmdgg.xyz"
|
||||
servers["ya"]="ssh -p 7189 gaohengyi@jumpserver.yacloud.net"
|
||||
servers["u1"]="ssh root@u1"
|
||||
servers["dev"]="ssh root@125.64.33.85"
|
||||
|
||||
function help() {
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo -e " 1.SSH to server: con (${GREEN}-C${NC}|${GREEN}--connect-host${NC} can be omitted) [NAME]"
|
||||
echo -e " Options:"
|
||||
echo -e " -u|--user [USER] Overwrite default user"
|
||||
echo -e " -p|--port [PORT] Overwrite default port\n"
|
||||
echo -e " 2.Remove know_hosts: con ${GREEN}-R${NC}|${GREEN}--remove-known-host${NC} [NAME]"
|
||||
echo ""
|
||||
echo "Available servers:"
|
||||
for name in "${!servers[@]}"; do
|
||||
sshcmd="${servers[$name]}"
|
||||
srv=($(parse_ssh_string $sshcmd))
|
||||
port=${srv[0]}
|
||||
user=${srv[1]}
|
||||
host=${srv[2]}
|
||||
|
||||
printf "${GREEN}%-6s${NC}" "* $name"
|
||||
printf " -> "
|
||||
printf "${NC}%-24s${NC}" "$user@$host"
|
||||
printf "${YELLOW}%-16s${NC}\n" " ssh_port:$port"
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
# parse_ssh_string: Parse ssh command to port, user, port
|
||||
#
|
||||
# - e.g: result=($(parse_ssh_string "ssh -p 2432 gaofei@192.168.137.105"))
|
||||
#
|
||||
# - params: string (e.g: ssh -p 2222 root@192.168.137.101)
|
||||
# - return: array (port[default:22] user host)
|
||||
function parse_ssh_string() {
|
||||
local str="$@"
|
||||
local port=22 # 默认端口
|
||||
local user=""
|
||||
local host=""
|
||||
|
||||
# 使用正则表达式解析字符串
|
||||
if [[ $str =~ -p[[:space:]]([0-9]+) ]]; then
|
||||
port=${BASH_REMATCH[1]}
|
||||
fi
|
||||
|
||||
if [[ $str =~ ([^[:space:]]+)@([a-zA-Z0-9.-]+) ]]; then
|
||||
user=${BASH_REMATCH[1]}
|
||||
host=${BASH_REMATCH[2]}
|
||||
fi
|
||||
|
||||
# 将结果存储到数组
|
||||
local result=("$port" "$user" "$host")
|
||||
echo "${result[@]}"
|
||||
}
|
||||
|
||||
function ssh_to_server() {
|
||||
if [[ -z $1 ]]; then
|
||||
print_err "server name not provided."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
user=""
|
||||
port=""
|
||||
hostname=""
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-u | --user)
|
||||
user=$2
|
||||
shift 2
|
||||
;;
|
||||
-p | --port)
|
||||
port=$2
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
hostname=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for name in "${!servers[@]}"; do
|
||||
if [[ $hostname == $name ]]; then
|
||||
sshcmd="${servers[$name]}"
|
||||
srv=($(parse_ssh_string $sshcmd))
|
||||
if [[ -z $port ]]; then
|
||||
port=${srv[0]}
|
||||
fi
|
||||
|
||||
if [[ -z $user ]]; then
|
||||
user=${srv[1]}
|
||||
fi
|
||||
|
||||
host=${srv[2]}
|
||||
|
||||
cmd=""
|
||||
if [[ "$port" -eq "22" ]]; then
|
||||
cmd="ssh $user@$host"
|
||||
else
|
||||
cmd="ssh -p $port $user@$host"
|
||||
fi
|
||||
|
||||
print_info "Executing: $cmd"
|
||||
eval $cmd
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
|
||||
print_err "server not found: $hostname"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function remove_known_host() {
|
||||
target_host=$1
|
||||
for name in "${!servers[@]}"; do
|
||||
if [[ $1 == $name ]]; then
|
||||
sshcmd="${servers[$name]}"
|
||||
server=($(parse_ssh_string $sshcmd))
|
||||
target_host=${server[2]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
cmd="ssh-keygen -R $target_host"
|
||||
print_info "Executing $cmd"
|
||||
eval $cmd
|
||||
exit $?
|
||||
}
|
||||
|
||||
function main() {
|
||||
if [[ -z $1 || $1 == "-h" || $1 == "--help" ]]; then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-R | --remove-known-host)
|
||||
shift 1
|
||||
remove_known_host $@
|
||||
;;
|
||||
-C | --connect-host)
|
||||
shift 1
|
||||
ssh_to_server $@
|
||||
;;
|
||||
*)
|
||||
ssh_to_server $@
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main $@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function print_err() {
|
||||
echo -e "\n[${RED}Err${NC}] $@"
|
||||
}
|
||||
|
||||
function print_info() {
|
||||
echo -e "\n[${GREEN}INFO${NC}] $@"
|
||||
}
|
||||
|
||||
declare -A servers
|
||||
servers["yact"]="ssh root@172.50.10.83"
|
||||
servers["tw"]="ssh root@tw.xmdgg.xyz"
|
||||
servers["hk"]="ssh root@hk.xmdgg.xyz"
|
||||
servers["us"]="ssh root@us.xmdgg.xyz"
|
||||
servers["ya"]="ssh -p 7189 gaohengyi@jumpserver.yacloud.net"
|
||||
servers["u1"]="ssh root@u1"
|
||||
servers["dev"]="ssh root@125.64.33.85"
|
||||
|
||||
function help() {
|
||||
echo
|
||||
echo "Usage:"
|
||||
echo -e " 1.SSH to server: con (${GREEN}-C${NC}|${GREEN}--connect-host${NC} can be omitted) [NAME]"
|
||||
echo -e " Options:"
|
||||
echo -e " -u|--user [USER] Overwrite default user"
|
||||
echo -e " -p|--port [PORT] Overwrite default port\n"
|
||||
echo -e " 2.Remove know_hosts: con ${GREEN}-R${NC}|${GREEN}--remove-known-host${NC} [NAME]"
|
||||
echo ""
|
||||
echo "Available servers:"
|
||||
for name in "${!servers[@]}"; do
|
||||
sshcmd="${servers[$name]}"
|
||||
srv=($(parse_ssh_string $sshcmd))
|
||||
port=${srv[0]}
|
||||
user=${srv[1]}
|
||||
host=${srv[2]}
|
||||
|
||||
printf "${GREEN}%-6s${NC}" "* $name"
|
||||
printf " -> "
|
||||
printf "${NC}%-24s${NC}" "$user@$host"
|
||||
printf "${YELLOW}%-16s${NC}\n" " ssh_port:$port"
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
# parse_ssh_string: Parse ssh command to port, user, port
|
||||
#
|
||||
# - e.g: result=($(parse_ssh_string "ssh -p 2432 gaofei@192.168.137.105"))
|
||||
#
|
||||
# - params: string (e.g: ssh -p 2222 root@192.168.137.101)
|
||||
# - return: array (port[default:22] user host)
|
||||
function parse_ssh_string() {
|
||||
local str="$@"
|
||||
local port=22 # 默认端口
|
||||
local user=""
|
||||
local host=""
|
||||
|
||||
# 使用正则表达式解析字符串
|
||||
if [[ $str =~ -p[[:space:]]([0-9]+) ]]; then
|
||||
port=${BASH_REMATCH[1]}
|
||||
fi
|
||||
|
||||
if [[ $str =~ ([^[:space:]]+)@([a-zA-Z0-9.-]+) ]]; then
|
||||
user=${BASH_REMATCH[1]}
|
||||
host=${BASH_REMATCH[2]}
|
||||
fi
|
||||
|
||||
# 将结果存储到数组
|
||||
local result=("$port" "$user" "$host")
|
||||
echo "${result[@]}"
|
||||
}
|
||||
|
||||
function ssh_to_server() {
|
||||
if [[ -z $1 ]]; then
|
||||
print_err "server name not provided."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
user=""
|
||||
port=""
|
||||
hostname=""
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-u | --user)
|
||||
user=$2
|
||||
shift 2
|
||||
;;
|
||||
-p | --port)
|
||||
port=$2
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
hostname=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for name in "${!servers[@]}"; do
|
||||
if [[ $hostname == $name ]]; then
|
||||
sshcmd="${servers[$name]}"
|
||||
srv=($(parse_ssh_string $sshcmd))
|
||||
if [[ -z $port ]]; then
|
||||
port=${srv[0]}
|
||||
fi
|
||||
|
||||
if [[ -z $user ]]; then
|
||||
user=${srv[1]}
|
||||
fi
|
||||
|
||||
host=${srv[2]}
|
||||
|
||||
cmd=""
|
||||
if [[ "$port" -eq "22" ]]; then
|
||||
cmd="ssh $user@$host"
|
||||
else
|
||||
cmd="ssh -p $port $user@$host"
|
||||
fi
|
||||
|
||||
print_info "Executing: $cmd"
|
||||
eval $cmd
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
|
||||
print_err "server not found: $hostname"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function remove_known_host() {
|
||||
target_host=$1
|
||||
for name in "${!servers[@]}"; do
|
||||
if [[ $1 == $name ]]; then
|
||||
sshcmd="${servers[$name]}"
|
||||
server=($(parse_ssh_string $sshcmd))
|
||||
target_host=${server[2]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
cmd="ssh-keygen -R $target_host"
|
||||
print_info "Executing $cmd"
|
||||
eval $cmd
|
||||
exit $?
|
||||
}
|
||||
|
||||
function main() {
|
||||
if [[ -z $1 || $1 == "-h" || $1 == "--help" ]]; then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-R | --remove-known-host)
|
||||
shift 1
|
||||
remove_known_host $@
|
||||
;;
|
||||
-C | --connect-host)
|
||||
shift 1
|
||||
ssh_to_server $@
|
||||
;;
|
||||
*)
|
||||
ssh_to_server $@
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main $@
|
||||
|
6
x/.gitignore
vendored
6
x/.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
Caddyfile
|
||||
config.yaml
|
||||
bin
|
||||
Caddyfile
|
||||
config.yaml
|
||||
bin
|
||||
|
80
x/README.md
80
x/README.md
@ -1,40 +1,40 @@
|
||||
# Verion 0.3
|
||||
|
||||
## QUICK START
|
||||
|
||||
1. Set variable: `DOMAIN` and `TAG`
|
||||
|
||||
```shell
|
||||
export DOMAIN=xxx.xxx
|
||||
export TAG=v0.4
|
||||
```
|
||||
|
||||
2. Start
|
||||
|
||||
#### server
|
||||
|
||||
- Github:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/x/quick_server.sh)
|
||||
```
|
||||
|
||||
- Gitea:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/x/quick_server.sh)
|
||||
```
|
||||
|
||||
#### client
|
||||
|
||||
- Github:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/x/quick_client.sh)
|
||||
```
|
||||
|
||||
- Gitea:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/x/quick_client.sh)
|
||||
```
|
||||
# Verion 0.3
|
||||
|
||||
## QUICK START
|
||||
|
||||
1. Set variable: `DOMAIN` and `TAG`
|
||||
|
||||
```shell
|
||||
export DOMAIN=xxx.xxx
|
||||
export TAG=v0.4
|
||||
```
|
||||
|
||||
2. Start
|
||||
|
||||
#### server
|
||||
|
||||
- Github:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/x/quick_server.sh)
|
||||
```
|
||||
|
||||
- Gitea:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/x/quick_server.sh)
|
||||
```
|
||||
|
||||
#### client
|
||||
|
||||
- Github:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/x/quick_client.sh)
|
||||
```
|
||||
|
||||
- Gitea:
|
||||
|
||||
```shell
|
||||
bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/x/quick_client.sh)
|
||||
```
|
||||
|
@ -1,124 +1,124 @@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function logerr() {
|
||||
echo -e "[${RED}ERR${NC}] $1"
|
||||
}
|
||||
|
||||
function loginfo() {
|
||||
echo -e "[INFO] $1"
|
||||
}
|
||||
|
||||
if [[ -z $DOMAIN ]]; then
|
||||
echo
|
||||
logerr "env:DOMAIN is not set"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG=${TAG:-latest}
|
||||
|
||||
github_download_url_prefix="https://github.com/xxoommd/magic/releases/download"
|
||||
gitee_download_url_prefix="https://github.com/xxoommd/ultimate_collection/releases/download"
|
||||
|
||||
naive_bin_name=""
|
||||
hysteria_bin_name=""
|
||||
|
||||
os_arch=$(uname -m)
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if [[ $os_arch != "x86_64" ]]; then
|
||||
logerr "Unsuppored arch: ${YELLOW}${os_arch}"${NC}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
naive_bin_name="naive-linux-amd64"
|
||||
hysteria_bin_name="hysteria-linux-amd64"
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
if [[ $os_arch == "x86_64" ]]; then
|
||||
naive_bin_name="naive-darwin-amd64"
|
||||
hysteria_bin_name="hysteria-darwin-amd64"
|
||||
elif [[ $os_arch == "arm64" ]]; then
|
||||
naive_bin_name="naive-darwin-arm64"
|
||||
hysteria_bin_name="hysteria-darwin-arm64"
|
||||
else
|
||||
logerr "Unsuppored arch: ${YELLOW}${os_arch}"${NC}
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then
|
||||
if [[ $os_arch == "x86_64" ]]; then
|
||||
naive_bin_name="naive-windows-amd64.exe"
|
||||
hysteria_bin_name="hysteria-windows-amd64-avx.exe"
|
||||
else
|
||||
logerr "Unsuppored arch: ${YELLOW}${os_arch}"${NC}
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
logerr "Unsupported OS: ${YELLOW}$OSTYPE${NC} arch: {YELLOW}$os_arch${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$naive_bin_name" ] || [ -z "$hysteria_bin_name" ]; then
|
||||
logerr "Download URL is null. Naive:$naive_bin_name Hysteria:$hysteria_bin_name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function download_bin() {
|
||||
download_url_naive="${gitee_download_url_prefix}/${TAG}/${naive_bin_name}"
|
||||
download_url_hysteria="${gitee_download_url_prefix}/${TAG}/${hysteria_bin_name}"
|
||||
|
||||
curl -o ./naive -L $download_url_naive && curl -o ./hysteria -L $download_url_hysteria && chmod +x ./naive ./hysteria
|
||||
}
|
||||
|
||||
HYSTERIA_CONFIG="./hysteria-config.yaml"
|
||||
NAIVE_CONFIG="./naive-config.json"
|
||||
|
||||
function gen_hysteria_config() {
|
||||
|
||||
cat >$HYSTERIA_CONFIG <<EOF
|
||||
server: $DOMAIN:8443
|
||||
auth: fuckyouall
|
||||
bandwidth:
|
||||
up: 100 mbps
|
||||
down: 1000 mbps
|
||||
socks5:
|
||||
listen: 127.0.0.1:21089
|
||||
http:
|
||||
listen: 127.0.0.1:28080
|
||||
EOF
|
||||
}
|
||||
|
||||
function gen_naive_config() {
|
||||
|
||||
echo -e "[INFO] Generate ${GREEN}${NAIVE_CONFIG}${NC} ..."
|
||||
cat >${NAIVE_CONFIG} <<EOF
|
||||
{
|
||||
"listen": "http://127.0.0.1:28081",
|
||||
"proxy": "quic://xxoommd:fuckyouall@$DOMAIN"
|
||||
}
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
}
|
||||
|
||||
function main() {
|
||||
if download_bin; then
|
||||
if gen_hysteria_config; then
|
||||
if gen_naive_config; then
|
||||
loginfo "ALL SUCCESS. Use: ./naive $NAIVE_CONFIG AND ./hysteria -c $HYSTERIA_CONFIG"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo
|
||||
logerr "Download binary fail."
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main $@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function logerr() {
|
||||
echo -e "[${RED}ERR${NC}] $1"
|
||||
}
|
||||
|
||||
function loginfo() {
|
||||
echo -e "[INFO] $1"
|
||||
}
|
||||
|
||||
if [[ -z $DOMAIN ]]; then
|
||||
echo
|
||||
logerr "env:DOMAIN is not set"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG=${TAG:-latest}
|
||||
|
||||
github_download_url_prefix="https://github.com/xxoommd/magic/releases/download"
|
||||
gitee_download_url_prefix="https://github.com/xxoommd/ultimate_collection/releases/download"
|
||||
|
||||
naive_bin_name=""
|
||||
hysteria_bin_name=""
|
||||
|
||||
os_arch=$(uname -m)
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if [[ $os_arch != "x86_64" ]]; then
|
||||
logerr "Unsuppored arch: ${YELLOW}${os_arch}"${NC}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
naive_bin_name="naive-linux-amd64"
|
||||
hysteria_bin_name="hysteria-linux-amd64"
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
if [[ $os_arch == "x86_64" ]]; then
|
||||
naive_bin_name="naive-darwin-amd64"
|
||||
hysteria_bin_name="hysteria-darwin-amd64"
|
||||
elif [[ $os_arch == "arm64" ]]; then
|
||||
naive_bin_name="naive-darwin-arm64"
|
||||
hysteria_bin_name="hysteria-darwin-arm64"
|
||||
else
|
||||
logerr "Unsuppored arch: ${YELLOW}${os_arch}"${NC}
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "msys"* || "$OSTYPE" == "cygwin"* ]]; then
|
||||
if [[ $os_arch == "x86_64" ]]; then
|
||||
naive_bin_name="naive-windows-amd64.exe"
|
||||
hysteria_bin_name="hysteria-windows-amd64-avx.exe"
|
||||
else
|
||||
logerr "Unsuppored arch: ${YELLOW}${os_arch}"${NC}
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
logerr "Unsupported OS: ${YELLOW}$OSTYPE${NC} arch: {YELLOW}$os_arch${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$naive_bin_name" ] || [ -z "$hysteria_bin_name" ]; then
|
||||
logerr "Download URL is null. Naive:$naive_bin_name Hysteria:$hysteria_bin_name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function download_bin() {
|
||||
download_url_naive="${gitee_download_url_prefix}/${TAG}/${naive_bin_name}"
|
||||
download_url_hysteria="${gitee_download_url_prefix}/${TAG}/${hysteria_bin_name}"
|
||||
|
||||
curl -o ./naive -L $download_url_naive && curl -o ./hysteria -L $download_url_hysteria && chmod +x ./naive ./hysteria
|
||||
}
|
||||
|
||||
HYSTERIA_CONFIG="./hysteria-config.yaml"
|
||||
NAIVE_CONFIG="./naive-config.json"
|
||||
|
||||
function gen_hysteria_config() {
|
||||
|
||||
cat >$HYSTERIA_CONFIG <<EOF
|
||||
server: $DOMAIN:8443
|
||||
auth: fuckyouall
|
||||
bandwidth:
|
||||
up: 100 mbps
|
||||
down: 1000 mbps
|
||||
socks5:
|
||||
listen: 127.0.0.1:21089
|
||||
http:
|
||||
listen: 127.0.0.1:28080
|
||||
EOF
|
||||
}
|
||||
|
||||
function gen_naive_config() {
|
||||
|
||||
echo -e "[INFO] Generate ${GREEN}${NAIVE_CONFIG}${NC} ..."
|
||||
cat >${NAIVE_CONFIG} <<EOF
|
||||
{
|
||||
"listen": "http://127.0.0.1:28081",
|
||||
"proxy": "quic://xxoommd:fuckyouall@$DOMAIN"
|
||||
}
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
}
|
||||
|
||||
function main() {
|
||||
if download_bin; then
|
||||
if gen_hysteria_config; then
|
||||
if gen_naive_config; then
|
||||
loginfo "ALL SUCCESS. Use: ./naive $NAIVE_CONFIG AND ./hysteria -c $HYSTERIA_CONFIG"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo
|
||||
logerr "Download binary fail."
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main $@
|
||||
|
@ -1,178 +1,178 @@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 仅root用户执行
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
echo "当前用户是 root"
|
||||
else
|
||||
echo -e "${RED}[Err]${NC}当前用户不是 root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 验证域名格式是否合法
|
||||
function is_valid_domain() {
|
||||
local str="$1"
|
||||
|
||||
# 使用正则表达式匹配合法域名格式
|
||||
if [[ $str =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$ ]]; then
|
||||
return 0 # 合法返回0
|
||||
else
|
||||
return 1 # 不合法返回1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Enabling BBR..."
|
||||
echo "net.core.default_qdisc=fq" | tee -a /etc/sysctl.conf
|
||||
echo "net.ipv4.tcp.congestion_control=bbr" |tee -a /etc/sysctl.conf
|
||||
sysctl -p
|
||||
|
||||
echo -e "\n[INFO] Validate DOMAN: ${BLUE}${DOMAIN}${NC} ..."
|
||||
|
||||
if [[ -z $DOMAIN ]]; then
|
||||
echo
|
||||
echo "[${RED}Err${NC}] DOMAIN is not set"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if is_valid_domain "$DOMAIN"; then
|
||||
echo -e "[INFO] ${BLUE}${UNDERLINE}$DOMAIN${NC} is a valid domain.\n"
|
||||
else
|
||||
echo -e "[${RED}ERR${NC}] ${BLUE}${UNDERLINE}$DOMAIN${NC} is not a valid domain. Abort."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG=${TAG:-"latest"}
|
||||
|
||||
echo -e "[INFO] Using TAG: ${YELLOW}${TAG}${NC}"
|
||||
|
||||
caddy_download_url=""
|
||||
hysteria_download_url=""
|
||||
|
||||
if [ "$DOWNLOAD_SRC" = "gitee" ]; then
|
||||
echo -e "[INFO] Download from ${YELLOW}Gitee${NC} ..."
|
||||
caddy_download_url="https://gitee.com/xxoommd/magic/releases/download/${TAG}/caddy-linux-amd64"
|
||||
hysteria_download_url="https://gitee.com/xxoommd/magic/releases/download/${TAG}/hysteria-linux-amd64-avx"
|
||||
else
|
||||
echo -e "[INFO] Download from ${YELLOW}Github${NC} ..."
|
||||
caddy_download_url="https://github.com/xxoommd/magic/releases/download/${TAG}/caddy-linux-amd64"
|
||||
hysteria_download_url="https://github.com/xxoommd/magic/releases/download/${TAG}/hysteria-linux-amd64-avx"
|
||||
fi
|
||||
|
||||
# 设置工作目录
|
||||
WORKING_DIR="/root/.local/magic"
|
||||
if [ ! -d "${WORKING_DIR}" ]; then
|
||||
mkdir -p "${WORKING_DIR}"
|
||||
fi
|
||||
|
||||
CADDY_STORAGE="${WORKING_DIR}/caddy"
|
||||
CERT_DIR="$CADDY_STORAGE/certificates/acme-v02.api.letsencrypt.org-directory/$DOMAIN"
|
||||
CRT_FILE="$CERT_DIR/$DOMAIN.crt"
|
||||
KEY_FILE="$CERT_DIR/$DOMAIN.key"
|
||||
HY_CONFIG_FILE="${WORKING_DIR}/hy-config.yaml"
|
||||
CADDY_CONFIG_FILE="${WORKING_DIR}/Caddyfile"
|
||||
|
||||
echo -e "[INFO] Download ${GREEN}hysteria${NC} and ${GREEN}caddy${NC} ..."
|
||||
curl -L -o /usr/local/bin/hysteria $hysteria_download_url && \
|
||||
curl -L -o /usr/local/bin/caddy $caddy_download_url && \
|
||||
chmod +x /usr/local/bin/hysteria /usr/local/bin/caddy
|
||||
echo -e "[INFO] Download Done\n"
|
||||
|
||||
# Generating all config files...
|
||||
echo -e "[INFO] Generate ${GREEN}${CADDY_CONFIG_FILE}${NC} ..."
|
||||
cat >${CADDY_CONFIG_FILE} <<EOF
|
||||
{
|
||||
storage file_system $CADDY_STORAGE
|
||||
}
|
||||
|
||||
:443, ${DOMAIN}
|
||||
tls xxoommd@${DOMAIN}
|
||||
route {
|
||||
forward_proxy {
|
||||
basic_auth xxoommd fuckyouall
|
||||
hide_ip
|
||||
hide_via
|
||||
probe_resistance
|
||||
# upstream socks5://127.0.0.1:40000
|
||||
}
|
||||
respond "hello ${DOMAIN}@naive!"
|
||||
}
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Generate ${GREEN}${HY_CONFIG_FILE}${NC} ..."
|
||||
cat >${HY_CONFIG_FILE} <<EOF
|
||||
listen: :8443
|
||||
tls:
|
||||
cert: $CRT_FILE
|
||||
key: $KEY_FILE
|
||||
auth:
|
||||
type: password
|
||||
password: fuckyouall
|
||||
masquerade:
|
||||
type: string
|
||||
string:
|
||||
content: 'hello ${DOMAIN}@hysteria2'
|
||||
headers:
|
||||
content-type: text/plain
|
||||
custom-stuff: ice cream so good
|
||||
statusCode: 200
|
||||
disableUDP: false
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Generate ${GREEN}hysteria.service${NC} ..."
|
||||
cat >/etc/systemd/system/hysteria.service <<EOF
|
||||
[Unit]
|
||||
Description=Hysteria Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/hysteria server --config /${HY_CONFIG_FILE}
|
||||
WorkingDirectory=${WORKING_DIR}
|
||||
Restart=on-failure
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Generating caddy.service${NC} ..."
|
||||
cat >/etc/systemd/system/caddy.service <<EOF
|
||||
[Unit]
|
||||
Description=Caddy
|
||||
Documentation=https://caddyserver.com/docs/
|
||||
After=network.target network-online.target
|
||||
Requires=network-online.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/caddy run --environ --config ${CADDY_CONFIG_FILE}
|
||||
ExecReload=/usr/local/bin/caddy reload --config ${CADDY_CONFIG_FILE}
|
||||
TimeoutStopSec=5s
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=512
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Handling ${GREEN}system daemons${NC} ..."
|
||||
systemctl daemon-reload && systemctl enable caddy && systemctl enable hysteria
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "All ready!!!"
|
||||
echo -e " Note: Run ${GREEN}caddy${NC} first to gain certificates. Wait a few seconds then start ${GREEN}hysteria${NC}."
|
||||
echo -e " E.g: ${GREEN}systemctl start caddy && sleep 10 && systemctl start hysteria${NC}\n"
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 仅root用户执行
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
echo "当前用户是 root"
|
||||
else
|
||||
echo -e "${RED}[Err]${NC}当前用户不是 root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 验证域名格式是否合法
|
||||
function is_valid_domain() {
|
||||
local str="$1"
|
||||
|
||||
# 使用正则表达式匹配合法域名格式
|
||||
if [[ $str =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$ ]]; then
|
||||
return 0 # 合法返回0
|
||||
else
|
||||
return 1 # 不合法返回1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Enabling BBR..."
|
||||
echo "net.core.default_qdisc=fq" | tee -a /etc/sysctl.conf
|
||||
echo "net.ipv4.tcp_congestion_control=bbr" |tee -a /etc/sysctl.conf
|
||||
sysctl -p
|
||||
|
||||
echo -e "\n[INFO] Validate DOMAN: ${BLUE}${DOMAIN}${NC} ..."
|
||||
|
||||
if [[ -z $DOMAIN ]]; then
|
||||
echo
|
||||
echo "[${RED}Err${NC}] DOMAIN is not set"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if is_valid_domain "$DOMAIN"; then
|
||||
echo -e "[INFO] ${BLUE}${UNDERLINE}$DOMAIN${NC} is a valid domain.\n"
|
||||
else
|
||||
echo -e "[${RED}ERR${NC}] ${BLUE}${UNDERLINE}$DOMAIN${NC} is not a valid domain. Abort."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG=${TAG:-"latest"}
|
||||
|
||||
echo -e "[INFO] Using TAG: ${YELLOW}${TAG}${NC}"
|
||||
|
||||
caddy_download_url=""
|
||||
hysteria_download_url=""
|
||||
|
||||
if [ "$DOWNLOAD_SRC" = "gitee" ]; then
|
||||
echo -e "[INFO] Download from ${YELLOW}Gitee${NC} ..."
|
||||
caddy_download_url="https://gitee.com/xxoommd/magic/releases/download/${TAG}/caddy-linux-amd64"
|
||||
hysteria_download_url="https://gitee.com/xxoommd/magic/releases/download/${TAG}/hysteria-linux-amd64-avx"
|
||||
else
|
||||
echo -e "[INFO] Download from ${YELLOW}Github${NC} ..."
|
||||
caddy_download_url="https://github.com/xxoommd/magic/releases/download/${TAG}/caddy-linux-amd64"
|
||||
hysteria_download_url="https://github.com/xxoommd/magic/releases/download/${TAG}/hysteria-linux-amd64-avx"
|
||||
fi
|
||||
|
||||
# 设置工作目录
|
||||
WORKING_DIR="/root/.local/magic"
|
||||
if [ ! -d "${WORKING_DIR}" ]; then
|
||||
mkdir -p "${WORKING_DIR}"
|
||||
fi
|
||||
|
||||
CADDY_STORAGE="${WORKING_DIR}/caddy"
|
||||
CERT_DIR="$CADDY_STORAGE/certificates/acme-v02.api.letsencrypt.org-directory/$DOMAIN"
|
||||
CRT_FILE="$CERT_DIR/$DOMAIN.crt"
|
||||
KEY_FILE="$CERT_DIR/$DOMAIN.key"
|
||||
HY_CONFIG_FILE="${WORKING_DIR}/hy-config.yaml"
|
||||
CADDY_CONFIG_FILE="${WORKING_DIR}/Caddyfile"
|
||||
|
||||
echo -e "[INFO] Download ${GREEN}hysteria${NC} and ${GREEN}caddy${NC} ..."
|
||||
curl -L -o /usr/local/bin/hysteria $hysteria_download_url && \
|
||||
curl -L -o /usr/local/bin/caddy $caddy_download_url && \
|
||||
chmod +x /usr/local/bin/hysteria /usr/local/bin/caddy
|
||||
echo -e "[INFO] Download Done\n"
|
||||
|
||||
# Generating all config files...
|
||||
echo -e "[INFO] Generate ${GREEN}${CADDY_CONFIG_FILE}${NC} ..."
|
||||
cat >${CADDY_CONFIG_FILE} <<EOF
|
||||
{
|
||||
storage file_system $CADDY_STORAGE
|
||||
}
|
||||
|
||||
:443, ${DOMAIN}
|
||||
tls xxoommd@${DOMAIN}
|
||||
route {
|
||||
forward_proxy {
|
||||
basic_auth xxoommd fuckyouall
|
||||
hide_ip
|
||||
hide_via
|
||||
probe_resistance
|
||||
# upstream socks5://127.0.0.1:40000
|
||||
}
|
||||
respond "hello ${DOMAIN}@naive!"
|
||||
}
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Generate ${GREEN}${HY_CONFIG_FILE}${NC} ..."
|
||||
cat >${HY_CONFIG_FILE} <<EOF
|
||||
listen: :8443
|
||||
tls:
|
||||
cert: $CRT_FILE
|
||||
key: $KEY_FILE
|
||||
auth:
|
||||
type: password
|
||||
password: fuckyouall
|
||||
masquerade:
|
||||
type: string
|
||||
string:
|
||||
content: 'hello ${DOMAIN}@hysteria2'
|
||||
headers:
|
||||
content-type: text/plain
|
||||
custom-stuff: ice cream so good
|
||||
statusCode: 200
|
||||
disableUDP: false
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Generate ${GREEN}hysteria.service${NC} ..."
|
||||
cat >/etc/systemd/system/hysteria.service <<EOF
|
||||
[Unit]
|
||||
Description=Hysteria Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/hysteria server --config /${HY_CONFIG_FILE}
|
||||
WorkingDirectory=${WORKING_DIR}
|
||||
Restart=on-failure
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Generating caddy.service${NC} ..."
|
||||
cat >/etc/systemd/system/caddy.service <<EOF
|
||||
[Unit]
|
||||
Description=Caddy
|
||||
Documentation=https://caddyserver.com/docs/
|
||||
After=network.target network-online.target
|
||||
Requires=network-online.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/caddy run --environ --config ${CADDY_CONFIG_FILE}
|
||||
ExecReload=/usr/local/bin/caddy reload --config ${CADDY_CONFIG_FILE}
|
||||
TimeoutStopSec=5s
|
||||
LimitNOFILE=1048576
|
||||
LimitNPROC=512
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "[INFO] Handling ${GREEN}system daemons${NC} ..."
|
||||
systemctl daemon-reload && systemctl enable caddy && systemctl enable hysteria
|
||||
echo -e "[INFO] Generate Done\n"
|
||||
|
||||
echo -e "All ready!!!"
|
||||
echo -e " Note: Run ${GREEN}caddy${NC} first to gain certificates. Wait a few seconds then start ${GREEN}hysteria${NC}."
|
||||
echo -e " E.g: ${GREEN}systemctl start caddy && sleep 10 && systemctl start hysteria${NC}\n"
|
||||
|
378
x/update_bin.sh
378
x/update_bin.sh
@ -1,189 +1,189 @@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
BIN_PATH="./bin"
|
||||
|
||||
function check_golang() {
|
||||
echo
|
||||
echo "[INFO] Checking golang..."
|
||||
if command -v go >/dev/null 2>&1; then
|
||||
GO_VER="$(go version)"
|
||||
echo "[INFO] Go is installed: " $GO_VER
|
||||
echo
|
||||
else
|
||||
echo "[INFO] Go is not installed. Start installing..."
|
||||
install_go
|
||||
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "[${RED}Err${NC}] Install ${YELLLOW}golang${NC} fail"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_go() {
|
||||
go_ver=$(curl -s https://go.dev/VERSION?m=text | grep go)
|
||||
echo "[INFO] Downloading ${go_ver}..."
|
||||
curl -s -L -o /tmp/$go_ver.linux-amd64.tar.gz https://go.dev/dl/${go_ver}.linux-amd64.tar.gz &&
|
||||
sudo tar -xf /tmp/go*.linux-amd64.tar.gz -C /usr/local/ &&
|
||||
rm /tmp/go*.linux-amd64.tar.gz &&
|
||||
echo 'export GOROOT=/usr/local/go' >>~/.profile &&
|
||||
echo 'export PATH=$GOROOT/bin:$PATH' >>~/.profile &&
|
||||
echo 'export GO111MODULE=on' >>~/.profile &&
|
||||
source ~/.profile && echo -e "[INFO] Install golang success:" && go version && echo
|
||||
}
|
||||
|
||||
function build_caddy() {
|
||||
export GOOS=$1
|
||||
export GOARCH=$2
|
||||
export OUTPUT="caddy-${GOOS}-${GOARCH}"
|
||||
if [[ "$GOOS" == "windows" ]]; then
|
||||
export OUTPUT=$OUTPUT.exe
|
||||
fi
|
||||
cmd="~/go/bin/xcaddy build --output $BIN_PATH/${OUTPUT} --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive > /dev/null 2>&1"
|
||||
echo -e "- Building ${GREEN}${OUTPUT}${NC}: ${YELLOW}${cmd}${NC}"
|
||||
eval ${cmd}
|
||||
}
|
||||
|
||||
function update_caddy() {
|
||||
go env -w GO111MODULE=on &&
|
||||
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest &&
|
||||
build_caddy "linux" "amd64" &&
|
||||
# build_caddy "darwin" "arm64" &&
|
||||
# build_caddy "darwin" "amd64" &&
|
||||
# build_caddy "windows" "amd64" &&
|
||||
chmod +x $BIN_PATH/* && ls -lhF $BIN_PATH/caddy*
|
||||
}
|
||||
|
||||
function download_naive() {
|
||||
NAIVE_VERSION=$1
|
||||
OS=$2
|
||||
ARCH=$3
|
||||
OS_N=$4
|
||||
ARCH_N=$5
|
||||
SUFFIX=${6:-tar.xz}
|
||||
|
||||
target_name="naive-${OS}-${ARCH}.${SUFFIX}"
|
||||
download_url="https://github.com/klzgrad/naiveproxy/releases/download/${NAIVE_VERSION}/naiveproxy-${NAIVE_VERSION}-${OS_N}-${ARCH_N}.${SUFFIX}"
|
||||
download_cmd="curl -s -L -o /tmp/${target_name} $download_url"
|
||||
decompress_cmd="tar -xf /tmp/${target_name} -C /tmp"
|
||||
mv_cmd="mv /tmp/naiveproxy-${NAIVE_VERSION}-${OS_N}-${ARCH_N}/naive $BIN_PATH/naive-${OS}-${ARCH}"
|
||||
|
||||
if [[ "$SUFFIX" == "zip" ]]; then
|
||||
decompress_cmd="unzip -q -o -d /tmp /tmp/${target_name}"
|
||||
mv_cmd="mv /tmp/naiveproxy-${NAIVE_VERSION}-${OS_N}-${ARCH_N}/naive.exe $BIN_PATH/naive-${OS}-${ARCH}.exe"
|
||||
fi
|
||||
|
||||
echo -e "- Downloading: ${target_name} ..."
|
||||
|
||||
eval $download_cmd && eval $decompress_cmd && eval $mv_cmd
|
||||
rm -rf /tmp/naive*
|
||||
}
|
||||
|
||||
function update_naive() {
|
||||
rm -rf /tmp/naive*
|
||||
NAIVE_VERSION="v135.0.7049.38-2"
|
||||
download_naive $NAIVE_VERSION "linux" "amd64" "linux" "x64" &&
|
||||
download_naive $NAIVE_VERSION "darwin" "amd64" "mac" "x64" &&
|
||||
download_naive $NAIVE_VERSION "darwin" "arm64" "mac" "arm64" &&
|
||||
download_naive $NAIVE_VERSION "windows" "amd64" "win" "x64" "zip" &&
|
||||
echo &&
|
||||
chmod +x $BIN_PATH/naive* && ls -lhF $BIN_PATH/naive*
|
||||
}
|
||||
|
||||
function download_hysteria() {
|
||||
echo "- Downloading hysteria-linux-amd64-avx ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-linux-amd64-avx https://download.hysteria.network/app/latest/hysteria-linux-amd64-avx &&
|
||||
echo "- Downloading hysteria-darwin-amd64 ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-darwin-amd64 https://download.hysteria.network/app/latest/hysteria-darwin-amd64 &&
|
||||
echo "- Downloading hysteria-darwin-arm64 ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-darwin-arm64 https://download.hysteria.network/app/latest/hysteria-darwin-arm64 &&
|
||||
echo "- Downloading hysteria-windows-amd64-avx.exe ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-windows-amd64-avx.exe https://download.hysteria.network/app/latest/hysteria-windows-amd64-avx.exe &&
|
||||
echo &&
|
||||
chmod +x $BIN_PATH/* && ls -lhF $BIN_PATH/hy*
|
||||
}
|
||||
|
||||
function main() {
|
||||
source ~/.profile
|
||||
|
||||
up_caddy=false
|
||||
up_hy=false
|
||||
up_naive=false
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
up_caddy=true
|
||||
up_hy=true
|
||||
up_naive=true
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
caddy)
|
||||
up_caddy=true
|
||||
;;
|
||||
hysteria | hy)
|
||||
up_hy=true
|
||||
;;
|
||||
naive)
|
||||
up_naive=true
|
||||
;;
|
||||
all)
|
||||
up_naive=true
|
||||
up_caddy=true
|
||||
up_hy=true
|
||||
;;
|
||||
*)
|
||||
echo -e "\n[${RED}Err${NC}] Invalid arg: $1\n"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[ ! -d "$BIN_PATH" ] && mkdir -p $BIN_PATH # 创建./bin目录
|
||||
|
||||
if ! check_golang; then
|
||||
echo -e "[${RED}Err${NC}] Check ${YELLLOW}golang${NC} success"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$up_caddy" = true ]; then
|
||||
echo
|
||||
echo -e "[INFO] Updating ${GREEN}caddy${NC} ..."
|
||||
if update_caddy; then
|
||||
echo -e "[INFO] Updating ${GREEN}caddy${NC} success"
|
||||
else
|
||||
echo -e "[INFO] Updating ${GREEN}caddy${NC} fail"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "$up_hy" = true ]; then
|
||||
echo -e "[INFO] Downloading ${GREEN}hysteria2${NC} ..."
|
||||
if download_hysteria; then
|
||||
echo -e "[INFO] Download ${GREEN}hysteria2${NC} success"
|
||||
else
|
||||
echo -e "[Err] Download ${GREEN}hysteria2${NC} fail"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "$up_naive" = true ]; then
|
||||
echo -e "[INFO] Downloading ${GREEN}naive${NC} ..."
|
||||
if ! update_naive; then
|
||||
echo -e "[${RED}ERR${NC}] Download naive fail"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
main $@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[0;33m'
|
||||
UNDERLINE='\033[4m' # 下划线
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
BIN_PATH="./bin"
|
||||
|
||||
function check_golang() {
|
||||
echo
|
||||
echo "[INFO] Checking golang..."
|
||||
if command -v go >/dev/null 2>&1; then
|
||||
GO_VER="$(go version)"
|
||||
echo "[INFO] Go is installed: " $GO_VER
|
||||
echo
|
||||
else
|
||||
echo "[INFO] Go is not installed. Start installing..."
|
||||
install_go
|
||||
|
||||
if [[ $? != 0 ]]; then
|
||||
echo -e "[${RED}Err${NC}] Install ${YELLLOW}golang${NC} fail"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_go() {
|
||||
go_ver=$(curl -s https://go.dev/VERSION?m=text | grep go)
|
||||
echo "[INFO] Downloading ${go_ver}..."
|
||||
curl -s -L -o /tmp/$go_ver.linux-amd64.tar.gz https://go.dev/dl/${go_ver}.linux-amd64.tar.gz &&
|
||||
sudo tar -xf /tmp/go*.linux-amd64.tar.gz -C /usr/local/ &&
|
||||
rm /tmp/go*.linux-amd64.tar.gz &&
|
||||
echo 'export GOROOT=/usr/local/go' >>~/.profile &&
|
||||
echo 'export PATH=$GOROOT/bin:$PATH' >>~/.profile &&
|
||||
echo 'export GO111MODULE=on' >>~/.profile &&
|
||||
source ~/.profile && echo -e "[INFO] Install golang success:" && go version && echo
|
||||
}
|
||||
|
||||
function build_caddy() {
|
||||
export GOOS=$1
|
||||
export GOARCH=$2
|
||||
export OUTPUT="caddy-${GOOS}-${GOARCH}"
|
||||
if [[ "$GOOS" == "windows" ]]; then
|
||||
export OUTPUT=$OUTPUT.exe
|
||||
fi
|
||||
cmd="~/go/bin/xcaddy build --output $BIN_PATH/${OUTPUT} --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive > /dev/null 2>&1"
|
||||
echo -e "- Building ${GREEN}${OUTPUT}${NC}: ${YELLOW}${cmd}${NC}"
|
||||
eval ${cmd}
|
||||
}
|
||||
|
||||
function update_caddy() {
|
||||
go env -w GO111MODULE=on &&
|
||||
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest &&
|
||||
build_caddy "linux" "amd64" &&
|
||||
# build_caddy "darwin" "arm64" &&
|
||||
# build_caddy "darwin" "amd64" &&
|
||||
# build_caddy "windows" "amd64" &&
|
||||
chmod +x $BIN_PATH/* && ls -lhF $BIN_PATH/caddy*
|
||||
}
|
||||
|
||||
function download_naive() {
|
||||
NAIVE_VERSION=$1
|
||||
OS=$2
|
||||
ARCH=$3
|
||||
OS_N=$4
|
||||
ARCH_N=$5
|
||||
SUFFIX=${6:-tar.xz}
|
||||
|
||||
target_name="naive-${OS}-${ARCH}.${SUFFIX}"
|
||||
download_url="https://github.com/klzgrad/naiveproxy/releases/download/${NAIVE_VERSION}/naiveproxy-${NAIVE_VERSION}-${OS_N}-${ARCH_N}.${SUFFIX}"
|
||||
download_cmd="curl -s -L -o /tmp/${target_name} $download_url"
|
||||
decompress_cmd="tar -xf /tmp/${target_name} -C /tmp"
|
||||
mv_cmd="mv /tmp/naiveproxy-${NAIVE_VERSION}-${OS_N}-${ARCH_N}/naive $BIN_PATH/naive-${OS}-${ARCH}"
|
||||
|
||||
if [[ "$SUFFIX" == "zip" ]]; then
|
||||
decompress_cmd="unzip -q -o -d /tmp /tmp/${target_name}"
|
||||
mv_cmd="mv /tmp/naiveproxy-${NAIVE_VERSION}-${OS_N}-${ARCH_N}/naive.exe $BIN_PATH/naive-${OS}-${ARCH}.exe"
|
||||
fi
|
||||
|
||||
echo -e "- Downloading: ${target_name} ..."
|
||||
|
||||
eval $download_cmd && eval $decompress_cmd && eval $mv_cmd
|
||||
rm -rf /tmp/naive*
|
||||
}
|
||||
|
||||
function update_naive() {
|
||||
rm -rf /tmp/naive*
|
||||
NAIVE_VERSION="v135.0.7049.38-2"
|
||||
download_naive $NAIVE_VERSION "linux" "amd64" "linux" "x64" &&
|
||||
download_naive $NAIVE_VERSION "darwin" "amd64" "mac" "x64" &&
|
||||
download_naive $NAIVE_VERSION "darwin" "arm64" "mac" "arm64" &&
|
||||
download_naive $NAIVE_VERSION "windows" "amd64" "win" "x64" "zip" &&
|
||||
echo &&
|
||||
chmod +x $BIN_PATH/naive* && ls -lhF $BIN_PATH/naive*
|
||||
}
|
||||
|
||||
function download_hysteria() {
|
||||
echo "- Downloading hysteria-linux-amd64-avx ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-linux-amd64-avx https://download.hysteria.network/app/latest/hysteria-linux-amd64-avx &&
|
||||
echo "- Downloading hysteria-darwin-amd64 ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-darwin-amd64 https://download.hysteria.network/app/latest/hysteria-darwin-amd64 &&
|
||||
echo "- Downloading hysteria-darwin-arm64 ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-darwin-arm64 https://download.hysteria.network/app/latest/hysteria-darwin-arm64 &&
|
||||
echo "- Downloading hysteria-windows-amd64-avx.exe ..." &&
|
||||
curl -s -L -o $BIN_PATH/hysteria-windows-amd64-avx.exe https://download.hysteria.network/app/latest/hysteria-windows-amd64-avx.exe &&
|
||||
echo &&
|
||||
chmod +x $BIN_PATH/* && ls -lhF $BIN_PATH/hy*
|
||||
}
|
||||
|
||||
function main() {
|
||||
source ~/.profile
|
||||
|
||||
up_caddy=false
|
||||
up_hy=false
|
||||
up_naive=false
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
up_caddy=true
|
||||
up_hy=true
|
||||
up_naive=true
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
caddy)
|
||||
up_caddy=true
|
||||
;;
|
||||
hysteria | hy)
|
||||
up_hy=true
|
||||
;;
|
||||
naive)
|
||||
up_naive=true
|
||||
;;
|
||||
all)
|
||||
up_naive=true
|
||||
up_caddy=true
|
||||
up_hy=true
|
||||
;;
|
||||
*)
|
||||
echo -e "\n[${RED}Err${NC}] Invalid arg: $1\n"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
[ ! -d "$BIN_PATH" ] && mkdir -p $BIN_PATH # 创建./bin目录
|
||||
|
||||
if ! check_golang; then
|
||||
echo -e "[${RED}Err${NC}] Check ${YELLLOW}golang${NC} success"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$up_caddy" = true ]; then
|
||||
echo
|
||||
echo -e "[INFO] Updating ${GREEN}caddy${NC} ..."
|
||||
if update_caddy; then
|
||||
echo -e "[INFO] Updating ${GREEN}caddy${NC} success"
|
||||
else
|
||||
echo -e "[INFO] Updating ${GREEN}caddy${NC} fail"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "$up_hy" = true ]; then
|
||||
echo -e "[INFO] Downloading ${GREEN}hysteria2${NC} ..."
|
||||
if download_hysteria; then
|
||||
echo -e "[INFO] Download ${GREEN}hysteria2${NC} success"
|
||||
else
|
||||
echo -e "[Err] Download ${GREEN}hysteria2${NC} fail"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
|
||||
if [ "$up_naive" = true ]; then
|
||||
echo -e "[INFO] Downloading ${GREEN}naive${NC} ..."
|
||||
if ! update_naive; then
|
||||
echo -e "[${RED}ERR${NC}] Download naive fail"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
main $@
|
||||
|
Loading…
x
Reference in New Issue
Block a user