Compare commits
89 Commits
147670f24f
...
e1d14e68cb
Author | SHA1 | Date | |
---|---|---|---|
e1d14e68cb | |||
6d17986574 | |||
5db4586f2b | |||
b460838426 | |||
f6896bdb28 | |||
35c77a1a01 | |||
db267ea0b9 | |||
8b5d304ec4 | |||
1e0df6eaed | |||
edc0c5b106 | |||
358438cef0 | |||
6da44d3c14 | |||
651c344931 | |||
b13ba8591c | |||
0234d2207e | |||
2b367eb43a | |||
6555544668 | |||
0f0a8edc6c | |||
95047371a8 | |||
9bb34dacba | |||
de7c16a890 | |||
87b977d05f | |||
98f4fa8adf | |||
08a8d2f979 | |||
71444c16ec | |||
1dc291725b | |||
470500cc0d | |||
ed14128c30 | |||
fb8446eb3f | |||
a4f8d8dfb0 | |||
8d0a88e02e | |||
bfae54713a | |||
560e42c27d | |||
aca18a9c0a | |||
0c98172c80 | |||
1ed19e66ae | |||
848151a728 | |||
640138a8d1 | |||
2043b3d997 | |||
99a1ea54a1 | |||
b196fdacee | |||
8f7d0f4099 | |||
88fa604f7d | |||
7a312c9a89 | |||
dcd32d33d9 | |||
3f34cf7561 | |||
9b3925ac38 | |||
42857e4e5d | |||
61ed8931b0 | |||
bc8ddeda81 | |||
1681010bf6 | |||
a6b5e1f220 | |||
50e6603d70 | |||
73dad9aa3f | |||
84ec270e0b | |||
ac8e926273 | |||
167767ccc2 | |||
ac526c51b9 | |||
d73a9e969b | |||
e9f55a5cf5 | |||
910f8c1dad | |||
824c166209 | |||
839d4006aa | |||
90885a398e | |||
d1773cce27 | |||
79b0c6c28d | |||
7e937c202e | |||
03855ea490 | |||
e31bd3c853 | |||
74bc4baae8 | |||
69296c2bec | |||
de69bb307a | |||
55e856934f | |||
debee99f00 | |||
fd471b7941 | |||
99909e8c14 | |||
9f27db43cc | |||
3fdd2a1d0d | |||
5f9cc680b3 | |||
a107eb6bf5 | |||
3df59d74ae | |||
192a8a145f | |||
29846aa2b5 | |||
af9cc15020 | |||
e28a0643d0 | |||
4046e894ff | |||
86e051a714 | |||
d84f312d58 | |||
23a48b3cb5 |
7
Config/Automation/Installs/acme_update.sh
Normal file
7
Config/Automation/Installs/acme_update.sh
Normal file
@ -0,0 +1,7 @@
|
||||
declare path="$1"
|
||||
|
||||
cat > "${path}/acme_update.sh" << EOF
|
||||
#!/bin/bash
|
||||
${HOME}/.acme.sh/acme.sh --upgrade
|
||||
${HOME}/.acme.sh/acme.sh --renew-all
|
||||
EOF
|
@ -8,10 +8,6 @@ declare aliyun_pick
|
||||
declare ignore=1
|
||||
|
||||
|
||||
if [[ -f "${path}/backup.sh" ]];then
|
||||
echo "该路径文件已经存在"
|
||||
fi
|
||||
|
||||
read -p "请输入数据目录,默认 /var/www :" web_path
|
||||
if [[ -z ${web_path} ]];then
|
||||
web_path='/var/www'
|
||||
@ -23,7 +19,7 @@ for item in "$web_path"/* ; do
|
||||
echo "${item_name}"
|
||||
done
|
||||
|
||||
echo "请输入需要屏蔽的目录用逗号隔开"
|
||||
echo "请输入需要屏蔽的目录用 空格 隔开"
|
||||
read -p "请输入:" ignore
|
||||
|
||||
|
@ -1,17 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare path_script=$1
|
||||
declare path_local=$1
|
||||
declare pick
|
||||
echo "========Automation========"
|
||||
declare file_name
|
||||
echo "========$(basename $0 .sh)========"
|
||||
declare print_number=0
|
||||
declare -a print_array
|
||||
for i in "${path_script}/Config/Automation"/*;do
|
||||
for i in "${path_local}"/*;do
|
||||
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
||||
if [[ $file_name == "test" || $file_name == "menu" ]]; then
|
||||
continue
|
||||
fi
|
||||
print_number=$((print_number + 1))
|
||||
print_array[$print_number]=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
||||
echo "${print_number}.${print_array[$print_number]}"
|
||||
print_array[$print_number]=$file_name
|
||||
echo "${print_number}.${file_name}"
|
||||
done
|
||||
echo "输入其他任意返回主页"
|
||||
echo "========Automation========"
|
||||
read -p "请输入:" pick
|
||||
|
||||
if [[ ! ${pick} =~ [1-$print_number] ]];then
|
||||
@ -49,13 +52,17 @@ if [[ "$cron" == '* * * * * ' ]];then
|
||||
exit
|
||||
fi
|
||||
|
||||
bash "${path_script}/Config/Automation/${print_array[pick]}.sh" "$path"
|
||||
if [[ -f "${path_local}/${print_array[pick]}.sh" ]];then
|
||||
echo "该路径文件已经存在"
|
||||
fi
|
||||
|
||||
bash "${path_local}/${print_array[pick]}.sh" "$path"
|
||||
|
||||
chmod +x "${path}/${print_array[pick]}.sh"
|
||||
declare cron_job="${cron} ${path}/${print_array[pick]}.sh"
|
||||
(crontab -l 2>/dev/null | grep -v "${print_array[pick]}.sh") | sudo crontab -
|
||||
(crontab -l 2>/dev/null; echo "$cron_job") | sudo crontab -
|
||||
(crontab -l 2>/dev/null | grep -v "${print_array[pick]}.sh") | crontab -
|
||||
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
|
||||
|
||||
sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败"
|
||||
systemctl restart cron 2>> /dev/null || echo "自动任务重启失败"
|
||||
|
||||
echo "配置完成"
|
@ -5,9 +5,7 @@ if ! command -v docker &> /dev/null; then
|
||||
echo "docker未安装"
|
||||
exit
|
||||
fi
|
||||
if [[ -f "${path}/up-docker_compose.sh" ]];then
|
||||
echo "该路径文件已经存在"
|
||||
fi
|
||||
|
||||
declare web_path
|
||||
read -p "请输入数据目录,默认 /var/www :" web_path
|
||||
if [[ -z ${web_path} ]];then
|
@ -1,9 +1,5 @@
|
||||
declare path="$1"
|
||||
|
||||
if [[ -f "${path}/update.sh" ]];then
|
||||
echo "该路径文件已经存在"
|
||||
fi
|
||||
|
||||
echo '#!/bin/bash' > "${path}/update.sh"
|
||||
|
||||
if [[ -f "/usr/bin/apt" ]];then
|
@ -1,11 +0,0 @@
|
||||
declare path="$1"
|
||||
|
||||
if [[ -f "${path}/acme.sh" ]];then
|
||||
echo "该路径文件已经存在"
|
||||
fi
|
||||
|
||||
cat > "${path}/acme.sh" << EOF
|
||||
#!/bin/bash
|
||||
${HOME}/.acme.sh/acme.sh --upgrade
|
||||
${HOME}/.acme.sh/acme.sh --renew-all
|
||||
EOF
|
@ -14,7 +14,7 @@ services:
|
||||
ports:
|
||||
- "${port}:5244"
|
||||
EOF
|
||||
sudo docker compose up -d || "安装失败" $$ exit
|
||||
declare password=$( sudo docker exec -it alist ./alist admin random | grep password | awk '{print $4}')
|
||||
docker compose up -d || "安装失败" $$ exit
|
||||
declare password=$( docker exec -it alist ./alist admin random | grep password | awk '{print $4}')
|
||||
echo "账号:admin"
|
||||
echo "密码:${password}"
|
@ -1,5 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! command -v sudo &> /dev/null; then
|
||||
echo "该软件需要安装sudo才能正常安装"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare path=$1
|
||||
declare port=$2
|
||||
|
||||
@ -52,6 +57,7 @@ services:
|
||||
volumes:
|
||||
- ./mysql:/var/lib/mysql
|
||||
EOF
|
||||
chown -R git:git $path
|
||||
sudo docker compose up -d
|
||||
|
||||
sudo -u git ssh -p $(( port+22 )) -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
|
57
Config/Docker/Softwares/menu.sh
Normal file
57
Config/Docker/Softwares/menu.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
declare path_local=$1
|
||||
declare pick
|
||||
declare file_name
|
||||
echo "========$(basename $0 .sh)========"
|
||||
declare print_number=0
|
||||
declare -a print_array
|
||||
for i in "${path_local}"/*;do
|
||||
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
||||
if [[ $file_name == "test" || $file_name == "menu" ]]; then
|
||||
continue
|
||||
fi
|
||||
print_number=$((print_number + 1))
|
||||
print_array[$print_number]=$file_name
|
||||
echo "${print_number}.${file_name}"
|
||||
done
|
||||
echo "输入其他任意返回主页"
|
||||
read -p "请输入:" pick
|
||||
|
||||
if [[ ! ${pick} =~ [1-$print_number] ]];then
|
||||
exit
|
||||
fi
|
||||
|
||||
declare file_path
|
||||
read -p "请输入软件储存位置,默认 /var/www/${print_array[${pick}]} :" file_path
|
||||
if [[ -z ${file_path} ]];then
|
||||
file_path="/var/www/${print_array[${pick}]}"
|
||||
fi
|
||||
|
||||
if [[ ! -d "$file_path" ]];then
|
||||
sudo mkdir -p "$file_path" || { echo "目录创建失败"; exit 1; }
|
||||
elif [[ ! -z "$(find "$file_path" -mindepth 1 -print -quit)" ]];then
|
||||
echo "该目录存有文件"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare dport=$(($RANDOM % 9000 + 1000))
|
||||
|
||||
while ss -tuln | grep $dport &> /dev/null
|
||||
do
|
||||
dport=$(($RANDOM % 9000 + 1000))
|
||||
done
|
||||
|
||||
declare port
|
||||
read -p "请输入访问端口,默认 $dport :" port
|
||||
|
||||
if [[ -z $port ]];then
|
||||
port=$dport
|
||||
fi
|
||||
|
||||
if ss -tuln | grep $port &> /dev/null;then
|
||||
echo "端口已被占用"
|
||||
exit
|
||||
fi
|
||||
|
||||
bash "${path_local}/${print_array[pick]}.sh" "$file_path" "$port"
|
||||
echo "${print_array[${pick}]}安装完成,访问端口${port}"
|
@ -16,6 +16,6 @@ services:
|
||||
- ./data:/data
|
||||
- ./letsencrypt:/etc/letsencrypt
|
||||
EOF
|
||||
sudo docker compose up -d
|
||||
docker compose up -d
|
||||
echo "Email: admin@example.com"
|
||||
echo "Password: changeme"
|
@ -12,7 +12,7 @@ POSTGRES_PASSWORD="safeline"
|
||||
SUBNET_PREFIX=172.22.222
|
||||
IMAGE_PREFIX=swr.cn-east-3.myhuaweicloud.com/chaitin-safeline
|
||||
EOF
|
||||
sudo docker compose up -d || "安装失败" $$ exit
|
||||
docker compose up -d || "安装失败" $$ exit
|
||||
declare password=$( docker exec safeline-mgt resetadmin &> /dev/null | grep password | awk -F ":" '{print $2}' )
|
||||
echo "账号:admin"
|
||||
echo "密码:${password}"
|
@ -8,7 +8,7 @@ if [[ -z $password ]];then
|
||||
password="Siyuan"
|
||||
fi
|
||||
|
||||
sudo chown -R 1000:1000 $path
|
||||
chown -R 1000:1000 $path
|
||||
cd $path
|
||||
cat > "docker-compose.yml" << EOF
|
||||
version: "3.9"
|
||||
@ -27,5 +27,5 @@ services:
|
||||
- "--lang=zh_CN"
|
||||
- "--accessAuthCode=$password"
|
||||
EOF
|
||||
sudo docker compose up -d || "安装失败" $$ exit
|
||||
docker compose up -d || "安装失败" $$ exit
|
||||
echo "访问密码:$password"
|
@ -40,5 +40,5 @@ mv "$admin" "../admin"
|
||||
mv "$email" "../email"
|
||||
cd ..
|
||||
rm -rf vaultwarden-lang-zhcn-main
|
||||
sudo docker compose up -d || echo "安装失败" && exit
|
||||
docker compose up -d || echo "安装失败" && exit
|
||||
echo "需要反向代理,使用https,才能正常使用"
|
31
Config/Docker/image.sh
Normal file
31
Config/Docker/image.sh
Normal file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
echo "1.查看当前运行中的镜像"
|
||||
echo "2.停止镜像"
|
||||
echo "3.删除没有使用的镜像"
|
||||
|
||||
declare pick
|
||||
read -p "请输入:" pick
|
||||
|
||||
case $pick in
|
||||
'1')
|
||||
docker ps --format "{{.Names}}"
|
||||
;;
|
||||
'2')
|
||||
declare -a docker_arr=($(docker ps --format "{{.Names}}"))
|
||||
declare docker_number=0
|
||||
for i in "${docker_arr[@]}" ; do
|
||||
docker_number=$(( docker_number+1 ))
|
||||
echo "${docker_number}.${i}"
|
||||
done
|
||||
echo "要停止的镜像序号,多个镜像用 空格 隔开"
|
||||
read -p "请输入:" pick
|
||||
for i in $pick ; do
|
||||
if [[ $i =~ [1-$docker_number] ]]; then
|
||||
docker stop "${docker_arr[$(( i -1 ))]}"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
'3')
|
||||
docker system prune -af
|
||||
echo "清理完成"
|
||||
esac
|
42
Config/Docker/source.sh
Normal file
42
Config/Docker/source.sh
Normal file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "1.查看当前源"
|
||||
echo "2.换源"
|
||||
declare pick
|
||||
read -p "请输入:" pick
|
||||
|
||||
case $pick in
|
||||
'1')
|
||||
grep -oP '(https?://[^\"]+)' /etc/docker/daemon.json
|
||||
;;
|
||||
'2')
|
||||
declare -A img_dick
|
||||
declare -a img_number
|
||||
declare img_pick=0
|
||||
img_dick['Daocloud(默认)']='https://docker.m.daocloud.io'
|
||||
img_dick['官方']='docker.io'
|
||||
|
||||
for i in "${!img_dick[@]}";
|
||||
do
|
||||
img_pick=$(( img_pick+1 ))
|
||||
img_number[$img_pick]=$i
|
||||
echo "${img_pick}.${i}"
|
||||
done
|
||||
read -p "请输入要选择的镜像,也可直接输入镜像网站:" img_pick
|
||||
if [[ -z $img_pick ]];then
|
||||
declare url='https://docker.m.daocloud.io'
|
||||
elif [[ $img_pick =~ [\w\.]+ ]];then
|
||||
declare url=$img_pick
|
||||
elif [[ ${img_pick} =~ [1-${!img_dick[*]}] ]];then
|
||||
img_pick=${img_number[$img_pick]}
|
||||
declare url=${img_dick[$img_pick]}
|
||||
else
|
||||
echo "输入错误"
|
||||
exit
|
||||
fi
|
||||
echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json"
|
||||
systemctl restart docker 2>> /dev/null|| echo "docker 重启失败"&&exit
|
||||
echo "换源成功"
|
||||
|
||||
;;
|
||||
esac
|
5
Config/Docker/test.sh
Normal file
5
Config/Docker/test.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "docker未安装"
|
||||
exit 1
|
||||
fi
|
93
Config/Manage/install.sh
Normal file
93
Config/Manage/install.sh
Normal file
@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
if [[ $UID != 0 ]]; then
|
||||
echo "请以root权限执行该脚本"
|
||||
exit
|
||||
fi
|
||||
|
||||
if ! command -v git &> /dev/null; then
|
||||
if [[ -f "/usr/bin/apt-get" ]];then
|
||||
apt-get update -y
|
||||
apt-get install git -y
|
||||
elif [[ -f "/usr/bin/apt" ]];then
|
||||
apt update -y
|
||||
apt install git -y
|
||||
elif [[ -f "/usr/bin/pacman" ]];then
|
||||
pacman -Syu --noconfirm
|
||||
pacman -Sy --noconfirm git
|
||||
else
|
||||
echo "git未安装"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
declare path
|
||||
echo "请输入脚本的安装位置"
|
||||
read -p "默认 /var/script:" path
|
||||
if [[ -z $path ]];then
|
||||
path="/var/script"
|
||||
fi
|
||||
|
||||
mkdir -p "$path"
|
||||
rm -rf "$path/linuxtool"
|
||||
|
||||
declare -A url_dick
|
||||
declare -a url_arr
|
||||
declare url_number=0
|
||||
declare url_pick
|
||||
declare url
|
||||
echo "请选择脚本的下载地址"
|
||||
url_dick['github(default)']='https://github.com/lsy2246/linuxtool.git'
|
||||
url_dick['gitee']='https://gitee.com/lsy22/linuxtool.git'
|
||||
url_dick['gitlsy']='https://g.lsy22.com/lsy/linuxtool.git'
|
||||
|
||||
for i in "${!url_dick[@]}" ; do
|
||||
url_number=$(( url_number+1 ))
|
||||
url_arr[$url_number]=$i
|
||||
echo "${url_number}.${i}"
|
||||
done
|
||||
|
||||
read -p "请输入:" url_pick
|
||||
|
||||
if [[ $url_pick =~ [1-${#url_dick[@]}] ]]; then
|
||||
url=${url_dick[${url_arr[$url_pick]}]}
|
||||
else
|
||||
url='https://github.com/lsy2246/linuxtool.git'
|
||||
fi
|
||||
|
||||
echo "正在下载脚本中"
|
||||
git clone "$url" "$path/linuxtool" &> /dev/null
|
||||
|
||||
if ! [[ -d "${path}/linuxtool" ]];then
|
||||
echo "脚本下载失败"
|
||||
exit
|
||||
fi
|
||||
|
||||
chmod +x "$path/linuxtool/run.sh" &> /dev/null
|
||||
|
||||
if [[ -e "${HOME}/.bashrc" ]];then
|
||||
sed -i '/alias tool.*/d' "${HOME}/.bashrc"
|
||||
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "${HOME}/.bashrc"
|
||||
source "${HOME}/.bashrc" &> /dev/null
|
||||
fi
|
||||
|
||||
if [[ -e "${HOME}/.profile" ]];then
|
||||
sed -i '/alias tool.*/d' "${HOME}/.profile"
|
||||
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "${HOME}/.profile"
|
||||
source "${HOME}/.profile" &> /dev/null
|
||||
fi
|
||||
|
||||
if [[ -e "${HOME}/.zshrc" ]];then
|
||||
sed -i '/alias tool.*/d' "${HOME}/.zshrc"
|
||||
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "${HOME}/.zshrc"
|
||||
source "${HOME}/.zshrc" &> /dev/null
|
||||
fi
|
||||
|
||||
sed -i '/alias tool.*/d' "/etc/profile"
|
||||
echo "alias tool='$path/linuxtool/run.sh'" | cat >> "/etc/profile"
|
||||
|
||||
alias tool="$path/linuxtool/run.sh"
|
||||
|
||||
echo "工具箱已经安装成功"
|
||||
echo "位置:${path}/linuxtool"
|
||||
echo "命令:tool"
|
@ -1,100 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
|
||||
rm -rf ${HOME}/.acme.sh
|
||||
declare mail
|
||||
declare domain
|
||||
read -p "请输入用来申请域名的邮箱:" mail
|
||||
if [[ ! $mail =~ .*@.* ]];then
|
||||
echo "邮箱不合法"
|
||||
exit
|
||||
fi
|
||||
|
||||
curl https://get.acme.sh | sh -s "email=$mail"
|
||||
fi
|
||||
|
||||
declare domain_str=''
|
||||
echo "请输入需要申请SSL证书的域名"
|
||||
while(true);do
|
||||
read -p "不输入退出添加:" domain
|
||||
if [[ -z $domain ]];then
|
||||
break
|
||||
elif [[ ! $domain =~ [\w+\.]+ ]];then
|
||||
echo "域名不合法"
|
||||
exit
|
||||
else
|
||||
domain_str="$domain_str -d $domain"
|
||||
fi
|
||||
done
|
||||
if [[ -z $domain_str ]]; then
|
||||
echo "需要添加的域名不能为空"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare pick_mode
|
||||
echo "1.http验证"
|
||||
echo "2.dns验证"
|
||||
read -p "请选择验证模式:" pick_mode
|
||||
|
||||
case $pick_mode in
|
||||
'1')
|
||||
declare pick_start
|
||||
echo "请到服务器将80和443端口开启,将域名解析到本机"
|
||||
read -p "解析完成请输入 y:" pick_start
|
||||
if [[ ! $pick_start =~ [Yy] ]];then
|
||||
exit
|
||||
fi
|
||||
eval "${HOME}/.acme.sh/acme.sh --issue $domain_str --standalone"
|
||||
;;
|
||||
'2')
|
||||
declare pick=0
|
||||
declare -a mode_arr
|
||||
mode_arr[1]="TXT记录"
|
||||
mode_arr[2]='cloudflare'
|
||||
for i in "${!mode_arr[@]}"; do
|
||||
((pick++))
|
||||
echo "${pick}. ${mode_arr[$i]}"
|
||||
done
|
||||
read -p "请选择验证模式:" pick_mode
|
||||
if [[ ! $pick_mode =~ [1-${pick}] ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
case ${mode_arr[$pick_mode]} in
|
||||
'TXT记录')
|
||||
declare domain
|
||||
declare log_output=$(${HOME}/.acme.sh/acme.sh --issue --dns $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please)
|
||||
declare domain=$( echo "$log_output" | grep "Domain:" | awk -F ": " '{print $2}')
|
||||
declare txt_value=$(echo "$log_output" | grep "TXT value:" | awk -F ": " '{print $2}')
|
||||
echo "请到dns系统解析TXT记录"
|
||||
echo "名称: "
|
||||
echo $domain
|
||||
echo "文本记录:"
|
||||
echo $txt_value
|
||||
read -p "解析完成请输入 y:" pick
|
||||
if [[ $pick =~ [Yy] ]]; then
|
||||
eval "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please"
|
||||
else
|
||||
echo "解析完成后请输入下面的命令完成验证"
|
||||
echo "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please"
|
||||
fi
|
||||
;;
|
||||
'cloudflare')
|
||||
declare CF_Key
|
||||
declare CF_Email
|
||||
read -p "请输入cloudflare的邮箱:" CF_Email
|
||||
if [[ ! $CF_Email =~ .*@.* ]];then
|
||||
echo "邮箱不合法"
|
||||
exit
|
||||
fi
|
||||
read -p "请输入cloudflare的密钥:" CF_Key
|
||||
export CF_Key=$CF_Key
|
||||
export CF_Email=$CF_Email
|
||||
eval "${HOME}/.acme.sh/acme.sh --issue $domain_str --dns dns_cf"
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
declare lang
|
||||
echo "1.中文"
|
||||
echo "2.英文"
|
||||
read -p "请输入:" lang
|
||||
if [[ -f "/usr/bin/apt-get" ]];then
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y locales
|
||||
sudo apt-get install -y language-pack-zh-hans
|
||||
elif [[ -f "/usr/bin/apt" ]];then
|
||||
sudo apt update -y
|
||||
sudo apt install -y locales
|
||||
sudo apt install -y language-pack-zh-hans
|
||||
else
|
||||
echo "暂不支持该系统一键更换语言"
|
||||
exit
|
||||
fi
|
||||
sudo sed -i '/^#/! s/^/# /' /etc/locale.gen
|
||||
if ! grep LC_ALL /etc/default/locale &> /dev/null; then
|
||||
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
|
||||
fi
|
||||
case $lang in
|
||||
'1')
|
||||
sudo sed -i 's/.*zh_CN.UTF-8.*/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
sudo sed -i "s/^LANG.*/LANG=zh_CN.UTF-8/g" /etc/default/locale
|
||||
sudo sed -i "s/^LC_ALL.*/LC_ALL=zh_CN.UTF-8/g" /etc/default/locale
|
||||
;;
|
||||
'2')
|
||||
sudo sed -i 's/.*en_US.UTF-8.*/en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
sudo sed -i "s/^LANG.*/LANG=en_US.UTF-8/g" /etc/default/locale
|
||||
sudo sed -i "s/^LC_ALL.*/LC_ALL=en_US.UTF-8/g" /etc/default/locale
|
||||
;;
|
||||
esac
|
||||
sudo locale-gen
|
||||
update-locale
|
||||
source /etc/default/locale
|
||||
echo "语言更换成功"
|
10
Config/Other/bbr_open.sh
Normal file
10
Config/Other/bbr_open.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
declare version=$(uname -r | awk -F "." '{print $1}')
|
||||
if ! [[ $version -ge 5 ]];then
|
||||
echo "系统内核版本过低"
|
||||
exit
|
||||
fi
|
||||
grep -q "net.core.default_qdisc=fq" "/etc/sysctl.conf" || echo 'net.core.default_qdisc=fq' | tee -a "/etc/sysctl.conf"
|
||||
grep -q "net.ipv4.tcp_congestion_control=bbr" "/etc/sysctl.conf" || echo 'net.ipv4.tcp_congestion_control=bbr' | tee -a "/etc/sysctl.conf"
|
||||
sysctl -p || echo "bbr 开启失败"
|
||||
sysctl net.ipv4.tcp_available_congestion_control | grep bbr && echo "bbr 开启成功"
|
38
Config/Other/language.sh
Normal file
38
Config/Other/language.sh
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
declare lang
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "1.中文"
|
||||
echo "2.英文"
|
||||
read -p "请输入:" lang
|
||||
if [[ -f "/usr/bin/apt-get" ]];then
|
||||
apt-get update -y
|
||||
apt-get install -y locales
|
||||
apt-get install -y language-pack-zh-hans
|
||||
elif [[ -f "/usr/bin/apt" ]];then
|
||||
apt update -y
|
||||
apt install -y locales
|
||||
apt install -y language-pack-zh-hans
|
||||
else
|
||||
echo "暂不支持该系统一键更换语言"
|
||||
exit
|
||||
fi
|
||||
sed -i '/^#/! s/^/# /' /etc/locale.gen
|
||||
if ! grep LC_ALL /etc/default/locale &> /dev/null; then
|
||||
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
|
||||
fi
|
||||
case $lang in
|
||||
'1')
|
||||
sed -i 's/.*zh_CN.UTF-8.*/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
sed -i "s/^LANG.*/LANG=zh_CN.UTF-8/g" /etc/default/locale
|
||||
sed -i "s/^LC_ALL.*/LC_ALL=zh_CN.UTF-8/g" /etc/default/locale
|
||||
;;
|
||||
'2')
|
||||
sed -i 's/.*en_US.UTF-8.*/en_US.UTF-8 UTF-8/g' /etc/locale.gen
|
||||
sed -i "s/^LANG.*/LANG=en_US.UTF-8/g" /etc/default/locale
|
||||
sed -i "s/^LC_ALL.*/LC_ALL=en_US.UTF-8/g" /etc/default/locale
|
||||
;;
|
||||
esac
|
||||
locale-gen
|
||||
update-locale
|
||||
source /etc/default/locale
|
||||
echo "语言更换成功"
|
55
Config/Other/reinstall.sh
Normal file
55
Config/Other/reinstall.sh
Normal file
@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
declare pick
|
||||
declare server
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "请选择下载服务器"
|
||||
echo "1.国内服务器"
|
||||
echo "2.国外服务器(默认)"
|
||||
read -p "请输入:" pick
|
||||
if [[ $pick == '1' ]];then
|
||||
server="https://jihulab.com/bin456789/reinstall/-/raw/main/reinstall.sh"
|
||||
else
|
||||
server="https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh"
|
||||
fi
|
||||
|
||||
declare -A imags_dick
|
||||
declare -a imags_arr
|
||||
declare imags_number=0
|
||||
imags_dick['arch']=""
|
||||
imags_dick['kali']=""
|
||||
imags_dick['debian']="8 9 10 11 12"
|
||||
imags_dick['Ubuntu']="16.04 18.04 20.04 22.04 24.04"
|
||||
|
||||
for i in "${!imags_dick[@]}" ; do
|
||||
imags_number=$(( imags_number+1 ))
|
||||
imags_arr[$imags_number]=$i
|
||||
echo "${imags_number}.${i}"
|
||||
done
|
||||
|
||||
read -p "请选择需要安装的镜像序号:" pick
|
||||
|
||||
if [[ $pick =~ [1-"${#imags_dick[@]}"\ ] ]];then
|
||||
declare img=${imags_arr[$pick]}
|
||||
declare version=''
|
||||
declare -a version_arr
|
||||
declare version_number=0
|
||||
if [[ ! -z ${imags_dick[$img]} ]];then
|
||||
echo "请输入要安装的版本(默认最新)"
|
||||
for i in ${imags_dick[$img]} ; do
|
||||
version_number=$(( version_number+1 ))
|
||||
version_arr[$version_number]=$i
|
||||
echo "${version_number}.${i}"
|
||||
done
|
||||
read -p "请输入:" pick
|
||||
if [ -z $pick ]; then
|
||||
version=${version_arr[$version_number]}
|
||||
elif [[ $pick =~ [1-$version_number] ]];then
|
||||
version=${version_arr[$pick]}
|
||||
fi
|
||||
fi
|
||||
eval "bash <(curl -Ls ${server}) ${img} ${version}"
|
||||
echo "重启之后开始重装系统"
|
||||
echo "用服务器厂家的VNC连接可以看到重装进度"
|
||||
else
|
||||
echo "选择错误"
|
||||
fi
|
114
Config/User/key.sh
Normal file
114
Config/User/key.sh
Normal file
@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "1.生成密钥"
|
||||
echo "2.安装密钥"
|
||||
echo "输入其他返回主页"
|
||||
declare pick
|
||||
read -p "请输入要选择的命令:" pick
|
||||
|
||||
function open_key() {
|
||||
chmod 600 "$HOME/.ssh/authorized_keys"
|
||||
chmod 700 "$HOME/.ssh"
|
||||
|
||||
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
|
||||
declare pick2
|
||||
echo "是否关闭密码登录:"
|
||||
read -p "输入 n 取消关闭:" pick2
|
||||
|
||||
if [[ ! $pick2 =~ [Nn] ]];then
|
||||
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
|
||||
fi
|
||||
|
||||
systemctl restart sshd.service
|
||||
|
||||
echo "密钥安装完成"
|
||||
}
|
||||
|
||||
case $pick in
|
||||
'1')
|
||||
declare site="${HOME}/.ssh"
|
||||
read -p "请输入密钥安装位置,默认 :${site}:" pick
|
||||
|
||||
if [[ -d $pick ]]; then
|
||||
site=$pick
|
||||
elif [[ ! -z $pick ]];then
|
||||
echo "该路径没有文件夹"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare bit=""
|
||||
declare type=""
|
||||
declare phrase=""
|
||||
declare -A type_dick
|
||||
type_dick['rsa']="2048 4096"
|
||||
type_dick['ed25519']=""
|
||||
|
||||
declare print_number=0
|
||||
declare -a print_arr
|
||||
for i in "${!type_dick[@]}" ; do
|
||||
print_number=$(( print_number+1 ))
|
||||
print_arr[$print_number]=$i
|
||||
echo "${print_number}.${i}"
|
||||
done
|
||||
read -p "请选择要生成的密钥类型:" pick
|
||||
if ! [[ $pick =~ [1-${#type_dick[@]}] ]]; then
|
||||
echo "选择错误"
|
||||
exit
|
||||
fi
|
||||
type=${print_arr[$pick]}
|
||||
|
||||
if [ ! -z "${type_dick[$type]}" ]; then
|
||||
print_number=0
|
||||
echo "请选择密钥位大小"
|
||||
for i in ${type_dick[$type]} ; do
|
||||
print_number=$(( print_number+1 ))
|
||||
print_arr[$print_number]=$i
|
||||
echo "${print_number}.${i}"
|
||||
done
|
||||
read -p "请选择:" pick
|
||||
if ! [[ $pick =~ [1-${#print_arr[@]}] ]]; then
|
||||
echo "选择错误"
|
||||
exit
|
||||
fi
|
||||
bit="-b ${print_arr[$pick]}"
|
||||
fi
|
||||
|
||||
read -p "是否开启密钥短语,输入y开启,请输入:" pick
|
||||
if [[ $pick =~ [Yy] ]]; then
|
||||
read -p "请输入要设置的密钥短语" phrase
|
||||
fi
|
||||
eval "ssh-keygen -t ${type} ${bit} -N '${phrase}' -f '${site}/key' -q"
|
||||
echo "密钥安装成功"
|
||||
echo "私钥:${site}/key"
|
||||
echo "公钥:${site}/key.pub"
|
||||
read -p "是否开启密钥登录,输入n取消:" pick
|
||||
if ! [[ $pick =~ [Nn] ]]; then
|
||||
mkdir -p "$HOME/.ssh"
|
||||
echo "${site}/key.pub" > "$HOME/.ssh/authorized_keys"
|
||||
open_key
|
||||
fi
|
||||
;;
|
||||
'2')
|
||||
declare key
|
||||
echo "请输入公钥或文件路径:"
|
||||
echo "默认:$HOME/.ssh/id_rsa.pub"
|
||||
read -p "回车默认:" key
|
||||
|
||||
if [[ -z $key ]];then
|
||||
key="$HOME/.ssh/id_rsa.pub"
|
||||
fi
|
||||
|
||||
if [[ -f $key ]];then
|
||||
key=$(cat "$key")
|
||||
fi
|
||||
if [[ ! $key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then
|
||||
echo "公钥不合法"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/.ssh"
|
||||
echo "$key" > "$HOME/.ssh/authorized_keys"
|
||||
open_key
|
||||
esac
|
||||
|
70
Config/User/ssh.sh
Normal file
70
Config/User/ssh.sh
Normal file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
declare pick
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "1.更换ssh端口"
|
||||
echo "2.修改ssh登录方式"
|
||||
echo "任意输入返回主菜单"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
|
||||
case $pick in
|
||||
'1')
|
||||
read -p "请输入需要修改的端口号(默认22): " port_number
|
||||
|
||||
if [[ -z $port_number ]];then
|
||||
port_number=22
|
||||
fi
|
||||
|
||||
if ! [[ $port_number =~ ^[0-9]+$ ]] || ! ((port_number > 0 && port_number < 65535)); then
|
||||
echo "端口不合法"
|
||||
exit
|
||||
fi
|
||||
|
||||
if lsof -i :$port_number -t >/dev/null; then
|
||||
echo "$port_number 端口已被占用"
|
||||
exit
|
||||
fi
|
||||
|
||||
sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config
|
||||
|
||||
systemctl restart sshd.service
|
||||
|
||||
echo "端口已经修改为$port_number,记得防火墙放行"
|
||||
;;
|
||||
'2')
|
||||
declare pick_root
|
||||
declare pick2_key
|
||||
declare pick2_password
|
||||
echo "是否关闭root登录"
|
||||
read -p "输入 n 关闭:" pick_root
|
||||
echo "是否关闭密码登录"
|
||||
read -p "输入 n 关闭:" pick2_password
|
||||
echo "是否关闭密钥登录"
|
||||
read -p "输入 n 关闭:" pick2_key
|
||||
|
||||
if [[ ! $pick_root =~ [Nn] ]];then
|
||||
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录:开启"
|
||||
else
|
||||
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录:关闭"
|
||||
fi
|
||||
|
||||
if [[ ! $pick2_password =~ [Nn] ]];then
|
||||
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
||||
echo "密码登录:开启"
|
||||
else
|
||||
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
|
||||
echo "密码登录:关闭"
|
||||
fi
|
||||
|
||||
if [[ ! $pick2_key =~ [Nn] ]];then
|
||||
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
echo "密钥登录:开启"
|
||||
else
|
||||
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config
|
||||
echo "密钥登录:关闭"
|
||||
fi
|
||||
|
||||
systemctl restart sshd.service
|
||||
;;
|
||||
esac
|
5
Config/User/test.sh
Normal file
5
Config/User/test.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
if ! command -v ssh &> /dev/null; then
|
||||
echo "ssh未安装"
|
||||
exit
|
||||
fi
|
102
Config/User/user.sh
Normal file
102
Config/User/user.sh
Normal file
@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare pick
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "1.新建用户"
|
||||
echo "2.查看所有用户"
|
||||
echo "3.删除用户"
|
||||
echo "4.修改用户密码"
|
||||
echo "任意输入返回主菜单"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
|
||||
case $pick in
|
||||
'1')
|
||||
declare user_name
|
||||
read -p "请输入你想创建的用户名:" user_name
|
||||
|
||||
if id "$user_name" &>/dev/null; then
|
||||
echo "用户 $user_name 已存在。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
useradd -m -s /bin/bash "$user_name"
|
||||
|
||||
if grep -q "^$user_name " /etc/sudoers;then
|
||||
sed -i "s/^#\?$user_name.*/$user_name ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers
|
||||
else
|
||||
echo "$user_name ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
fi
|
||||
|
||||
|
||||
declare pick
|
||||
echo "用户登录方式"
|
||||
echo "y.密码登录"
|
||||
echo "n.使用root用户公钥"
|
||||
read -p "默认y,请输入:" pick
|
||||
if [[ ! $pick =~ [Nn] ]];then
|
||||
declare password
|
||||
read -p "请输入密码:" password
|
||||
echo "$user_name:$password" |chpasswd
|
||||
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
|
||||
echo "创建成功"
|
||||
echo "账号:$user_name"
|
||||
echo "密码:$password"
|
||||
else
|
||||
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'"
|
||||
cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys"
|
||||
chown "$user_name:$user_name" "/home/$user_name/.ssh/authorized_keys"
|
||||
su "$user_name" -c "chmod 600 '/home/$user_name/.ssh/authorized_keys'"
|
||||
su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'"
|
||||
|
||||
echo "创建成功"
|
||||
echo "账号:$user_name"
|
||||
echo "密钥登录"
|
||||
fi
|
||||
|
||||
declare pick2
|
||||
echo "是否关闭root登录"
|
||||
read -p "输入 n 取消关闭:" pick2
|
||||
|
||||
if [[ ! $pick2 =~ [Nn] ]];then
|
||||
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录已关闭"
|
||||
fi
|
||||
|
||||
systemctl restart sshd.service
|
||||
;;
|
||||
'2')
|
||||
echo "当前系统有以下用户"
|
||||
cut -d: -f1 /etc/passwd
|
||||
;;
|
||||
'3')
|
||||
declare user_name
|
||||
read -p "请输入需要删除的用户:" user_name
|
||||
if ! id $user_name &> /dev/nuull ;then
|
||||
echo "系统内没有该用户"
|
||||
exit
|
||||
fi
|
||||
sed -i "/^#\?$user_name.*/d" /etc/sudoers &> /dev/null
|
||||
pkill -u $user_name
|
||||
userdel -r $user_name &> /dev/null
|
||||
rm -rf "/home/${user_name}"
|
||||
echo "用户删除成功"
|
||||
;;
|
||||
'4')
|
||||
declare password
|
||||
declare user_name
|
||||
read -p "请输入需要修改密码的用户:" user_name
|
||||
if ! id $user_name &> /dev/null;then
|
||||
echo "系统内没有该用户"
|
||||
exit
|
||||
fi
|
||||
read -p "请输入${user_name}需要修改的密码:" password
|
||||
echo "${user_name}:${password}" |chpasswd
|
||||
if [[ ${user_name} == "root" ]]; then
|
||||
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
fi
|
||||
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
||||
systemctl restart sshd.service
|
||||
echo "修改成功,用户${user_name}的密码为:${password}"
|
||||
;;
|
||||
esac
|
142
Config/Web/acme/apply.sh
Normal file
142
Config/Web/acme/apply.sh
Normal file
@ -0,0 +1,142 @@
|
||||
#!/bin/bash
|
||||
declare pick_mode=$1
|
||||
declare domain=$2
|
||||
|
||||
if ! [[ $pick_mode == "nginx" ]]; then
|
||||
pick_mode=""
|
||||
domain=""
|
||||
fi
|
||||
|
||||
if ! command -v socat &> /dev/null; then
|
||||
if [[ -f "/usr/bin/apt-get" ]];then
|
||||
apt-get update -y
|
||||
apt-get install socat -y
|
||||
elif [[ -f "/usr/bin/apt" ]];then
|
||||
apt update -y
|
||||
apt install socat -y
|
||||
elif [[ -f "/usr/bin/pacman" ]];then
|
||||
pacman -Syu --noconfirm
|
||||
pacman -Sy --noconfirm socat
|
||||
else
|
||||
echo "socat未安装"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
|
||||
rm -rf ${HOME}/.apple.sh
|
||||
declare mail
|
||||
read -p "请输入用来申请域名的邮箱:" mail
|
||||
if [[ ! $mail =~ .*@.* ]];then
|
||||
echo "邮箱不合法"
|
||||
exit
|
||||
fi
|
||||
|
||||
curl https://get.acme.sh | sh -s "email=$mail"
|
||||
fi
|
||||
|
||||
declare domain_str
|
||||
|
||||
if [[ ! $domain ]];then
|
||||
echo "请输入需要申请SSL证书的域名"
|
||||
read -p "请输入要绑定的域名多个用 空格 隔开:" domain
|
||||
fi
|
||||
|
||||
|
||||
for i in ${domain} ; do
|
||||
if [[ ! $i =~ [\w+\.]+ ]];then
|
||||
echo "域名不合法"
|
||||
exit
|
||||
else
|
||||
domain_str="$domain_str -d $i"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z $domain_str ]]; then
|
||||
echo "需要添加的域名不能为空"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "1.http验证"
|
||||
echo "2.dns验证"
|
||||
read -p "请选择验证模式:" pick_mode
|
||||
|
||||
case $pick_mode in
|
||||
'1')
|
||||
declare mode
|
||||
if command -v nginx &> /dev/null; then
|
||||
mode="nginx"
|
||||
cat > "/etc/nginx/conf.d/test.conf" << EOF
|
||||
server {
|
||||
listen 80; # 监听80端口
|
||||
server_name ${domain}; # 服务器名称(本地)
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html; # 指定根目录
|
||||
index index.html index.htm; # 默认页面
|
||||
}
|
||||
}
|
||||
EOF
|
||||
elif command -v apache &> /dev/null; then
|
||||
mode="apache"
|
||||
else
|
||||
mode="standalone"
|
||||
fi
|
||||
echo "请到服务器将80和443端口开启,将域名解析到本机"
|
||||
read -p "解析完成请回车:"
|
||||
eval "${HOME}/.acme.sh/acme.sh --issue ${domain_str} --${mode}"
|
||||
rm /etc/nginx/conf.d/test.conf
|
||||
;;
|
||||
'2')
|
||||
declare pick=0
|
||||
declare -a mode_arr
|
||||
mode_arr[1]="TXT记录"
|
||||
mode_arr[2]='cloudflare'
|
||||
for i in "${!mode_arr[@]}"; do
|
||||
((pick++))
|
||||
echo "${pick}. ${mode_arr[$i]}"
|
||||
done
|
||||
read -p "请选择验证模式:" pick_mode
|
||||
if [[ ! $pick_mode =~ [1-${pick}] ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
case ${mode_arr[$pick_mode]} in
|
||||
'TXT记录')
|
||||
declare log_output=$(${HOME}/.apple.sh/apple.sh --issue --dns $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please)
|
||||
declare -a domain=($( echo "$log_output" | grep "Domain:" | awk -F ": " '{print $2}'))
|
||||
declare -a txt_value=($(echo "$log_output" | grep "TXT value:" | awk -F ": " '{print $2}'))
|
||||
echo "请到dns系统解析TXT记录"
|
||||
for (( i = 0; i < ${#domain[@]}; i++ )); do
|
||||
echo "需要解析的第$((i+1))条"
|
||||
echo "名称: ${domain[$i]}"
|
||||
echo "文本记录:${txt_value[$i]}"
|
||||
done
|
||||
|
||||
read -p "解析完成请输入 y:" pick
|
||||
if [[ $pick =~ [Yy] ]]; then
|
||||
eval "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please"
|
||||
else
|
||||
echo "解析完成后请输入下面的命令完成验证"
|
||||
echo "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please"
|
||||
fi
|
||||
;;
|
||||
'cloudflare')
|
||||
declare CF_Key
|
||||
declare CF_Email
|
||||
read -p "请输入cloudflare的邮箱:" CF_Email
|
||||
if [[ ! $CF_Email =~ .*@.* ]];then
|
||||
echo "邮箱不合法"
|
||||
exit
|
||||
fi
|
||||
read -p "请输入cloudflare的密钥:" CF_Key
|
||||
export CF_Key=$CF_Key
|
||||
export CF_Email=$CF_Email
|
||||
eval "${HOME}/.acme.sh/acme.sh --issue $domain_str --dns dns_cf"
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
|
245
Config/Web/nginx.sh
Normal file
245
Config/Web/nginx.sh
Normal file
@ -0,0 +1,245 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! command -v nginx &> /dev/null; then
|
||||
if [[ -f "/usr/bin/apt-get" ]];then
|
||||
apt-get update -y
|
||||
apt-get install nginx -y
|
||||
elif [[ -f "/usr/bin/apt" ]];then
|
||||
apt update -y
|
||||
apt install nginx -y
|
||||
elif [[ -f "/usr/bin/pacman" ]];then
|
||||
pacman -Syu --noconfirm
|
||||
pacman -Sy --noconfirm nginx
|
||||
else
|
||||
echo "nginx未安装"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
declare pick
|
||||
echo "========$(basename $0 .sh)========"
|
||||
echo "1.新增站点配置文件"
|
||||
echo "2.查看已有站点配置文件"
|
||||
echo "3.删除站点配置文件"
|
||||
read -p "请选择:" pick
|
||||
case $pick in
|
||||
'1')
|
||||
declare domain
|
||||
read -p "请输入要绑定的域名多个用 空格 隔开:" domain
|
||||
|
||||
declare ssl_certificate
|
||||
declare ssl_certificate_key
|
||||
declare ssl_domain=$(echo "${domain}" | awk '{print $1}')
|
||||
|
||||
echo "ssl证书"
|
||||
echo "1.自动申请(默认)"
|
||||
echo "2.手动输入"
|
||||
read -p "请输入:" pick
|
||||
if [[ $pick == 2 ]]; then
|
||||
echo "证书,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
|
||||
read -p "请输入证书地址:" ssl_certificate
|
||||
if [[ -z $ssl_certificate ]];then
|
||||
ssl_certificate="${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
|
||||
fi
|
||||
echo "密钥,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
|
||||
|
||||
read -p "请输入密钥地址:" ssl_certificate_key
|
||||
if [[ -z $ssl_certificate_key ]];then
|
||||
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
|
||||
fi
|
||||
else
|
||||
echo "1.nginx(默认)"
|
||||
read -p "请选择:" pick
|
||||
bash "$(dirname $0)/acme/apply" "nginx" "${domain}"
|
||||
ssl_certificate="${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
|
||||
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
declare name
|
||||
read -p "请输入配置文件名,默认为域名:" name
|
||||
if [[ -z $name ]]; then
|
||||
name=$ssl_domain
|
||||
fi
|
||||
|
||||
echo "工作方式"
|
||||
echo "1.反向代理(默认)"
|
||||
echo "2.静态文件"
|
||||
read -p "请选择:" pick
|
||||
declare path
|
||||
if [[ $pick == 2 ]]; then
|
||||
read -p "请输入要代理的站点路径" path
|
||||
cat > "/etc/nginx/sites-available/${name}.conf" << EOF
|
||||
server {
|
||||
listen 443 ssl http2; # 监听 443 端口并启用 SSL 和 HTTP/2
|
||||
server_name ${domain}; # 替换为你的域名
|
||||
|
||||
# SSL 证书配置
|
||||
ssl_certificate ${ssl_certificate}; # 证书文件路径
|
||||
ssl_certificate_key ${ssl_certificate_key}; # 证书密钥文件路径
|
||||
ssl_protocols TLSv1.2 TLSv1.3; # 仅使用安全的 TLS 协议版本
|
||||
ssl_ciphers HIGH:!aNULL:!MD5; # 安全的密码套件
|
||||
ssl_prefer_server_ciphers on; # 优先使用服务器的密码套件
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# HSTS(HTTP 严格传输安全)强制浏览器使用 HTTPS
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# 设置文件传输的最大大小
|
||||
client_max_body_size 100M; # 上传文件最大大小 (例如 100MB)
|
||||
proxy_max_temp_file_size 1024m; # 代理最大临时文件大小
|
||||
|
||||
# 超时与缓冲设置
|
||||
client_body_timeout 60s; # 等待客户端发送请求主体的超时时间
|
||||
client_header_timeout 60s; # 等待客户端发送请求头的超时时间
|
||||
send_timeout 60s; # 发送响应的超时时间
|
||||
client_body_buffer_size 128k; # 上传缓冲区大小
|
||||
proxy_buffer_size 4k; # 设置代理服务器响应的缓冲区大小
|
||||
proxy_buffers 8 16k; # 代理服务器的缓冲区数和大小
|
||||
proxy_busy_buffers_size 64k; # 忙碌代理缓冲区大小
|
||||
large_client_header_buffers 4 16k; # 设置较大的客户端头部缓冲区,防止上传大文件时出现 413 错误
|
||||
|
||||
# 静态文件目录
|
||||
root ${path};
|
||||
index index.html index.htm;
|
||||
|
||||
# 日志
|
||||
access_log /var/log/nginx/example.com_access.log;
|
||||
error_log /var/log/nginx/example.com_error.log;
|
||||
|
||||
# 默认处理
|
||||
location / {
|
||||
try_files \$uri \$uri/ =404;
|
||||
}
|
||||
|
||||
# 防止访问隐藏文件(如 .git)
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
}
|
||||
|
||||
# 错误页面配置
|
||||
error_page 404 /404.html;
|
||||
location = /404.html {
|
||||
root /var/www/example.com/html;
|
||||
}
|
||||
}
|
||||
|
||||
# HTTP 到 HTTPS 重定向
|
||||
server {
|
||||
listen 80; # 监听 80 端口
|
||||
server_name ${domain};
|
||||
|
||||
# 将所有 HTTP 请求重定向到 HTTPS
|
||||
return 301 https://\$host\$request_uri;
|
||||
}
|
||||
|
||||
EOF
|
||||
else
|
||||
read -p "请输入后端服务器的地址,如果只输入数字代表端口:" path
|
||||
if [[ $path =~ [0-9]+ ]]; then
|
||||
path="http://127.0.0.1:${path}"
|
||||
fi
|
||||
cat > "/etc/nginx/sites-available/${name}.conf" << EOF
|
||||
server {
|
||||
listen 443 ssl http2; # 监听 443 端口,并启用 HTTP/2
|
||||
server_name ${domain}; # 替换为你的域名
|
||||
|
||||
# SSL 证书配置
|
||||
ssl_certificate ${ssl_certificate}; # 证书文件路径
|
||||
ssl_certificate_key ${ssl_certificate_key}; # 证书密钥文件路径
|
||||
ssl_protocols TLSv1.2 TLSv1.3; # 使用安全的 TLS 协议版本
|
||||
ssl_ciphers HIGH:!aNULL:!MD5; # 安全密码套件
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
# 启用 SSL session 缓存和超时设置
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# 强制使用 HTTPS (HSTS)
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# 日志设置
|
||||
access_log /var/log/nginx/${name}_access.log;
|
||||
error_log /var/log/nginx/${name}_error.log;
|
||||
|
||||
# 错误页面配置
|
||||
error_page 404 /404.html;
|
||||
location = /404.html {
|
||||
root /var/www/example.com/html;
|
||||
}
|
||||
|
||||
# 设置文件传输的最大大小
|
||||
client_max_body_size 100M; # 上传文件最大大小 (例如 100MB)
|
||||
proxy_max_temp_file_size 1024m; # 代理最大临时文件大小
|
||||
|
||||
# 超时与缓冲设置
|
||||
client_body_timeout 60s; # 等待客户端发送请求主体的超时时间
|
||||
client_header_timeout 60s; # 等待客户端发送请求头的超时时间
|
||||
send_timeout 60s; # 发送响应的超时时间
|
||||
client_body_buffer_size 128k; # 上传缓冲区大小
|
||||
proxy_buffer_size 4k; # 设置代理服务器响应的缓冲区大小
|
||||
proxy_buffers 8 16k; # 代理服务器的缓冲区数和大小
|
||||
proxy_busy_buffers_size 64k; # 忙碌代理缓冲区大小
|
||||
large_client_header_buffers 4 16k; # 设置较大的客户端头部缓冲区,防止上传大文件时出现 413 错误
|
||||
|
||||
# 反向代理到后台应用 (常规 HTTP/HTTPS)
|
||||
location / {
|
||||
proxy_pass ${path}; # 反向代理到后端应用服务器
|
||||
proxy_set_header Host \$host; # 保持原始主机头
|
||||
proxy_set_header X-Real-IP \$remote_addr; # 传递客户端的真实 IP
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; # 传递代理链中的 IP
|
||||
proxy_set_header X-Forwarded-Proto \$scheme; # 传递协议(HTTP 或 HTTPS)
|
||||
|
||||
# 防止后端服务器返回不安全的内容
|
||||
proxy_redirect off;
|
||||
|
||||
# 超时时间配置
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
send_timeout 60s;
|
||||
}
|
||||
|
||||
# WebSocket 反向代理到后台应用
|
||||
location /ws {
|
||||
proxy_pass ${path}; # 反向代理到 WebSocket 应用服务器
|
||||
proxy_http_version 1.1; # WebSocket 必须使用 HTTP 1.1
|
||||
proxy_set_header Upgrade \$http_upgrade; # 升级请求头,用于 WebSocket
|
||||
proxy_set_header Connection "Upgrade"; # 持久连接,保持 WebSocket 连接
|
||||
proxy_set_header Host \$host; # 保持原始主机头
|
||||
proxy_set_header X-Real-IP \$remote_addr; # 传递客户端的真实 IP
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; # 传递代理链中的 IP
|
||||
proxy_set_header X-Forwarded-Proto \$scheme; # 传递协议(HTTP 或 HTTPS)
|
||||
|
||||
# 超时时间配置 (WebSocket 是长连接)
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 3600s; # WebSocket 长连接需较长读超时
|
||||
send_timeout 60s;
|
||||
}
|
||||
|
||||
# 错误页面配置
|
||||
error_page 502 /502.html;
|
||||
location = /502.html {
|
||||
root /usr/share/nginx/html; # 错误页面路径
|
||||
}
|
||||
}
|
||||
|
||||
# HTTP 到 HTTPS 重定向
|
||||
server {
|
||||
listen 80; # 监听 HTTP 80 端口
|
||||
server_name ${domain}; # 替换为你的域名
|
||||
|
||||
# 将所有 HTTP 请求重定向到 HTTPS
|
||||
return 301 https://\$host\$request_uri;
|
||||
}
|
||||
|
||||
EOF
|
||||
fi
|
||||
ln -s "/etc/nginx/sites-available/${name}.conf" "/etc/nginx/sites-enabled" &> /dev/null
|
||||
nginx -s reload &> /dev/null
|
||||
echo "配置完成"
|
||||
;;
|
||||
esac
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "正在更新系统包管理器"
|
||||
declare install_str
|
||||
declare version="$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')"
|
||||
declare status=0
|
||||
@ -8,15 +8,15 @@ declare pkg
|
||||
if [[ -f "/usr/bin/apt-get" ]];then
|
||||
pkg='apt-get'
|
||||
install_str+="${pkg} install -y"
|
||||
sudo apt-get update -y
|
||||
apt-get update -y
|
||||
elif [[ -f "/usr/bin/apt" ]];then
|
||||
pkg='apt'
|
||||
install_str+="${pkg} install -y"
|
||||
sudo apt update -y
|
||||
apt update -y
|
||||
elif [[ -f "/usr/bin/pacman" ]];then
|
||||
pkg='pacman'
|
||||
install_str+="${pkg} -Sy --noconfirm"
|
||||
sudo pacman -Syu --noconfirm
|
||||
pacman -Syu --noconfirm
|
||||
else
|
||||
echo "暂不支持该系统一键安装常用软件"
|
||||
exit
|
||||
@ -24,35 +24,55 @@ fi
|
||||
|
||||
|
||||
declare pick
|
||||
declare soft_number
|
||||
declare -A soft_dick
|
||||
declare -a soft_array
|
||||
soft_array[0]='git'
|
||||
soft_array[1]='vim'
|
||||
soft_array[2]='wget'
|
||||
soft_array[3]='curl'
|
||||
soft_array[4]='ssh'
|
||||
soft_array[5]='zsh'
|
||||
soft_array[6]='zip'
|
||||
soft_dick['git']=0
|
||||
soft_dick['vim']=0
|
||||
soft_dick['wget']=0
|
||||
soft_dick['curl']=0
|
||||
soft_dick['sudo']=0
|
||||
soft_dick['ssh']=0
|
||||
soft_dick['zsh']=0
|
||||
soft_dick['zsh-beautify']=1
|
||||
soft_dick['docker']=1
|
||||
soft_dick['x-cmd']=1
|
||||
|
||||
echo "======一键安装常用软件======"
|
||||
for i in "${soft_array[@]}"
|
||||
do
|
||||
read -p "是否安装${i},输入 n 取消安装:" pick
|
||||
if [[ ! $pick =~ [Nn] ]];then
|
||||
install_str+=" ${i}"
|
||||
echo "========$(basename $0 .sh)========"
|
||||
for i in "${!soft_dick[@]}" ; do
|
||||
soft_number=$(( soft_number+1 ))
|
||||
soft_array[$soft_number]=$i
|
||||
echo "${soft_number}.${i}"
|
||||
done
|
||||
echo "请输入需要安装的软件序号(默认安装全部)"
|
||||
read -p "用 空格 隔开:" pick
|
||||
|
||||
if [[ -z $pick ]];then
|
||||
for (( i = 1; i <= ${#soft_dick[@]}; i++ )); do
|
||||
if [[ $i != 1 ]]; then
|
||||
pick="$pick $i"
|
||||
else
|
||||
pick="$i"
|
||||
fi
|
||||
done
|
||||
elif ! [[ $pick -ge 1 && $pick -le ${#soft_dick[@]} || $pick =~ ([1-${#soft_dick[@]}][\s]?)+ ]];then
|
||||
echo "输入错误"
|
||||
exit
|
||||
fi
|
||||
|
||||
for i in $pick ; do
|
||||
if [[ ${soft_dick[${soft_array[$i]}]} == 0 ]]; then
|
||||
eval "$install_str ${soft_array[$i]}"
|
||||
else
|
||||
soft_dick[${soft_array[$i]}]=2
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${soft_dick['x-cmd']} == 2 ]];then
|
||||
eval "$(curl https://get.x-cmd.com)"
|
||||
fi
|
||||
|
||||
declare pick_x
|
||||
read -p "是否安装x-cmd,输入 n 取消安装:" pick_x
|
||||
|
||||
declare pick_zsh
|
||||
read -p "是否一键美化zsh,输入 n 取消:" pick_zsh
|
||||
|
||||
declare pick_docker
|
||||
read -p "是否安装docker,输入 n 取消:" pick_docker
|
||||
|
||||
if [[ ! $pick_docker =~ [Nn] ]];then
|
||||
if [[ ${soft_dick['docker']} == 2 ]];then
|
||||
declare -A docker_imgs
|
||||
docker_imgs['官方']='https://download.docker.com'
|
||||
docker_imgs['中国科技大学(默认)']='https://mirrors.ustc.edu.cn/docker-ce'
|
||||
@ -68,7 +88,7 @@ if [[ ! $pick_docker =~ [Nn] ]];then
|
||||
docker_img_number[$docker_img_number_pick]=$i
|
||||
echo "${docker_img_number_pick}.${i}"
|
||||
done
|
||||
read -p "请输入需要选择的镜像站:" docker_img_number_pick
|
||||
read -p "请选择Docker镜像站:" docker_img_number_pick
|
||||
declare docker_img
|
||||
if [[ ! $docker_img_number_pick =~ [1-${#docker_imgs[@]}] ]];then
|
||||
docker_img='https://mirrors.sustc.edu.cn/docker-ce'
|
||||
@ -76,42 +96,30 @@ if [[ ! $pick_docker =~ [Nn] ]];then
|
||||
docker_img_number_pick=${docker_img_number[$docker_img_number_pick]}
|
||||
docker_img=${docker_imgs[$docker_img_number_pick]}
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ ! $pick_x =~ [Nn] ]];then
|
||||
eval "$(curl https://get.x-cmd.com)"
|
||||
fi
|
||||
|
||||
|
||||
eval "sudo ${install_str}"
|
||||
if [[ ! $pick_x =~ [Nn] ]];then
|
||||
eval "$(curl https://get.x-cmd.com)"
|
||||
fi
|
||||
|
||||
if [[ ! $pick_docker =~ [Nn] ]];then
|
||||
if [[ ${pkg} == 'apt' || ${pkg} == 'apt-get' ]];then
|
||||
sudo ${pkg} update
|
||||
sudo ${pkg} install ca-certificates curl -y
|
||||
sudo install -m 0755 -d /etc/apt/keyrings
|
||||
sudo curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc
|
||||
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
||||
${pkg} update
|
||||
${pkg} install ca-certificates curl -y
|
||||
install -m 0755 -d /etc/apt/keyrings
|
||||
curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc
|
||||
chmod a+r /etc/apt/keyrings/docker.asc
|
||||
echo \
|
||||
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_img}/linux/${version} \
|
||||
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
|
||||
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
sudo ${pkg} update
|
||||
sudo ${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
|
||||
elif [[ ${pkg} == 'arch' ]];then
|
||||
sudo pacman -Sy docker --noconfirm
|
||||
sudo systemctl start docker.service
|
||||
sudo systemctl enable docker.service
|
||||
sudo usermod -aG docker $USER
|
||||
newgrp docker
|
||||
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
${pkg} update
|
||||
${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
|
||||
elif [[ ${pkg} == 'pacman' ]];then
|
||||
pacman -Sy docker --noconfirm
|
||||
systemctl start docker.service
|
||||
systemctl enable docker.service
|
||||
usermod -aG docker $USER
|
||||
newgrp docker
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! $pick_zsh =~ [Nn] ]];then
|
||||
|
||||
if [[ ${soft_dick['zsh-beautify']} == 2 ]];then
|
||||
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sed 's/read -r opt//g'| sed 's/exec zsh -l//g'| sh
|
||||
while [[ ! -d "$HOME/.oh-my-zsh" ]]; do
|
||||
sleep 3
|
||||
@ -119,8 +127,8 @@ if [[ ! $pick_zsh =~ [Nn] ]];then
|
||||
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
|
||||
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
|
||||
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
|
||||
sudo sed -i 's/^#\?ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc
|
||||
sudo sed -i 's/^#\?plugins.*/plugins=(zsh-syntax-highlighting zsh-autosuggestions command-not-found)/g' ~/.zshrc
|
||||
sed -i 's/^#\?ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc
|
||||
sed -i 's/^#\?plugins.*/plugins=(zsh-syntax-highlighting zsh-autosuggestions command-not-found)/g' ~/.zshrc
|
||||
chsh -s /bin/zsh
|
||||
exec zsh -l
|
||||
fi
|
@ -12,14 +12,13 @@ sources_dick['网易云']='https://mirrors.163.com'
|
||||
|
||||
declare -a pcik_array
|
||||
declare pick=0
|
||||
echo "========Sources========"
|
||||
echo "========$(basename $0 .sh)========"
|
||||
for i in "${!sources_dick[@]}";
|
||||
do
|
||||
pick=$(( pick+1 ))
|
||||
pcik_array[$pick]=$i
|
||||
echo "${pick}.${i}"
|
||||
done
|
||||
echo "========Sources========"
|
||||
read -p "请输入:" pick
|
||||
|
||||
|
||||
@ -40,8 +39,8 @@ deb ${url}/debian/ bookworm main contrib non-free non-free-firmware
|
||||
deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware
|
||||
deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware
|
||||
EOF
|
||||
sudo apt update -y
|
||||
sudo apt-get update -y
|
||||
apt update -y
|
||||
apt-get update -y
|
||||
status=1
|
||||
;;
|
||||
'bullseye')
|
||||
@ -50,18 +49,18 @@ deb ${url}/debian/ bullseye main contrib non-free
|
||||
deb ${url}/debian/ bullseye-updates main contrib non-free
|
||||
deb ${url}/debian/ bullseye-backports main contrib non-free
|
||||
EOF
|
||||
sudo apt update -y
|
||||
sudo apt-get update -y
|
||||
apt update -y
|
||||
apt-get update -y
|
||||
status=1
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$system" in
|
||||
'arch')
|
||||
sudo pacman -Sy pacman-key --noconfirm
|
||||
pacman -Sy pacman-key --noconfirm
|
||||
sed -i '/^Server.*/d' "/etc/pacman.conf"
|
||||
echo "Server = ${url}/archlinuxcn/\$arch"
|
||||
sudo pacman-key --lsign-key "farseerfc@archlinux.org"
|
||||
pacman-key --lsign-key "farseerfc@archlinux.org"
|
||||
pacman -Syyu
|
||||
status=1
|
||||
;;
|
||||
@ -72,8 +71,8 @@ deb ${url}/ubuntu/ ${version}-security main restricted universe multiverse
|
||||
deb ${url}/ubuntu/ ${version}-updates main restricted universe multiverse
|
||||
deb ${url}/ubuntu/ ${version}-backports main restricted universe multiverse
|
||||
EOF
|
||||
sudo apt update -y
|
||||
sudo apt-get update -y
|
||||
apt update -y
|
||||
apt-get update -y
|
||||
status=1
|
||||
;;
|
||||
esac
|
@ -1,98 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare path_script=$1
|
||||
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "docker未安装"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare pick_array
|
||||
declare pick_number=6
|
||||
declare pick
|
||||
|
||||
echo "========Docker========"
|
||||
echo "1.换源"
|
||||
echo "2.清除所有未使用镜像"
|
||||
echo "-----一键搭建软件-----"
|
||||
for i in "${path_script}/Config/Docker"/*;do
|
||||
pick_number=$((pick_number + 1))
|
||||
pick_array[$pick_number]=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
||||
echo "${pick_number}.${pick_array[$pick_number]}"
|
||||
done
|
||||
echo "-----一键搭建软件-----"
|
||||
echo "任意输入返回主菜单"
|
||||
echo "========Docker========"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
|
||||
clear
|
||||
|
||||
if [[ $pick == '1' ]];then
|
||||
declare -A img_dick
|
||||
declare -a img_number
|
||||
declare img_pick=0
|
||||
img_dick['Daocloud(默认)']='https://docker.m.daocloud.io'
|
||||
|
||||
for i in "${!img_dick[@]}";
|
||||
do
|
||||
img_pick=$(( img_pick+1 ))
|
||||
img_number[$img_pick]=$i
|
||||
echo "${img_pick}.${i}"
|
||||
done
|
||||
read -p "请输入要选择的镜像,也可直接输入镜像网站:" img_pick
|
||||
if [[ -z $img_pick ]];then
|
||||
declare url='https://docker.m.daocloud.io'
|
||||
elif [[ $img_pick =~ ^[http] ]];then
|
||||
declare url=$img_pick
|
||||
elif [[ ${img_pick} -le 0 || ${img_pick} -ge ${!img_dick[*]} ]];then
|
||||
img_pick=${img_number[$img_pick]}
|
||||
declare url=${img_dick[$img_pick]}
|
||||
else
|
||||
echo "输入错误"
|
||||
exit
|
||||
fi
|
||||
sudo echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json"
|
||||
sudo systemctl restart docker 2>> /dev/null|| echo "docker 重启失败"
|
||||
echo "换源成功"
|
||||
|
||||
elif [[ $pick == '2' ]];then
|
||||
sudo docker system prune -af
|
||||
echo "清理完成"
|
||||
elif [[ "${pick}" -gt "$((${pick_number}-${#pick_array[*]}))" && "${pick}" -le "${pick_number}" ]];then
|
||||
declare file_path
|
||||
read -p "请输入软件储存位置,默认 /var/www/${pick_array[${pick}]} :" file_path
|
||||
if [[ -z ${file_path} ]];then
|
||||
file_path="/var/www/${pick_array[${pick}]}"
|
||||
fi
|
||||
|
||||
if [[ ! -d "$file_path" ]];then
|
||||
sudo mkdir -p "$file_path" || { echo "目录创建失败"; exit 1; }
|
||||
elif [[ ! -z "$(find "$file_path" -mindepth 1 -print -quit)" ]];then
|
||||
echo "该目录存有文件"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare dport=$(($RANDOM % 9000 + 1000))
|
||||
|
||||
while ss -tuln | grep $dport &> /dev/null
|
||||
do
|
||||
dport=$(($RANDOM % 9000 + 1000))
|
||||
done
|
||||
|
||||
declare port
|
||||
read -p "请输入访问端口,默认 $dport :" port
|
||||
|
||||
if [[ -z $port ]];then
|
||||
port=$dport
|
||||
fi
|
||||
|
||||
if ss -tuln | grep $port &> /dev/null;then
|
||||
echo "端口已被占用"
|
||||
exit
|
||||
fi
|
||||
|
||||
bash "${path_script}/Config/Docker/${pick_array[${pick}]}.sh" "$file_path" "$port"
|
||||
echo "${pick_array[${pick}]}安装完成,访问端口${port}"
|
||||
fi
|
||||
|
||||
|
182
Menus/Login.sh
182
Menus/Login.sh
@ -1,182 +0,0 @@
|
||||
#!/bin/bash
|
||||
declare pick
|
||||
echo "========Login========"
|
||||
echo "1.修改root密码"
|
||||
echo "2.ssh安装密钥"
|
||||
echo "3.新建用户"
|
||||
echo "4.管理ssh登录方式"
|
||||
echo "5.更换ssh端口"
|
||||
echo "任意输入返回主菜单"
|
||||
echo "========Login========"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
|
||||
|
||||
case $pick in
|
||||
1)
|
||||
declare password
|
||||
read -p "请输入root密码:" password
|
||||
echo "root:$password" |sudo chpasswd
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
||||
sudo systemctl restart sshd.service
|
||||
echo "修改成功当前root密码为:$password"
|
||||
;;
|
||||
2)
|
||||
declare key
|
||||
echo "请输入公钥或文件路径:"
|
||||
echo "默认:$HOME/.ssh/id_rsa.pub"
|
||||
read -p "回车默认:" key
|
||||
|
||||
if [[ -z $key ]];then
|
||||
key="$HOME/.ssh/id_rsa.pub"
|
||||
fi
|
||||
|
||||
if [[ -f $key ]];then
|
||||
key=$(cat "$key")
|
||||
fi
|
||||
if [[ ! $key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then
|
||||
echo "公钥不合法"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/.ssh"
|
||||
echo "$key" > "$HOME/.ssh/authorized_keys"
|
||||
|
||||
chmod 600 "$HOME/.ssh/authorized_keys"
|
||||
chmod 700 "$HOME/.ssh"
|
||||
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
|
||||
declare pick2
|
||||
echo "是否关闭密码登录:"
|
||||
read -p "输入 n 取消关闭:" pick2
|
||||
|
||||
if [[ ! $pick2 =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
|
||||
fi
|
||||
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
|
||||
echo "密钥安装完成"
|
||||
;;
|
||||
3)
|
||||
declare user_name
|
||||
read -p "请输入你想创建的用户名:" user_name
|
||||
|
||||
if id "$user_name" &>/dev/null; then
|
||||
echo "用户 $user_name 已存在。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
useradd -m -s /bin/bash "$user_name"
|
||||
|
||||
if grep -q "^$user_name " /etc/sudoers;then
|
||||
sudo sed -i "s/^#\?$user_name.*/lsy ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers
|
||||
else
|
||||
sudo echo "lsy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
fi
|
||||
|
||||
|
||||
declare pick
|
||||
echo "用户登录方式"
|
||||
echo "y.密码登录"
|
||||
echo "n.使用root用户公钥"
|
||||
read -p "默认y,请输入:" pick
|
||||
if [[ ! $pick =~ [Nn] ]];then
|
||||
declare password
|
||||
read -p "请输入密码:" password
|
||||
echo "$user_name:$password" |sudo chpasswd
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
|
||||
echo "创建成功"
|
||||
echo "账号:$user_name"
|
||||
echo "密码:$password"
|
||||
else
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'"
|
||||
sudo cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys"
|
||||
sudo chown lsy:lsy "/home/$user_name/.ssh/authorized_keys"
|
||||
su "$user_name" -c "chmod 600 '/home/$user_name/.ssh/authorized_keys'"
|
||||
su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'"
|
||||
|
||||
echo "创建成功"
|
||||
echo "账号:$user_name"
|
||||
echo "密钥登录"
|
||||
fi
|
||||
|
||||
declare pick2
|
||||
echo "是否关闭root登录"
|
||||
read -p "输入 n 取消关闭:" pick2
|
||||
|
||||
if [[ ! $pick2 =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录已关闭"
|
||||
fi
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
|
||||
;;
|
||||
4)
|
||||
declare pick_root
|
||||
declare pick2_key
|
||||
declare pick2_password
|
||||
echo "是否关闭root登录"
|
||||
read -p "输入 n 关闭:" pick_root
|
||||
echo "是否关闭密码登录"
|
||||
read -p "输入 n 关闭:" pick2_password
|
||||
echo "是否关闭密钥登录"
|
||||
read -p "输入 n 关闭:" pick2_key
|
||||
|
||||
if [[ ! $pick_root =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录:开启"
|
||||
else
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录:关闭"
|
||||
fi
|
||||
|
||||
if [[ ! $pick2_password =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
||||
echo "密码登录:开启"
|
||||
else
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
|
||||
echo "密码登录:关闭"
|
||||
fi
|
||||
|
||||
if [[ ! $pick2_key =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
echo "密钥登录:开启"
|
||||
else
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config
|
||||
echo "密钥登录:关闭"
|
||||
fi
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
;;
|
||||
5)
|
||||
read -p "请输入需要修改的端口号(默认22): " port_number
|
||||
|
||||
if [[ -z $port_number ]];then
|
||||
port_number=22
|
||||
fi
|
||||
|
||||
if ! [[ $port_number =~ ^[0-9]+$ ]] || ! ((port_number > 0 && port_number < 65535)); then
|
||||
echo "端口不合法"
|
||||
exit
|
||||
fi
|
||||
|
||||
if sudo lsof -i :$port_number -t >/dev/null; then
|
||||
echo "$port_number 端口已被占用"
|
||||
exit
|
||||
fi
|
||||
|
||||
sudo sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
|
||||
echo "端口已经修改为$port_number,记得防火墙放行"
|
||||
;;
|
||||
*)
|
||||
clear
|
||||
esac
|
||||
|
@ -1,29 +0,0 @@
|
||||
declare pick
|
||||
declare path_script=$1
|
||||
echo "========Other========"
|
||||
echo "1.开启BBR"
|
||||
echo "2.更换系统语言"
|
||||
echo "3.申请SSL证书"
|
||||
echo "输入其他任意返回主页"
|
||||
echo "========Other========"
|
||||
read -p "请输入:" pick
|
||||
|
||||
case "$pick" in
|
||||
'1')
|
||||
declare version=$(uname -r | awk -F "." '{print $1}')
|
||||
if ! [[ $version -ge 5 ]];then
|
||||
echo "系统内核版本过低"
|
||||
exit
|
||||
fi
|
||||
grep -q "net.core.default_qdisc=fq" "/etc/sysctl.conf" || echo 'net.core.default_qdisc=fq' | sudo tee -a "/etc/sysctl.conf"
|
||||
grep -q "net.ipv4.tcp_congestion_control=bbr" "/etc/sysctl.conf" || echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a "/etc/sysctl.conf"
|
||||
sudo sysctl -p || echo "bbr 开启失败"
|
||||
sysctl net.ipv4.tcp_available_congestion_control | grep bbr && echo "bbr 开启成功"
|
||||
;;
|
||||
'2')
|
||||
bash "${path_script}/Config/Other/Language.sh"
|
||||
;;
|
||||
'3')
|
||||
bash "${path_script}/Config/Other/Acme.sh"
|
||||
;;
|
||||
esac
|
33
Run.sh
33
Run.sh
@ -1,33 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ! command -v sudo &> /dev/null; then
|
||||
echo "sudo未安装,部分命令无法正常运行"
|
||||
fi
|
||||
|
||||
|
||||
declare -a pick_array
|
||||
declare pick_number
|
||||
declare pick
|
||||
declare path_script=$(dirname $0)
|
||||
|
||||
while true
|
||||
do
|
||||
|
||||
pick_number=0
|
||||
echo "======Linux工具箱======"
|
||||
for i in "${path_script}/Menus"/*
|
||||
do
|
||||
pick_number=$((pick_number + 1))
|
||||
pick_array[$pick_number]=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
||||
echo "${pick_number}.${pick_array[$pick_number]}"
|
||||
done
|
||||
echo "======Linux工具箱======"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
if [[ "${pick}" -gt 0 && "${pick}" -le "${#pick_array[*]}" ]];then
|
||||
clear
|
||||
bash "${path_script}/Menus/${pick_array[$pick]}.sh" "$path_script"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
|
||||
done
|
63
run.sh
Normal file
63
run.sh
Normal file
@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $UID != 0 ]]; then
|
||||
echo "请以root权限执行该脚本"
|
||||
exit
|
||||
fi
|
||||
|
||||
declare -a pick_array
|
||||
declare pick_number
|
||||
declare pick
|
||||
declare path_script=$(dirname $0)
|
||||
path_script="${path_script}/Config"
|
||||
declare path_local=$path_script
|
||||
declare file_name
|
||||
|
||||
while true
|
||||
do
|
||||
if [[ -e "${path_local}/test.sh" ]]; then
|
||||
bash "${path_local}/test.sh"
|
||||
if [[ $? -eq 1 ]]; then
|
||||
path_local=$path_script
|
||||
fi
|
||||
fi
|
||||
if [[ -e "${path_local}/menu.sh" ]]; then
|
||||
clear
|
||||
bash "${path_local}/menu.sh" "$path_local"
|
||||
path_local=$path_script
|
||||
fi
|
||||
pick_number=0
|
||||
pick_array=()
|
||||
echo "======$(basename $path_local .sh)======"
|
||||
for i in "${path_local}"/*
|
||||
do
|
||||
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
|
||||
if [[ $file_name == "test" ]]; then
|
||||
continue
|
||||
fi
|
||||
pick_number=$((pick_number + 1))
|
||||
pick_array[$pick_number]=$file_name
|
||||
echo "${pick_number}.${pick_array[$pick_number]}"
|
||||
done
|
||||
|
||||
if [[ $path_local != $path_script ]]; then
|
||||
echo "输入任意返回主页"
|
||||
fi
|
||||
|
||||
read -p "请输入要使用的功能:" pick
|
||||
if [[ "${pick}" =~ [1-${#pick_array[*]}] ]];then
|
||||
clear
|
||||
if [[ -d "${path_local}/${pick_array[$pick]}" ]]; then
|
||||
path_local="${path_local}/${pick_array[$pick]}"
|
||||
elif [[ -e "${path_local}/${pick_array[$pick]}.sh" ]]; then
|
||||
bash "${path_local}/${pick_array[$pick]}.sh"
|
||||
path_local=$path_script
|
||||
fi
|
||||
else
|
||||
if [[ $path_local == $path_script ]]; then
|
||||
exit
|
||||
fi
|
||||
path_local=$path_script
|
||||
fi
|
||||
|
||||
done
|
Loading…
Reference in New Issue
Block a user