Your commit message
This commit is contained in:
40
基础脚本/fontColor.sh
Normal file
40
基础脚本/fontColor.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
#######第一种方法(推荐使用 颜色函数)########
|
||||
|
||||
#########color code#############
|
||||
RED="31m" ## 姨妈红
|
||||
GREEN="32m" ## 水鸭青
|
||||
YELLOW="33m" ## 鸭屎黄
|
||||
BLUE="35m" ## 基佬紫
|
||||
BLUE="36m" ## 天依蓝
|
||||
|
||||
###############color echo func#################
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
###########第二种方法###############
|
||||
Red_font_prefix="\033[31m"
|
||||
Green_font_prefix="\033[32m"
|
||||
Yellow_font_prefix="\033[33m"
|
||||
Blue_font_prefix="\033[34m"
|
||||
|
||||
Green_background_prefix="\033[42;37m"
|
||||
Red_background_prefix="\033[41;37m"
|
||||
Font_color_suffix="\033[0m"
|
||||
main(){
|
||||
colorEcho ${RED} "这是红色的字体!"
|
||||
colorEcho ${GREEN} "这是绿色的字体!"
|
||||
colorEcho ${YELLOW} "这是黄色的字体!"
|
||||
colorEcho ${BLUE} "这是蓝色的字体!"
|
||||
echo "#######################下面是第二种方法!###############################"
|
||||
echo
|
||||
echo -e "${Red_font_prefix}这是红色的字体!${Font_color_suffix}"
|
||||
echo -e "${Green_font_prefix}这是绿色的字体!${Font_color_suffix}"
|
||||
echo -e "${Yellow_font_prefix}这是黄色的字体!${Font_color_suffix}"
|
||||
echo -e "${Blue_font_prefix}这是蓝色的字体!${Font_color_suffix}"
|
||||
}
|
||||
|
||||
main
|
||||
494
基础脚本/go.sh
Normal file
494
基础脚本/go.sh
Normal file
@@ -0,0 +1,494 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This file is accessible as https://install.direct/go.sh
|
||||
# Original source is located at github.com/v2ray/v2ray-core/release/install-release.sh
|
||||
|
||||
# If not specify, default meaning of return value:
|
||||
# 0: Success
|
||||
# 1: System error
|
||||
# 2: Application error
|
||||
# 3: Network error
|
||||
|
||||
# CLI arguments
|
||||
PROXY=''
|
||||
HELP=''
|
||||
FORCE=''
|
||||
CHECK=''
|
||||
REMOVE=''
|
||||
VERSION=''
|
||||
VSRC_ROOT='/tmp/v2ray'
|
||||
EXTRACT_ONLY=''
|
||||
LOCAL=''
|
||||
LOCAL_INSTALL=''
|
||||
DIST_SRC='jsdelivr'
|
||||
ERROR_IF_UPTODATE=''
|
||||
|
||||
CUR_VER=""
|
||||
NEW_VER=""
|
||||
VDIS=''
|
||||
ZIPFILE="/tmp/v2ray/v2ray.zip"
|
||||
V2RAY_RUNNING=0
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
|
||||
SYSTEMCTL_CMD=$(command -v systemctl 2>/dev/null)
|
||||
SERVICE_CMD=$(command -v service 2>/dev/null)
|
||||
|
||||
#######color code########
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
|
||||
#########################
|
||||
while [[ $# > 0 ]]; do
|
||||
case "$1" in
|
||||
-p|--proxy)
|
||||
PROXY="-x ${2}"
|
||||
shift # past argument
|
||||
;;
|
||||
-h|--help)
|
||||
HELP="1"
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE="1"
|
||||
;;
|
||||
-c|--check)
|
||||
CHECK="1"
|
||||
;;
|
||||
--remove)
|
||||
REMOVE="1"
|
||||
;;
|
||||
--version)
|
||||
VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
--extract)
|
||||
VSRC_ROOT="$2"
|
||||
shift
|
||||
;;
|
||||
--extractonly)
|
||||
EXTRACT_ONLY="1"
|
||||
;;
|
||||
-l|--local)
|
||||
LOCAL="$2"
|
||||
LOCAL_INSTALL="1"
|
||||
shift
|
||||
;;
|
||||
--source)
|
||||
DIST_SRC="$2"
|
||||
shift
|
||||
;;
|
||||
--errifuptodate)
|
||||
ERROR_IF_UPTODATE="1"
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
######## 颜色函数方法 #########
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
archAffix(){
|
||||
case "${1:-"$(uname -m)"}" in
|
||||
i686|i386)
|
||||
echo '32'
|
||||
;;
|
||||
x86_64|amd64)
|
||||
echo '64'
|
||||
;;
|
||||
*armv7*|armv6l)
|
||||
echo 'arm'
|
||||
;;
|
||||
*armv8*|aarch64)
|
||||
echo 'arm64'
|
||||
;;
|
||||
*mips64le*)
|
||||
echo 'mips64le'
|
||||
;;
|
||||
*mips64*)
|
||||
echo 'mips64'
|
||||
;;
|
||||
*mipsle*)
|
||||
echo 'mipsle'
|
||||
;;
|
||||
*mips*)
|
||||
echo 'mips'
|
||||
;;
|
||||
*s390x*)
|
||||
echo 's390x'
|
||||
;;
|
||||
ppc64le)
|
||||
echo 'ppc64le'
|
||||
;;
|
||||
ppc64)
|
||||
echo 'ppc64'
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
downloadV2Ray(){
|
||||
rm -rf /tmp/v2ray
|
||||
mkdir -p /tmp/v2ray
|
||||
if [[ "${DIST_SRC}" == "jsdelivr" ]]; then
|
||||
DOWNLOAD_LINK="https://cdn.jsdelivr.net/gh/v2ray/dist/v2ray-linux-${VDIS}.zip"
|
||||
else
|
||||
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${NEW_VER}/v2ray-linux-${VDIS}.zip"
|
||||
fi
|
||||
colorEcho ${BLUE} "Downloading V2Ray: ${DOWNLOAD_LINK}"
|
||||
curl ${PROXY} -L -H "Cache-Control: no-cache" -o ${ZIPFILE} ${DOWNLOAD_LINK}
|
||||
if [ $? != 0 ];then
|
||||
colorEcho ${RED} "Failed to download! Please check your network or try again."
|
||||
return 3
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
installSoftware(){
|
||||
|
||||
for software in $@
|
||||
do
|
||||
COMPONENT=$1
|
||||
if [[ -n `command -v $COMPONENT` ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
getPMT
|
||||
if [[ $? -eq 1 ]]; then
|
||||
colorEcho ${RED} "The system package manager tool isn't APT or YUM, please install ${COMPONENT} manually."
|
||||
return 1
|
||||
fi
|
||||
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "Updating software repo"
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
|
||||
colorEcho ${BLUE} "Installing ${COMPONENT}"
|
||||
$CMD_INSTALL $COMPONENT
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to install ${COMPONENT}. Please install it manually."
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
done
|
||||
}
|
||||
|
||||
# return 1: not apt, yum, or zypper
|
||||
getPMT(){
|
||||
if [[ -n `command -v apt-get` ]];then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
elif [[ -n `command -v yum` ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
elif [[ -n `command -v zypper` ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
extract(){
|
||||
colorEcho ${BLUE}"Extracting V2Ray package to /tmp/v2ray."
|
||||
mkdir -p /tmp/v2ray
|
||||
unzip $1 -d ${VSRC_ROOT}
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to extract V2Ray."
|
||||
return 2
|
||||
fi
|
||||
if [[ -d "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}" ]]; then
|
||||
VSRC_ROOT="/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
normalizeVersion() {
|
||||
if [ -n "$1" ]; then
|
||||
case "$1" in
|
||||
v*)
|
||||
echo "$1"
|
||||
;;
|
||||
*)
|
||||
echo "v$1"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# 1: new V2Ray. 0: no. 2: not installed. 3: check failed. 4: don't check.
|
||||
getVersion(){
|
||||
if [[ -n "$VERSION" ]]; then
|
||||
NEW_VER="$(normalizeVersion "$VERSION")"
|
||||
return 4
|
||||
else
|
||||
VER="$(/usr/bin/v2ray/v2ray -version 2>/dev/null)"
|
||||
RETVAL=$?
|
||||
CUR_VER="$(normalizeVersion "$(echo "$VER" | head -n 1 | cut -d " " -f2)")"
|
||||
TAG_URL="https://api.github.com/repos/v2ray/v2ray-core/releases/latest"
|
||||
NEW_VER="$(normalizeVersion "$(curl ${PROXY} -s "${TAG_URL}" --connect-timeout 10 | grep 'tag_name' | cut -d\" -f26)")"
|
||||
|
||||
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then
|
||||
colorEcho ${RED} "Failed to fetch release information. Please check your network or try again."
|
||||
return 3
|
||||
elif [[ $RETVAL -ne 0 ]];then
|
||||
return 2
|
||||
elif [[ $NEW_VER != $CUR_VER ]];then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
stopV2ray(){
|
||||
colorEcho ${BLUE} "Shutting down V2Ray service."
|
||||
if [[ -n "${SYSTEMCTL_CMD}" ]] || [[ -f "/lib/systemd/system/v2ray.service" ]] || [[ -f "/etc/systemd/system/v2ray.service" ]]; then
|
||||
${SYSTEMCTL_CMD} stop v2ray
|
||||
elif [[ -n "${SERVICE_CMD}" ]] || [[ -f "/etc/init.d/v2ray" ]]; then
|
||||
${SERVICE_CMD} v2ray stop
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "Failed to shutdown V2Ray service."
|
||||
return 2
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
startV2ray(){
|
||||
if [ -n "${SYSTEMCTL_CMD}" ] && [[ -f "/lib/systemd/system/v2ray.service" || -f "/etc/systemd/system/v2ray.service" ]]; then
|
||||
${SYSTEMCTL_CMD} start v2ray
|
||||
elif [ -n "${SERVICE_CMD}" ] && [ -f "/etc/init.d/v2ray" ]; then
|
||||
${SERVICE_CMD} v2ray start
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "Failed to start V2Ray service."
|
||||
return 2
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
copyFile() {
|
||||
NAME=$1
|
||||
ERROR=`cp "${VSRC_ROOT}/${NAME}" "/usr/bin/v2ray/${NAME}" 2>&1`
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "${ERROR}"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
makeExecutable() {
|
||||
chmod +x "/usr/bin/v2ray/$1"
|
||||
}
|
||||
|
||||
installV2Ray(){
|
||||
# Install V2Ray binary to /usr/bin/v2ray
|
||||
mkdir -p /usr/bin/v2ray
|
||||
copyFile v2ray
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to copy V2Ray binary and resources."
|
||||
return 1
|
||||
fi
|
||||
makeExecutable v2ray
|
||||
copyFile v2ctl && makeExecutable v2ctl
|
||||
copyFile geoip.dat
|
||||
copyFile geosite.dat
|
||||
|
||||
# Install V2Ray server config to /etc/v2ray
|
||||
if [[ ! -f "/etc/v2ray/config.json" ]]; then
|
||||
mkdir -p /etc/v2ray
|
||||
mkdir -p /var/log/v2ray
|
||||
cp "${VSRC_ROOT}/vpoint_vmess_freedom.json" "/etc/v2ray/config.json"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${YELLOW} "Failed to create V2Ray configuration file. Please create it manually."
|
||||
return 1
|
||||
fi
|
||||
let PORT=$RANDOM+10000
|
||||
UUID=$(cat /proc/sys/kernel/random/uuid)
|
||||
|
||||
sed -i "s/10086/${PORT}/g" "/etc/v2ray/config.json"
|
||||
sed -i "s/23ad6b10-8d1a-40f7-8ad0-e3e35cd38297/${UUID}/g" "/etc/v2ray/config.json"
|
||||
|
||||
colorEcho ${BLUE} "PORT:${PORT}"
|
||||
colorEcho ${BLUE} "UUID:${UUID}"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
installInitScript(){
|
||||
if [[ -n "${SYSTEMCTL_CMD}" ]] && [[ ! -f "/etc/systemd/system/v2ray.service" && ! -f "/lib/systemd/system/v2ray.service" ]]; then
|
||||
cp "${VSRC_ROOT}/systemd/v2ray.service" "/etc/systemd/system/"
|
||||
systemctl daemon-reload
|
||||
systemctl enable v2ray.service
|
||||
elif [[ -n "${SERVICE_CMD}" ]] && [[ ! -f "/etc/init.d/v2ray" ]]; then
|
||||
installSoftware "daemon" || return $?
|
||||
cp "${VSRC_ROOT}/systemv/v2ray" "/etc/init.d/v2ray"
|
||||
chmod +x "/etc/init.d/v2ray"
|
||||
update-rc.d v2ray defaults
|
||||
fi
|
||||
}
|
||||
|
||||
Help(){
|
||||
cat - 1>& 2 << EOF
|
||||
./install-release.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
|
||||
-h, --help Show help
|
||||
-p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc
|
||||
-f, --force Force install
|
||||
--version Install a particular version, use --version v3.15
|
||||
-l, --local Install from a local file
|
||||
--remove Remove installed V2Ray
|
||||
-c, --check Check for update
|
||||
EOF
|
||||
}
|
||||
|
||||
remove(){
|
||||
if [[ -n "${SYSTEMCTL_CMD}" ]] && [[ -f "/etc/systemd/system/v2ray.service" ]];then
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
stopV2ray
|
||||
fi
|
||||
systemctl disable v2ray.service
|
||||
rm -rf "/usr/bin/v2ray" "/etc/systemd/system/v2ray.service"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to remove V2Ray."
|
||||
return 0
|
||||
else
|
||||
colorEcho ${GREEN} "Removed V2Ray successfully."
|
||||
colorEcho ${BLUE} "If necessary, please remove configuration file and log file manually."
|
||||
return 0
|
||||
fi
|
||||
elif [[ -n "${SYSTEMCTL_CMD}" ]] && [[ -f "/lib/systemd/system/v2ray.service" ]];then
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
stopV2ray
|
||||
fi
|
||||
systemctl disable v2ray.service
|
||||
rm -rf "/usr/bin/v2ray" "/lib/systemd/system/v2ray.service"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to remove V2Ray."
|
||||
return 0
|
||||
else
|
||||
colorEcho ${GREEN} "Removed V2Ray successfully."
|
||||
colorEcho ${BLUE} "If necessary, please remove configuration file and log file manually."
|
||||
return 0
|
||||
fi
|
||||
elif [[ -n "${SERVICE_CMD}" ]] && [[ -f "/etc/init.d/v2ray" ]]; then
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
stopV2ray
|
||||
fi
|
||||
rm -rf "/usr/bin/v2ray" "/etc/init.d/v2ray"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "Failed to remove V2Ray."
|
||||
return 0
|
||||
else
|
||||
colorEcho ${GREEN} "Removed V2Ray successfully."
|
||||
colorEcho ${BLUE} "If necessary, please remove configuration file and log file manually."
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
colorEcho ${YELLOW} "V2Ray not found."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
checkUpdate(){
|
||||
echo "Checking for update."
|
||||
VERSION=""
|
||||
getVersion
|
||||
RETVAL="$?"
|
||||
if [[ $RETVAL -eq 1 ]]; then
|
||||
colorEcho ${BLUE} "Found new version ${NEW_VER} for V2Ray.(Current version:$CUR_VER)"
|
||||
elif [[ $RETVAL -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "No new version. Current version is ${NEW_VER}."
|
||||
elif [[ $RETVAL -eq 2 ]]; then
|
||||
colorEcho ${YELLOW} "No V2Ray installed."
|
||||
colorEcho ${BLUE} "The newest version for V2Ray is ${NEW_VER}."
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
main(){
|
||||
#helping information
|
||||
[[ "$HELP" == "1" ]] && Help && return
|
||||
[[ "$CHECK" == "1" ]] && checkUpdate && return
|
||||
[[ "$REMOVE" == "1" ]] && remove && return
|
||||
|
||||
local ARCH=$(uname -m)
|
||||
VDIS="$(archAffix)"
|
||||
|
||||
# extract local file
|
||||
if [[ $LOCAL_INSTALL -eq 1 ]]; then
|
||||
colorEcho ${YELLOW} "Installing V2Ray via local file. Please make sure the file is a valid V2Ray package, as we are not able to determine that."
|
||||
NEW_VER=local
|
||||
installSoftware unzip || return $?
|
||||
rm -rf /tmp/v2ray
|
||||
extract $LOCAL || return $?
|
||||
#FILEVDIS=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f4`
|
||||
#SYSTEM=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f3`
|
||||
#if [[ ${SYSTEM} != "linux" ]]; then
|
||||
# colorEcho ${RED} "The local V2Ray can not be installed in linux."
|
||||
# return 1
|
||||
#elif [[ ${FILEVDIS} != ${VDIS} ]]; then
|
||||
# colorEcho ${RED} "The local V2Ray can not be installed in ${ARCH} system."
|
||||
# return 1
|
||||
#else
|
||||
# NEW_VER=`ls /tmp/v2ray |grep v2ray-v |cut -d "-" -f2`
|
||||
#fi
|
||||
else
|
||||
# download via network and extract
|
||||
installSoftware "curl" || return $?
|
||||
getVersion
|
||||
RETVAL="$?"
|
||||
if [[ $RETVAL == 0 ]] && [[ "$FORCE" != "1" ]]; then
|
||||
colorEcho ${BLUE} "Latest version ${CUR_VER} is already installed."
|
||||
if [ -n "${ERROR_IF_UPTODATE}" ]; then
|
||||
return 10
|
||||
fi
|
||||
return
|
||||
elif [[ $RETVAL == 3 ]]; then
|
||||
return 3
|
||||
else
|
||||
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}"
|
||||
downloadV2Ray || return $?
|
||||
installSoftware unzip || return $?
|
||||
extract ${ZIPFILE} || return $?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${EXTRACT_ONLY}" ]; then
|
||||
colorEcho ${GREEN} "V2Ray extracted to ${VSRC_ROOT}, and exiting..."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if pgrep "v2ray" > /dev/null ; then
|
||||
V2RAY_RUNNING=1
|
||||
stopV2ray
|
||||
fi
|
||||
installV2Ray || return $?
|
||||
installInitScript || return $?
|
||||
if [[ ${V2RAY_RUNNING} -eq 1 ]];then
|
||||
colorEcho ${BLUE} "Restarting V2Ray service."
|
||||
startV2ray
|
||||
fi
|
||||
colorEcho ${GREEN} "V2Ray ${NEW_VER} is installed."
|
||||
rm -rf /tmp/v2ray
|
||||
return 0
|
||||
}
|
||||
|
||||
main
|
||||
49
基础脚本/unixbench.sh
Normal file
49
基础脚本/unixbench.sh
Normal file
@@ -0,0 +1,49 @@
|
||||
#! /bin/bash
|
||||
#==============================================================#
|
||||
# Description: Unixbench script #
|
||||
# Author: Teddysun <i@teddysun.com> #
|
||||
# Intro: https://teddysun.com/245.html #
|
||||
#==============================================================#
|
||||
cur_dir=/opt/unixbench
|
||||
|
||||
# Check System
|
||||
[[ $EUID -ne 0 ]] && echo 'Error: This script must be run as root!' && exit 1
|
||||
[[ -f /etc/redhat-release ]] && os='centos'
|
||||
[[ ! -z "`egrep -i debian /etc/issue`" ]] && os='debian'
|
||||
[[ ! -z "`egrep -i ubuntu /etc/issue`" ]] && os='ubuntu'
|
||||
[[ "$os" == '' ]] && echo 'Error: Your system is not supported to run it!' && exit 1
|
||||
|
||||
# Install necessary libaries
|
||||
if [ "$os" == 'centos' ]; then
|
||||
yum -y install make automake gcc autoconf gcc-c++ time perl-Time-HiRes
|
||||
else
|
||||
apt-get -y update
|
||||
apt-get -y install make automake gcc autoconf time perl
|
||||
fi
|
||||
|
||||
# Create new soft download dir
|
||||
mkdir -p ${cur_dir}
|
||||
cd ${cur_dir}
|
||||
|
||||
# Download UnixBench5.1.3
|
||||
if [ -s UnixBench5.1.3.tgz ]; then
|
||||
echo "UnixBench5.1.3.tgz [found]"
|
||||
else
|
||||
echo "UnixBench5.1.3.tgz not found!!!download now..."
|
||||
if ! wget -c https://dl.lamp.sh/files/UnixBench5.1.3.tgz; then
|
||||
echo "Failed to download UnixBench5.1.3.tgz, please download it to ${cur_dir} directory manually and try again."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
tar -zxvf UnixBench5.1.3.tgz && rm -f UnixBench5.1.3.tgz
|
||||
cd UnixBench/
|
||||
|
||||
#Run unixbench
|
||||
make
|
||||
./Run
|
||||
|
||||
echo
|
||||
echo
|
||||
echo "======= Script description and score comparison completed! ======= "
|
||||
echo
|
||||
echo
|
||||
3
基础脚本/关闭防火墙.sh
Normal file
3
基础脚本/关闭防火墙.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
4
基础脚本/去掉注释.sh
Normal file
4
基础脚本/去掉注释.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
sed -i -r '/^[ ]*#/d;/^$/d' /etc/haproxy/haproxy.cfg #修改配置文件去掉注释,或者你可以直接复制我的代码
|
||||
|
||||
|
||||
sed -i -r '/^[ ]*#/d;/^$/d'#Port 22
|
||||
27
基础脚本/参数传递.sh
Normal file
27
基础脚本/参数传递.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 输出参数索引
|
||||
echo "OPTIND starts at $OPTIND"
|
||||
# 接收参数
|
||||
while getopts ":pq:" optname
|
||||
do
|
||||
case "$optname" in
|
||||
"p")
|
||||
echo "Option $optname is specified"
|
||||
;;
|
||||
"q")
|
||||
echo "Option $optname has value $OPTARG"
|
||||
;;
|
||||
"?")
|
||||
echo "Unknown option $OPTARG"
|
||||
;;
|
||||
":")
|
||||
echo "No argument value for option $OPTARG"
|
||||
;;
|
||||
*)
|
||||
# Should not occur
|
||||
echo "Unknown error while processing options"
|
||||
;;
|
||||
esac
|
||||
echo "OPtIND now is $OPTIND"
|
||||
done
|
||||
67
基础脚本/安装单个软件.sh
Normal file
67
基础脚本/安装单个软件.sh
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
|
||||
#########color code#############
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
###############color echo func#################
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
# 判断系统的包管理工具 apt, yum, or zypper
|
||||
getPackageManageTool(){
|
||||
if [[ -n `command -v apt-get` ]];then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
elif [[ -n `command -v yum` ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
elif [[ -n `command -v zypper` ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 安装所需要的程序,及依赖程序
|
||||
installDemands(){
|
||||
COMPONENT=$1
|
||||
if [[ -n `command -v $COMPONENT` ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
getPackageManageTool
|
||||
if [[ $? -eq 1 ]]; then
|
||||
colorEcho ${RED} "The system package manager tool isn't APT or YUM, please install ${COMPONENT} manually."
|
||||
return 1
|
||||
fi
|
||||
|
||||
### 更新程序引索
|
||||
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "正在更新软件包管理..."
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
|
||||
colorEcho ${BLUE} "正在安装 ${COMPONENT}.."
|
||||
$CMD_INSTALL $COMPONENT
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "安装 ${COMPONENT} 失败. 请手动安装该程序."
|
||||
return 1
|
||||
else
|
||||
colorEcho ${GREEN} "已经成功安装 ${COMPONENT}."
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 下面只是例子,使用时在主函数中应用之
|
||||
installDemands "iftop" || return $?
|
||||
76
基础脚本/安装多个软件.sh
Normal file
76
基础脚本/安装多个软件.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
CMD_INSTALL=""
|
||||
CMD_UPDATE=""
|
||||
CMD_REMOVE=""
|
||||
SOFTWARE_UPDATED=0
|
||||
|
||||
#########color code#############
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
###############color echo func#################
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
# 判断系统的包管理工具 apt, yum, or zypper
|
||||
getPackageManageTool(){
|
||||
if [[ -n `command -v apt-get` ]];then
|
||||
CMD_INSTALL="apt-get -y -qq install"
|
||||
CMD_UPDATE="apt-get -qq update"
|
||||
CMD_REMOVE="apt-get -y remove"
|
||||
elif [[ -n `command -v yum` ]]; then
|
||||
CMD_INSTALL="yum -y -q install"
|
||||
CMD_UPDATE="yum -q makecache"
|
||||
CMD_REMOVE="yum -y remove"
|
||||
elif [[ -n `command -v zypper` ]]; then
|
||||
CMD_INSTALL="zypper -y install"
|
||||
CMD_UPDATE="zypper ref"
|
||||
CMD_REMOVE="zypper -y remove"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
## 安装所需要的程序,及依赖程序
|
||||
installDemandSoftwares(){
|
||||
# 检查系统包管理方式,更新包
|
||||
getPackageManageTool
|
||||
if [[ $? -eq 1 ]]; then
|
||||
colorEcho ${RED} "系统的包管理不是 APT or YUM, 请手动安装所需要的软件."
|
||||
return 1
|
||||
fi
|
||||
|
||||
### 更新程序引索
|
||||
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then
|
||||
colorEcho ${BLUE} "正在更新软件包管理..."
|
||||
$CMD_UPDATE
|
||||
SOFTWARE_UPDATED=1
|
||||
fi
|
||||
|
||||
for software in $@
|
||||
do
|
||||
## 安装该软件
|
||||
if [[ -n `command -v ${software}` ]]; then
|
||||
colorEcho ${GREEN} "${software}已经安装了...跳过..."
|
||||
else
|
||||
colorEcho ${BLUE} "正在安装 ${software}.."
|
||||
$CMD_INSTALL ${software}
|
||||
|
||||
## 判断该软件是否安装成功
|
||||
if [[ $? -ne 0 ]]; then
|
||||
colorEcho ${RED} "安装 ${software} 失败. 请手动安装该程序."
|
||||
return 1
|
||||
else
|
||||
colorEcho ${GREEN} "已经成功安装 ${software}."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
installDemandSoftwares iftop vim curl wget mtr
|
||||
66
基础脚本/检查系统版本.sh
Normal file
66
基础脚本/检查系统版本.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
### 为了文件美观,直接继承了fontColor.sh文件 #####
|
||||
|
||||
#######第一种方法########
|
||||
RED="31m" # Error message
|
||||
GREEN="32m" # Success message
|
||||
YELLOW="33m" # Warning message
|
||||
BLUE="36m" # Info message
|
||||
|
||||
check_root(){
|
||||
if [[ $EUID != 0 ]];then
|
||||
colorEcho ${RED} "当前非root账号(或没有root权限),无法继续操作,请更换root账号!"
|
||||
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限(执行后可能会提示输入root密码)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
####### 获取系统版本及64位或32位信息
|
||||
check_sys(){
|
||||
sys_bit=$(uname -m)
|
||||
case $sys_bit in
|
||||
i[36]86)
|
||||
os_bit="32"
|
||||
release="386"
|
||||
;;
|
||||
x86_64)
|
||||
os_bit="64"
|
||||
release="amd64"
|
||||
;;
|
||||
*armv6*)
|
||||
os_bit="arm"
|
||||
release="arm6"
|
||||
;;
|
||||
*armv7*)
|
||||
os_bit="arm"
|
||||
release="arm7"
|
||||
;;
|
||||
*aarch64* | *armv8*)
|
||||
os_bit="arm64"
|
||||
release="arm64"
|
||||
;;
|
||||
*)
|
||||
colorEcho ${RED} "
|
||||
哈哈……这个 辣鸡脚本 不支持你的系统。 (-_-) \n
|
||||
备注: 仅支持 Ubuntu 16+ / Debian 8+ / CentOS 7+ 系统
|
||||
" && exit 1
|
||||
;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
######## 颜色函数方法很精妙 ############
|
||||
colorEcho(){
|
||||
echo -e "\033[${1}${@:2}\033[0m" 1>& 2
|
||||
}
|
||||
|
||||
main(){
|
||||
check_root
|
||||
check_sys
|
||||
|
||||
colorEcho $GREEN "\t你现在正在以root的身份查看系统信息!"
|
||||
colorEcho $YELLOW "\t操作系统是${os_bit}位的,发行版本是${release}"
|
||||
}
|
||||
|
||||
main
|
||||
33
基础脚本/获取本机的公网IP.sh
Normal file
33
基础脚本/获取本机的公网IP.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 判断命令是否存在
|
||||
command_exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# 获取服务器的公网IP地址
|
||||
get_server_ip() {
|
||||
local server_ip=""
|
||||
local Network_Manage_Tool=""
|
||||
|
||||
if command_exists ip; then
|
||||
Network_Manage_Tool="$(ip addr)"
|
||||
elif command_exists ifconfig; then
|
||||
Network_Manage_Tool="$(ifconfig)"
|
||||
fi
|
||||
|
||||
server_ip=$(echo "$Network_Manage_Tool" | \
|
||||
grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | \
|
||||
grep -vE "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | \
|
||||
head -n 1)
|
||||
|
||||
# 自动获取失败时,通过网站提供的 API 获取外网地址
|
||||
if [ -z "$server_ip" ]; then
|
||||
server_ip="$(wget -qO- --no-check-certificate https://ipv4.icanhazip.com)"
|
||||
server_ip=$(curl -s https://myip.ipip.net | awk '{print$2}' | cut -d":" -f2)
|
||||
fi
|
||||
|
||||
echo "$server_ip"
|
||||
}
|
||||
|
||||
get_server_ip
|
||||
55
基础脚本/获取本机的内网IP.sh
Normal file
55
基础脚本/获取本机的内网IP.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
InnerIPv4CIDR=""
|
||||
InnerIPv6CIDR=""
|
||||
|
||||
InnerIPv4=""
|
||||
InnerIPv6=""
|
||||
|
||||
|
||||
# 获取服务器的公网IP地址
|
||||
get_Internal_IP_CIDR() {
|
||||
|
||||
local interface_prefix=("[[:space:]]eth[0-9]{1,2}" "[[:space:]]ens[0-9]{1,3}" "[[:space:]]eno[0-9]{1,3}" "[[:space:]]enp[0-9]{1,2}")
|
||||
local real_interface="eth90"
|
||||
|
||||
for interface in "${interface_prefix[@]}"; do
|
||||
echo $(ip link show) | grep -oE ${interface} | head -1
|
||||
if [[ $? -eq 0 ]]; then
|
||||
real_interface=$(echo $(ip link show) | grep -oE ${interface} | head -1 | cut -d" " -f2)
|
||||
echo "当前主机的真实内网网卡为 => [$real_interface]"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 提取IPv4地址(CIDR格式)
|
||||
local ipv4_regex="inet[[:space:]](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}"
|
||||
|
||||
# 提取IPv6地址(CIDR格式)
|
||||
loca ipv6_regex="inet6[[:space:]]([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}"
|
||||
|
||||
# 查找IPv4地址
|
||||
local inner_ipv4=$(echo $(ip addr show $real_interface) | grep -oE $ipv4_regex | cut -d" " -f2)
|
||||
InnerIPv4CIDR=$inner_ipv4
|
||||
echo "Interface: $real_interface, IPv4 Address: $inner_ipv4"
|
||||
|
||||
# 查找IPv6地址
|
||||
local inner_ipv6=$(echo $(ip addr show $real_interface) | grep -oE $ipv6_regex | cut -d" " -f2)
|
||||
InnerIPv6CIDR=$inner_ipv6
|
||||
echo "Interface: $real_interface, IPv4 Address: $inner_ipv6"
|
||||
|
||||
}
|
||||
|
||||
get_Internal_IP_() {
|
||||
|
||||
get_Internal_IP_CIDR
|
||||
|
||||
InnerIPv4=$(echo $InnerIPv4CIDR | cut -d "/" -f1)
|
||||
InnerIPv6=$(echo $InnerIPv6CIDR | cut -d "/" -f1)
|
||||
|
||||
echo "服务器的内网IPv4地址为 $InnerIPv4"
|
||||
echo "服务器的内网IPv6地址为 $InnerIPv6"
|
||||
|
||||
}
|
||||
|
||||
get_Internal_IP_CIDR
|
||||
66
基础脚本/读取脚本传递参数.sh
Normal file
66
基础脚本/读取脚本传递参数.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 当运行时, 可以传入额外的参数
|
||||
## ./runParams.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
|
||||
|
||||
Help(){
|
||||
cat - 1>& 2 << EOF
|
||||
./install-release.sh [-h] [-c] [--remove] [-p proxy] [-f] [--version vx.y.z] [-l file]
|
||||
-h, --help Show help
|
||||
-p, --proxy To download through a proxy server, use -p socks5://127.0.0.1:1080 or -p http://127.0.0.1:3128 etc
|
||||
-f, --force Force install
|
||||
--version Install a particular version, use --version v3.15
|
||||
-l, --local Install from a local file
|
||||
--remove Remove installed V2Ray
|
||||
-c, --check Check for update
|
||||
EOF
|
||||
}
|
||||
|
||||
#########################
|
||||
while [[ $# > 0 ]]; do
|
||||
case "$1" in
|
||||
-p|--proxy)
|
||||
PROXY="-x ${2}"
|
||||
shift # past argument
|
||||
;;
|
||||
-h|--help)
|
||||
HELP="1"
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE="1"
|
||||
;;
|
||||
-c|--check)
|
||||
CHECK="1"
|
||||
;;
|
||||
--remove)
|
||||
REMOVE="1"
|
||||
;;
|
||||
--version)
|
||||
VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
--extract)
|
||||
VSRC_ROOT="$2"
|
||||
shift
|
||||
;;
|
||||
--extractonly)
|
||||
EXTRACT_ONLY="1"
|
||||
;;
|
||||
-l|--local)
|
||||
LOCAL="$2"
|
||||
LOCAL_INSTALL="1"
|
||||
shift
|
||||
;;
|
||||
--source)
|
||||
DIST_SRC="$2"
|
||||
shift
|
||||
;;
|
||||
--errifuptodate)
|
||||
ERROR_IF_UPTODATE="1"
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
Reference in New Issue
Block a user