用ai格式化变量名和提示增加README

This commit is contained in:
lsy 2024-11-18 23:12:52 +08:00
parent 95891ac2f1
commit 7cd0bf71de
39 changed files with 848 additions and 786 deletions

View File

@ -1,6 +1,6 @@
declare path="$1" declare update_path="$1"
cat > "${path}/acme_update.sh" << EOF cat > "${update_path}/acme_update.sh" << EOF
#!/bin/bash #!/bin/bash
${HOME}/.acme.sh/acme.sh --upgrade ${HOME}/.acme.sh/acme.sh --upgrade
${HOME}/.acme.sh/acme.sh --renew-all --force ${HOME}/.acme.sh/acme.sh --renew-all --force

View File

@ -1,49 +1,47 @@
#!/bin/bash #!/bin/bash
declare path="$1" declare backup_path="$1"
declare web_path declare data_directory
declare local_pick declare local_backup_choice
declare baidu_pick declare baidu_backup_choice
declare aliyun_pick declare aliyun_backup_choice
declare ignore=1 declare ignore_flag=1
read -p "请输入数据目录,默认 /var/www " data_directory
read -p "请输入数据目录,默认 /var/www " web_path if [[ -z ${data_directory} ]];then
if [[ -z ${web_path} ]];then data_directory='/var/www'
web_path='/var/www'
fi fi
for item in "$web_path"/* ; do for item in "$data_directory"/* ; do
[[ $ignore -eq 1 ]] && echo "当前脚本会备份的目录如下" && ignore= [[ $ignore_flag -eq 1 ]] && echo "当前脚本会备份的目录如下" && ignore_flag=
declare item_name=$(basename "$item") declare item_name=$(basename "$item")
echo "${item_name}" echo "${item_name}"
done done
echo "请输入需要屏蔽的目录 空格 隔开" echo "请输入需要屏蔽的目录用空格隔开"
read -p "请输入:" ignore read -p "请输入:" ignore
read -p "是否备份到本地,默认关闭,输入 y 开启:" local_backup_choice
read -p "是否备份到百度网盘,默认开启,输入 n 关闭:" baidu_backup_choice
read -p "是否备份到阿里云盘,默认开启,输入 n 关闭:" aliyun_backup_choice
read -p "是否备份到本地,默认 关闭 ,输入 y 开启:" local_pick if [[ ! $local_backup_choice =~ [Yy] && $baidu_backup_choice =~ [Nn] && $aliyun_backup_choice =~ [Nn] ]];then
read -p "是否备份到百度网盘,默认 开启 ,输入 n 关闭:" baidu_pick
read -p "是否备份到阿里云盘 默认 开启 输入 n 关闭:" aliyun_pick
if [[ ! $local_pick =~ [Yy] && $baidu_pick =~ [Nn] && $aliyun_pick =~ [Nn] ]];then
echo "没有选择备份的选项" echo "没有选择备份的选项"
exit exit
fi fi
if [[ $local_pick =~ [Yy] ]];then if [[ $local_backup_choice =~ [Yy] ]];then
declare loacl_path declare local_backup_path
read -p "请输入本地备份路径,默认 /var/webbackup " loacl_path read -p "请输入本地备份路径,默认 /var/webbackup " local_backup_path
if [[ -z $loacl_path ]];then if [[ -z $local_backup_path ]];then
loacl_path='/var/webbackup' local_backup_path='/var/webbackup'
fi fi
if [[ -d $loacl_path ]];then if [[ -d $local_backup_path ]];then
mkdir -p "$loacl_path" mkdir -p "$local_backup_path"
fi fi
fi fi
if [[ ! $baidu_pick =~ [Nn] ]];then if [[ ! $baidu_backup_choice =~ [Nn] ]];then
if [[ -f "/usr/bin/apt-get" ]];then if [[ -f "/usr/bin/apt-get" ]];then
sudo apt-get install python3-venv -y sudo apt-get install python3-venv -y
elif [[ -f "/usr/bin/apt" ]];then elif [[ -f "/usr/bin/apt" ]];then
@ -51,11 +49,11 @@ if [[ ! $baidu_pick =~ [Nn] ]];then
elif [[ -f "/usr/bin/pacman" ]];then elif [[ -f "/usr/bin/pacman" ]];then
sudo pacman -Sy python3-venv --noconfirm sudo pacman -Sy python3-venv --noconfirm
else else
echo "无法自动安装 python3-venv 请手动安装" echo "无法自动安装 python3-venv请手动安装"
exit exit
fi fi
python3 -m venv "${path}/venv" python3 -m venv "${backup_path}/venv"
source "${path}/venv/bin/activate" source "${backup_path}/venv/bin/activate"
pip install bypy pip install bypy
pip install requests pip install requests
echo "1. 将提示中的链接粘贴到浏览器中登录" echo "1. 将提示中的链接粘贴到浏览器中登录"
@ -64,27 +62,26 @@ if [[ ! $baidu_pick =~ [Nn] ]];then
bypy info bypy info
fi fi
if [[ ! $aliyun_backup_choice =~ [Nn] ]];then
if [[ ! $aliyun_pick =~ [Nn] ]];then if [[ ! -d "${backup_path}/aliyunpan" ]];then
if [[ ! -d "${path}/aliyunpan" ]];then wget -P "${backup_path}" https://github.com/tickstep/aliyunpan/releases/download/v0.3.2/aliyunpan-v0.3.2-linux-amd64.zip -O "${backup_path}/aliyunpan.zip"
wget -P "${path}" https://github.com/tickstep/aliyunpan/releases/download/v0.3.2/aliyunpan-v0.3.2-linux-amd64.zip -O "${path}/aliyunpan.zip" unzip "${backup_path}/aliyunpan.zip" -d "${backup_path}"
unzip "${path}/aliyunpan.zip" -d "${path}" rm "${backup_path}/aliyunpan.zip"
rm "${path}/aliyunpan.zip" mv "${backup_path}/$(ls "${backup_path}" | grep "aliyunpan")" "${backup_path}/aliyunpan"
mv "${path}/$(ls "${path}" | grep "aliyunpan")" "${path}/aliyunpan"
fi fi
if [[ "$( ${path}/aliyunpan/aliyunpan who)" == "未登录账号" ]];then if [[ "$( ${backup_path}/aliyunpan/aliyunpan who)" == "未登录账号" ]];then
${path}/aliyunpan/aliyunpan login ${backup_path}/aliyunpan/aliyunpan login
fi fi
fi fi
cat > "${path}/backup.sh" << EOF cat > "${backup_path}/backup.sh" << EOF
#!/bin/bash #!/bin/bash
declare date_time=\$(date +"%Y_%m_%d") # 日期格式 declare date_time=\$(date +"%Y_%m_%d") # 日期格式
declare year=\$(date +"%Y") #年份 declare year=\$(date +"%Y") #年份
declare ignore="$ignore" declare ignore="$ignore"
source "${path}/venv/bin/activate" source "${backup_path}/venv/bin/activate"
for item in "$web_path"/*; do for item in "$data_directory"/*; do
declare item_name=\$(basename "\$item") declare item_name=\$(basename "\$item")
if [[ "\$ignore" =~ \$item_name ]];then if [[ "\$ignore" =~ \$item_name ]];then
continue continue
@ -94,27 +91,27 @@ for item in "$web_path"/*; do
tar -czf "\${item_name}_\${date_time}.tar.gz" \$(ls) tar -czf "\${item_name}_\${date_time}.tar.gz" \$(ls)
docker compose up -d docker compose up -d
bypy upload "\${item_name}_\${date_time}.tar.gz" "/\${item_name}/" bypy upload "\${item_name}_\${date_time}.tar.gz" "/\${item_name}/"
${path}/aliyunpan/aliyunpan upload "\${item_name}_\${date_time}.tar.gz" "/网站/\${item_name}/\${year}/" ${backup_path}/aliyunpan/aliyunpan upload "\${item_name}_\${date_time}.tar.gz" "/网站/\${item_name}/\${year}/"
mkdir -p "${loacl_path}/\${year}/\${item_name}" && cp "\${item_name}_\${date_time}.tar.gz" "${loacl_path}/\${year}/\${item_name}" mkdir -p "${local_backup_path}/\${year}/\${item_name}" && cp "\${item_name}_\${date_time}.tar.gz" "${local_backup_path}/\${year}/\${item_name}"
rm "\${item_name}_\${date_time}.tar.gz" rm "\${item_name}_\${date_time}.tar.gz"
done done
EOF EOF
if [[ $local_pick == [Yy] ]];then if [[ $local_backup_choice == [Yy] ]];then
echo "本地备份路径:${web_path}/年份/目录名称" echo "本地备份路径:${data_directory}/年份/目录名称"
else else
sed -i '/mkdir.*/d' "${path}/backup.sh" sed -i '/mkdir.*/d' "${backup_path}/backup.sh"
fi fi
if [[ $baidu_pick == [Nn] ]];then if [[ $baidu_backup_choice == [Nn] ]];then
sed -i '/bypy.*/d' "${path}/backup.sh" sed -i '/bypy.*/d' "${backup_path}/backup.sh"
sed -i '/source.*/d' "${path}/backup.sh" sed -i '/source.*/d' "${backup_path}/backup.sh"
else else
echo "百度网盘备份路径:我的应用数据/bypy/目录名称" echo "百度网盘备份路径:我的应用数据/bypy/目录名称"
fi fi
if [[ $baidu_pick == [Nn] ]];then if [[ $aliyun_backup_choice == [Nn] ]];then
sed -i '/.*aliyunpan.*/d' "/var/script/backup.sh" sed -i '/.*aliyunpan.*/d' "${backup_path}/backup.sh"
else else
echo "阿里云盘备份路径:网盘/目录名称/日期" echo "阿里云盘备份路径:网盘/目录名称/日期"
fi fi

View File

@ -1,32 +1,32 @@
#!/bin/bash #!/bin/bash
declare path_local=$1 declare local_path=$1
declare pick declare user_choice
declare file_name declare selected_file
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
declare print_number=0 declare file_count=0
declare -a print_array declare -a file_array
for i in "${path_local}"/*;do for file in "${local_path}"/*;do
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") selected_file=$(awk -F '.' '{print $1}' <<< "$(basename $file)")
if [[ $file_name == "test" || $file_name == "menu" ]]; then if [[ $selected_file == "test" || $selected_file == "menu" ]]; then
continue continue
fi fi
print_number=$((print_number + 1)) file_count=$((file_count + 1))
print_array[$print_number]=$file_name file_array[$file_count]=$selected_file
echo "${print_number}.${file_name}" echo "${file_count}.${selected_file}"
done done
echo "输入其他任意返回主页" echo "输入其他任意返回主页"
read -p "请输入:" pick read -p "请输入:" user_choice
if [[ ! ${pick} =~ [1-$print_number] ]];then if [[ ! ${user_choice} =~ [1-$file_count] ]];then
exit exit
fi fi
read -p "请输入脚本存放路径(默认:/var/script)" path read -p "请输入脚本存放路径(默认:/var/script" script_path
if [[ -z $path ]];then if [[ -z $script_path ]];then
path='/var/script' script_path='/var/script'
fi fi
mkdir -p "$path" mkdir -p "$script_path"
echo "执行日期" echo "执行日期"
echo "星号(*):表示匹配任意值" echo "星号(*):表示匹配任意值"
@ -34,33 +34,33 @@ echo "逗号(,):用于分隔多个值"
echo "斜线(/):用于指定间隔值" echo "斜线(/):用于指定间隔值"
echo "连字符(-):用于指定范围" echo "连字符(-):用于指定范围"
declare tmp_time declare cron_expression
declare -a cron_array=("分钟 059" "小时 023" "天数 131" "月份 112" "星期 07" ) declare -a cron_fields=("分钟 059" "小时 023" "天数 131" "月份 112" "星期 07" )
for i in "${cron_array[@]}";do for field in "${cron_fields[@]}";do
read -p "${i},默认为 * " tmp_time read -p "${field},默认为 * " tmp_time
if [[ $tmp_time =~ ^[0-9]+$ || $tmp_time == '*' ]];then if [[ $tmp_time =~ ^[0-9]+$ || $tmp_time == '*' ]];then
cron+="${tmp_time} " cron_expression+="${tmp_time} "
elif [[ -z ${tmp_time} ]];then elif [[ -z ${tmp_time} ]];then
cron+='* ' cron_expression+='* '
else else
echo "输入错误" echo "输入错误"
exit exit
fi fi
done done
if [[ "$cron" == '* * * * * ' ]];then if [[ "$cron_expression" == '* * * * * ' ]];then
read "该脚本会无时无刻执行,请重新输入" read -p "该脚本会无时无刻执行,请重新输入"
exit exit
fi fi
if [[ -f "${path_local}/${print_array[pick]}.sh" ]];then if [[ -f "${local_path}/${file_array[user_choice]}.sh" ]];then
echo "该路径文件已经存在" echo "该路径文件已经存在"
fi fi
bash "${path_local}/${print_array[pick]}.sh" "$path" bash "${local_path}/${file_array[user_choice]}.sh" "$script_path"
chmod +x "${path}/${print_array[pick]}.sh" && echo "脚本执行权限添加成功" || echo "脚本执行权限添加失败" chmod +x "${script_path}/${file_array[user_choice]}.sh" && echo "脚本执行权限添加成功" || echo "脚本执行权限添加失败"
declare cron_job="${cron} ${path}/${print_array[pick]}.sh" declare cron_job="${cron_expression} ${script_path}/${file_array[user_choice]}.sh"
(crontab -l 2>/dev/null | grep -v "${print_array[pick]}.sh") | crontab - (crontab -l 2>/dev/null | grep -v "${file_array[user_choice]}.sh") | crontab -
(crontab -l 2>/dev/null; echo "$cron_job") | crontab - (crontab -l 2>/dev/null; echo "$cron_job") | crontab -
systemctl restart cron 2>> /dev/null && echo "自动任务配置成功" || echo "自动任务重启失败" systemctl restart cron 2>> /dev/null && echo "自动任务配置成功" || echo "自动任务重启失败"

View File

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/bash
declare path="$1" declare docker_compose_path="$1"
if ! command -v docker &> /dev/null; then if ! command -v docker &> /dev/null; then
echo "docker未安装" echo "未安装 Docker"
exit exit
fi fi
declare web_path declare data_directory
read -p "请输入数据目录,默认 /var/www " web_path read -p "请输入数据目录,默认 /var/www " data_directory
if [[ -z ${web_path} ]];then if [[ -z ${data_directory} ]];then
web_path='/var/www' data_directory='/var/www'
fi fi
cat > "${path}/up-docker_compose.sh" << EOF cat > "${docker_compose_path}/up-docker_compose.sh" << EOF
#!/bin/bash #!/bin/bash
for dir in "${web_path}"/*/; do for dir in "${data_directory}"/*/; do
cd "\$dir" || exit cd "\$dir" || exit
sudo docker compose pull sudo docker compose pull
sudo docker compose up -d sudo docker compose up -d

View File

@ -1,17 +1,17 @@
declare path="$1" declare update_path="$1"
echo '#!/bin/bash' > "${path}/update.sh" echo '#!/bin/bash' > "${update_path}/update.sh"
if [[ -f "/usr/bin/apt" ]];then if [[ -f "/usr/bin/apt" ]];then
echo 'sudo apt update -y' >> "${path}/update.sh" echo 'sudo apt update -y' >> "${update_path}/update.sh"
echo 'sudo apt-get dist-upgrad -y' >> "${path}/update.sh" echo 'sudo apt-get dist-upgrade -y' >> "${update_path}/update.sh"
elif [[ -f "/usr/bin/apt-get" ]];then elif [[ -f "/usr/bin/apt-get" ]];then
echo 'sudo apt-get update -y' >> "${path}/update.sh" echo 'sudo apt-get update -y' >> "${update_path}/update.sh"
echo 'sudo apt dist-upgrade -y' >> "${path}/update.sh" echo 'sudo apt dist-upgrade -y' >> "${update_path}/update.sh"
elif [[ -f "/usr/bin/pacman" ]];then elif [[ -f "/usr/bin/pacman" ]];then
sudo pacman -Syu --noconfirm sudo pacman -Syu --noconfirm
else else
rm "${path}/update.sh" rm "${update_path}/update.sh"
echo "暂不支持该系统配置自动更新软件" echo "暂不支持该系统的自动更新配置"
exit exit
fi fi

View File

@ -1,70 +1,70 @@
#!/bin/bash #!/bin/bash
echo "1.查看已安装的脚本" echo "1. 查看已安装的脚本"
echo "2. 删除脚本" echo "2. 删除脚本"
declare pick declare user_choice
read -p "请输入" pick read -p "请输入您的选择:" user_choice
declare path="/var/script" declare script_directory="/var/script"
echo "请输入脚本安装地址,默认${path}" echo "请输入脚本安装目录,默认是 ${script_directory}"
read -p "请输入:" path read -p "请输入:" script_directory
if [[ -z $path ]]; then if [[ -z $script_directory ]]; then
path="/var/script" script_directory="/var/script"
elif ! [[ -d $path ]]; then elif ! [[ -d $script_directory ]]; then
echo "该地址不存在目录" echo "该目录不存在"
fi fi
case $pick in case $user_choice in
'1') '1')
declare -a script_arr declare -a installed_scripts
declare script_name declare script_name
declare script_number=0 declare script_count=0
for i in "$path"/* ; do for script in "$script_directory"/* ; do
if [[ $i == "${path}/*" ]];then if [[ $script == "${script_directory}/*" ]];then
echo "该地址不存在脚本" echo "该目录没有脚本"
exit exit
fi fi
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") script_name=$(awk -F '.' '{print $1}' <<< "$(basename $script)")
if [[ $script_name == "linuxtool" ]]; then if [[ $script_name == "linuxtool" ]]; then
continue continue
fi fi
script_number=$(( script_number+1 )) script_count=$(( script_count+1 ))
echo "${script_number}.${script_name}" echo "${script_count}.${script_name}"
script_arr[$script_number]=$script_name installed_scripts[$script_count]=$script_name
done done
if [ ${#script_arr[@]} == 0 ]; then if [ ${#installed_scripts[@]} == 0 ]; then
echo "该地址不存在脚本" echo "该目录没有脚本"
exit exit
fi fi
;; ;;
'2') '2')
declare -a script_arr declare -a installed_scripts
declare script_name declare script_name
declare script_number=0 declare script_count=0
for i in "$path"/* ; do for script in "$script_directory"/* ; do
if [[ $i == "${path}/*" ]];then if [[ $script == "${script_directory}/*" ]];then
echo "该地址不存在脚本" echo "该目录没有脚本"
exit exit
fi fi
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") script_name=$(awk -F '.' '{print $1}' <<< "$(basename $script)")
if [[ $script_name == "linuxtool" ]]; then if [[ $script_name == "linuxtool" ]]; then
continue continue
fi fi
script_number=$(( script_number+1 )) script_count=$(( script_count+1 ))
echo "${script_number}.${script_name}" echo "${script_count}.${script_name}"
script_arr[$script_number]=$script_name installed_scripts[$script_count]=$script_name
done done
if [ ${#script_arr[@]} == 0 ]; then if [ ${#installed_scripts[@]} == 0 ]; then
echo "该地址不存在脚本" echo "该目录没有脚本"
exit exit
fi fi
read -p "请输入要删除的序号,多个用 空格 隔开" script_name read -p "请输入要删除的序号(多个用空格隔开)" script_name
for i in $script_name ; do for i in $script_name ; do
if [[ $i =~ [1-${#script_arr[@]}] ]]; then if [[ $i =~ [1-${#installed_scripts[@]}] ]]; then
echo "开始删除 ${script_arr[$i]}" echo "开始删除 ${installed_scripts[$i]}"
(crontab -l 2>/dev/null | grep -v "${script_arr[$i]}") | crontab - && echo "已删除脚本的自动任务" (crontab -l 2>/dev/null | grep -v "${installed_scripts[$i]}") | crontab - && echo "已删除脚本的自动任务"
rm -rf "$path/${script_arr[$i]}" &> /dev/null rm -rf "$script_directory/${installed_scripts[$i]}" &> /dev/null
echo "删除完成" echo "删除完成"
fi fi
done done

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare installation_directory=$1
declare port=$2 declare web_service_port=$2
cd $path cd $installation_directory
cat > "docker-compose.yml" << EOF cat > "docker-compose.yml" << EOF
version: '3.8' version: '3.8'
services: services:
@ -12,9 +12,9 @@ services:
volumes: volumes:
- ./:/opt/alist/data - ./:/opt/alist/data
ports: ports:
- "${port}:5244" - "${web_service_port}:5244"
EOF EOF
docker compose up -d || "安装失败" $$ exit docker compose up -d || echo "安装失败" && exit
declare password=$( docker exec -it alist ./alist admin random | grep password | awk '{print $4}') declare admin_password=$( docker exec -it alist ./alist admin random | grep password | awk '{print $4}')
echo "账号admin" echo "账号admin"
echo "密码:${password}" echo "密码:${admin_password}"

View File

@ -5,18 +5,18 @@ if ! command -v sudo &> /dev/null; then
exit exit
fi fi
declare path=$1 declare installation_directory=$1
declare port=$2 declare web_service_port=$2
sudo useradd -m git sudo useradd -m git
sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key" -f /home/git/.ssh/id_rsa -N "" sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key" -f /home/git/.ssh/id_rsa -N ""
sudo -u git sh -c 'cat /home/git/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys' sudo -u git sh -c 'cat /home/git/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys'
sudo -u git sh -c 'chmod a+x /usr/local/bin/gitea' sudo -u git sh -c 'chmod a+x /usr/local/bin/gitea'
sudo -u git sh -c 'echo "ssh -p '$(( port+22 ))' -o StrictHostKeyChecking=no git@127.0.0.1 \"SSH_ORIGINAL_COMMAND=\\\"\$SSH_ORIGINAL_COMMAND\\\" \$0 \$@\"" > /usr/local/bin/gitea' sudo -u git sh -c 'echo "ssh -p '$(( web_service_port+22 ))' -o StrictHostKeyChecking=no git@127.0.0.1 \"SSH_ORIGINAL_COMMAND=\\\"\$SSH_ORIGINAL_COMMAND\\\" \$0 \$@\"" > /usr/local/bin/gitea'
declare uid=$( id git | awk -F'[=() ]+' '{print $2}' ) declare user_id=$( id git | awk -F'[=() ]+' '{print $2}' )
declare gid=$( id git | awk -F'[=() ]+' '{print $5}' ) declare group_id=$( id git | awk -F'[=() ]+' '{print $5}' )
cd $path cd $installation_directory
cat > "docker-compose.yml" << EOF cat > "docker-compose.yml" << EOF
networks: networks:
gitea: gitea:
@ -26,8 +26,8 @@ services:
image: gitea/gitea:latest image: gitea/gitea:latest
container_name: gitea container_name: gitea
environment: environment:
- USER_UID=${uid} - USER_UID=${user_id}
- USER_GID=${gid} - USER_GID=${group_id}
- GITEA__database__DB_TYPE=mysql - GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=db:3306 - GITEA__database__HOST=db:3306
- GITEA__database__NAME=gitea - GITEA__database__NAME=gitea
@ -42,8 +42,8 @@ services:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
- /home/git/.ssh/:/data/git/.ssh - /home/git/.ssh/:/data/git/.ssh
ports: ports:
- "${port}:3000" - "${web_service_port}:3000"
- "$(( port+22 )):22" - "$(( web_service_port+22 )):22"
depends_on: depends_on:
- db - db
db: db:
@ -59,6 +59,6 @@ services:
volumes: volumes:
- ./mysql:/var/lib/mysql - ./mysql:/var/lib/mysql
EOF EOF
chown -R git:git $path chown -R git:git $installation_directory
sudo docker compose up -d sudo docker compose up -d

View File

@ -1,57 +1,57 @@
#!/bin/bash #!/bin/bash
declare path_local=$1 declare local_directory=$1
declare pick declare user_choice
declare file_name declare selected_file_name
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
declare print_number=0 declare file_count=0
declare -a print_array declare -a file_array
for i in "${path_local}"/*;do for file in "${local_directory}"/*;do
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") selected_file_name=$(awk -F '.' '{print $1}' <<< "$(basename $file)")
if [[ $file_name == "test" || $file_name == "menu" ]]; then if [[ $selected_file_name == "test" || $selected_file_name == "menu" ]]; then
continue continue
fi fi
print_number=$((print_number + 1)) file_count=$((file_count + 1))
print_array[$print_number]=$file_name file_array[$file_count]=$selected_file_name
echo "${print_number}.${file_name}" echo "${file_count}.${selected_file_name}"
done done
echo "输入其他任意返回主页" echo "输入其他字符返回主页"
read -p "请输入:" pick read -p "请输入:" user_choice
if [[ ! ${pick} =~ [1-$print_number] ]];then if [[ ! ${user_choice} =~ [1-$file_count] ]];then
exit exit
fi fi
declare file_path declare storage_path
read -p "请输入软件储存位置,默认 /var/www/${print_array[${pick}]} " file_path read -p "请输入软件存储位置,默认 /var/www/${file_array[${user_choice}]} " storage_path
if [[ -z ${file_path} ]];then if [[ -z ${storage_path} ]];then
file_path="/var/www/${print_array[${pick}]}" storage_path="/var/www/${file_array[${user_choice}]}"
fi fi
if [[ ! -d "$file_path" ]];then if [[ ! -d "$storage_path" ]];then
sudo mkdir -p "$file_path" || { echo "目录创建失败"; exit 1; } sudo mkdir -p "$storage_path" || { echo "目录创建失败"; exit 1; }
elif [[ ! -z "$(find "$file_path" -mindepth 1 -print -quit)" ]];then elif [[ ! -z "$(find "$storage_path" -mindepth 1 -print -quit)" ]];then
echo "该目录存有文件" echo "该目录存有文件"
exit exit
fi fi
declare dport=$(($RANDOM % 9000 + 1000)) declare random_port=$(($RANDOM % 9000 + 1000))
while ss -tuln | grep $dport &> /dev/null while ss -tuln | grep $random_port &> /dev/null
do do
dport=$(($RANDOM % 9000 + 1000)) random_port=$(($RANDOM % 9000 + 1000))
done done
declare port declare access_port
read -p "请输入访问端口,默认 $dport " port read -p "请输入访问端口,默认 $random_port " access_port
if [[ -z $port ]];then if [[ -z $access_port ]];then
port=$dport access_port=$random_port
fi fi
if ss -tuln | grep $port &> /dev/null;then if ss -tuln | grep $access_port &> /dev/null;then
echo "端口已被占用" echo "端口已被占用"
exit exit
fi fi
bash "${path_local}/${print_array[pick]}.sh" "$file_path" "$port" bash "${local_directory}/${file_array[user_choice]}.sh" "$storage_path" "$access_port"
echo "${print_array[${pick}]}安装完成,访问端口${port}" echo "${file_array[${user_choice}]} 安装完成,访问端口 ${access_port}"

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare installation_directory=$1
declare port=$2 declare web_service_port=$2
cd $path cd $installation_directory
cat > docker-compose.yml << EOF cat > docker-compose.yml << EOF
services: services:
app: app:
@ -11,11 +11,11 @@ services:
ports: ports:
- '80:80' - '80:80'
- '443:443' - '443:443'
- '${port}:81' - '${web_service_port}:81'
volumes: volumes:
- ./data:/data - ./data:/data
- ./letsencrypt:/etc/letsencrypt - ./letsencrypt:/etc/letsencrypt
EOF EOF
docker compose up -d docker compose up -d
echo "Email: admin@example.com" echo "管理员邮箱: admin@example.com"
echo "Password: changeme" echo "管理员密码: changeme"

View File

@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare installation_directory=$1
declare port=$2 declare management_port=$2
cd $path cd $installation_directory
wget "https://waf-ce.chaitin.cn/release/latest/compose.yaml" wget "https://waf-ce.chaitin.cn/release/latest/compose.yaml"
cat > ".env" << EOF cat > ".env" << EOF
SAFELINE_DIR=$path SAFELINE_DIR=$installation_directory
IMAGE_TAG=latest IMAGE_TAG=latest
MGT_PORT=$port MGT_PORT=$management_port
POSTGRES_PASSWORD="safeline" POSTGRES_PASSWORD="safeline"
SUBNET_PREFIX=172.22.222 SUBNET_PREFIX=172.22.222
IMAGE_PREFIX=swr.cn-east-3.myhuaweicloud.com/chaitin-safeline IMAGE_PREFIX=swr.cn-east-3.myhuaweicloud.com/chaitin-safeline
EOF EOF
docker compose up -d || "安装失败" $$ exit docker compose up -d || echo "安装失败" && exit
declare password=$( docker exec safeline-mgt resetadmin &> /dev/null | grep password | awk -F "" '{print $2}' ) declare admin_password=$( docker exec safeline-mgt resetadmin &> /dev/null | grep password | awk -F "" '{print $2}' )
echo "账号admin" echo "账号admin"
echo "密码:${password}" echo "密码:${admin_password}"

View File

@ -1,15 +1,15 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare installation_directory=$1
declare port=$2 declare web_service_port=$2
declare password declare access_password
read -p "请输入思源访问密码,(默认 Siyuan )" password read -p "请输入思源访问密码默认Siyuan" access_password
if [[ -z $password ]];then if [[ -z $access_password ]];then
password="Siyuan" access_password="Siyuan"
fi fi
chown -R 1000:1000 $path chown -R 1000:1000 $installation_directory
cd $path cd $installation_directory
cat > "docker-compose.yml" << EOF cat > "docker-compose.yml" << EOF
version: "3.9" version: "3.9"
services: services:
@ -19,13 +19,13 @@ services:
user: '1000:1000' user: '1000:1000'
restart: always restart: always
ports: ports:
- $port:6806 - $web_service_port:6806
volumes: volumes:
- ./:/siyuan/workspace - ./:/siyuan/workspace
command: command:
- "--workspace=/siyuan/workspace/" - "--workspace=/siyuan/workspace/"
- "--lang=zh_CN" - "--lang=zh_CN"
- "--accessAuthCode=$password" - "--accessAuthCode=$access_password"
EOF EOF
docker compose up -d || "安装失败" $$ exit docker compose up -d || echo "安装失败" && exit
echo "访问密码:$password" echo "访问密码:$access_password"

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare installation_directory=$1
declare port=$2 declare web_service_port=$2
cd $path cd $installation_directory
mkdir data mkdir data
mkdir php mkdir php
@ -55,7 +55,7 @@ services: # 定义多个服务
nginx: # 服务名称 nginx: # 服务名称
image: nginx # 使用的镜像 image: nginx # 使用的镜像
ports: # 映射的端口 ports: # 映射的端口
- "${port}:80" # 宿主机端口 ${port} 映射到容器端口 80 - "${web_service_port}:80" # 宿主机端口 ${web_service_port} 映射到容器端口 80
restart: always # 容器重启策略 restart: always # 容器重启策略
volumes: # 映射文件 volumes: # 映射文件
- ./data:/var/www/html # 网站源代码 - ./data:/var/www/html # 网站源代码
@ -99,14 +99,12 @@ wget https://github.com/typecho/typecho/releases/download/v1.2.1/typecho.zip -O
unzip typecho.zip unzip typecho.zip
rm typecho.zip rm typecho.zip
cd $path cd $installation_directory
sudo chown -R 1000:1000 $path
sudo chown -R 1000:1000 $installation_directory
sudo chmod -R 777 data sudo chmod -R 777 data
sudo docker compose up -d sudo docker compose up -d
echo "数据库地址mysql" echo "数据库地址mysql"
@ -114,6 +112,6 @@ echo "数据库用户名root"
echo "数据库密码typecho" echo "数据库密码typecho"
echo "数据库名typecho" echo "数据库名typecho"
echo "安装完成${path}/data/config.inc.php末尾加上,防止排版错误" echo "安装完成,请在${installation_directory}/data/config.inc.php末尾添加防止排版错误"
echo "define('__TYPECHO_SECURE__',true);" echo "define('__TYPECHO_SECURE__',true);"

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare installation_directory=$1
declare port=$2 declare web_service_port=$2
declare password declare admin_password
read -p "请输入管理员密码(不输入则关闭管理员)" password read -p "请输入管理员密码(不输入则关闭管理员功能):" admin_password
cd $path cd $installation_directory
cat > "docker-compose.yml" << EOF cat > "docker-compose.yml" << EOF
version: '3.8' version: '3.8'
services: services:
@ -17,14 +17,14 @@ services:
- SIGNUPS_ALLOWED=true - SIGNUPS_ALLOWED=true
- WEBSOCKET_ENABLED=true - WEBSOCKET_ENABLED=true
- TZ=Asia/Shanghai - TZ=Asia/Shanghai
- ADMIN_TOKEN="$password" - ADMIN_TOKEN="$admin_password"
volumes: volumes:
- ./:/data/ - ./:/data/
ports: ports:
- "${port}:80" - "${web_service_port}:80"
EOF EOF
if [[ -z $password ]];then if [[ -z $admin_password ]];then
sed -i '/.*ADMIN_TOKEN=.*/d' "docker-compose.yml" sed -i '/.*ADMIN_TOKEN=.*/d' "docker-compose.yml"
fi fi
@ -34,11 +34,11 @@ wget https://github.com/wcjxixi/vaultwarden-lang-zhcn/archive/refs/heads/main.zi
unzip main.zip unzip main.zip
rm main.zip rm main.zip
cd vaultwarden-lang-zhcn-main cd vaultwarden-lang-zhcn-main
declare admin=$( ls | grep "admin" | tac | head -n 1 ) declare admin_file=$( ls | grep "admin" | tac | head -n 1 )
declare email=$( ls | grep "email" | tac | head -n 1 ) declare email_file=$( ls | grep "email" | tac | head -n 1 )
mv "$admin" "../admin" mv "$admin_file" "../admin"
mv "$email" "../email" mv "$email_file" "../email"
cd .. cd ..
rm -rf vaultwarden-lang-zhcn-main rm -rf vaultwarden-lang-zhcn-main
docker compose up -d || echo "安装失败" && exit docker compose up -d || echo "安装失败" && exit
echo "需要反向代理,使用https,才能正常使用" echo "需要反向代理使用HTTPS才能正常使用"

View File

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/bash
declare path=$1 declare install_path=$1
declare port=$2 declare service_port=$2
cd $path cd $install_path
declare namediv=$(basename $path) declare project_name=$(basename $install_path)
cd .. cd ..
rm -rf "$namediv" rm -rf "$project_name"
git clone -b docker-compose --depth 1 https://github.com/cedar2025/Xboard git clone -b docker-compose --depth 1 https://github.com/cedar2025/Xboard
if [[ "$namediv" != Xboard ]];then if [[ "$project_name" != Xboard ]];then
mv Xboard "$namediv" mv Xboard "$project_name"
fi fi
cd "$path" cd "$install_path"
docker compose run -it --rm xboard php artisan xboard:install docker compose run -it --rm xboard php artisan xboard:install

View File

@ -1,29 +1,29 @@
#!/bin/bash #!/bin/bash
echo "1. 查看当前运行中的镜像" echo "1. 查看当前运行中的镜像"
echo "2. 停止镜像" echo "2. 停止镜像"
echo "3.删除没有使用的镜像" echo "3. 删除未使用的镜像"
declare pick declare user_choice
read -p "请输入" pick read -p "请输入选项:" user_choice
case $pick in case $user_choice in
'1') '1')
docker ps --format "{{.Names}}" docker ps --format "{{.Names}}"
;; ;;
'2') '2')
declare -a docker_arr=($(docker ps --format "{{.Names}}")) declare -a running_images=($(docker ps --format "{{.Names}}"))
declare docker_number=0 declare image_count=0
for i in "${docker_arr[@]}" ; do for image in "${running_images[@]}" ; do
docker_number=$(( docker_number+1 )) image_count=$(( image_count+1 ))
echo "${docker_number}.${i}" echo "${image_count}.${image}"
done done
echo "要停止的镜像序号,多个镜像用 空格 隔开" echo "要停止的镜像序号,多个镜像用空格隔开"
read -p "请输入:" pick read -p "请输入:" user_choice
for i in $pick ; do for i in $user_choice ; do
if [[ $i =~ [1-$docker_number] ]]; then if [[ $i =~ [1-$image_count] ]]; then
echo "正在停止 ${docker_arr[$(( i -1 ))]}" echo "正在停止 ${running_images[$(( i -1 ))]}"
docker stop "${docker_arr[$(( i -1 ))]}" docker stop "${running_images[$(( i -1 ))]}"
echo "${docker_arr[$(( i -1 ))]} 已经停止" echo "${running_images[$(( i -1 ))]} 已经停止"
fi fi
done done
;; ;;

View File

@ -1,51 +1,50 @@
#!/bin/bash #!/bin/bash
echo "1.查看已安装的站点" echo "1. 查看已安装的站点"
echo "2. 删除软件" echo "2. 删除软件"
declare pick declare user_choice
read -p "请输入:" pick read -p "请输入:" user_choice
declare path="/var/www" declare site_path="/var/www"
echo "请输入站点安装地址,默认${path}" echo "请输入站点安装地址,默认 ${site_path}"
read -p "请输入:" path read -p "请输入:" site_path
if [[ -z $path ]]; then if [[ -z $site_path ]]; then
path="/var/www" site_path="/var/www"
elif ! [[ -d $path ]]; then elif ! [[ -d $site_path ]]; then
echo "该地址不存在目录" echo "该地址不存在目录"
fi fi
case $user_choice in
case $pick in
'1') '1')
for i in "$path"/* ; do for site in "$site_path"/* ; do
if [[ $i == "${path}/*" ]];then if [[ $site == "${site_path}/*" ]];then
echo "该地址不存在站点" echo "该地址不存在站点"
fi fi
echo $i echo $site
done done
;; ;;
'2') '2')
declare -a site_arr declare -a site_array
declare site_name declare site_name
declare site_number=0 declare site_number=0
for i in "$path"/* ; do for site in "$site_path"/* ; do
if [[ $i == "${path}/*" ]];then if [[ $site == "${site_path}/*" ]];then
echo "该地址不存在站点" echo "该地址不存在站点"
exit exit
fi fi
site_number=$(( site_number+1 )) site_number=$(( site_number+1 ))
site_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") site_name=$(awk -F '.' '{print $1}' <<< "$(basename $site)")
echo "${site_number}.${site_name}" echo "${site_number}.${site_name}"
site_arr[$site_number]=$site_name site_array[$site_number]=$site_name
done done
read -p "请输入要删除的序号,多个用 空格 隔开:" site_name read -p "请输入要删除的序号,多个用空格隔开:" selected_sites
for i in $site_name ; do for i in $selected_sites ; do
if [[ $i =~ [1-${#site_arr[*]}] ]]; then if [[ $i =~ [1-${#site_array[*]}] ]]; then
echo "开始删除 ${site_arr[$i]}" echo "开始删除 ${site_array[$i]}"
cd "$path/${site_arr[$i]}" cd "$site_path/${site_array[$i]}"
docker compose down &> /dev/null && echo "站点已停止运行" docker compose down &> /dev/null && echo "站点已停止运行"
rm -rf "$path/${site_arr[$i]}" &> /dev/null rm -rf "$site_path/${site_array[$i]}" &> /dev/null
echo "删除完成" echo "删除完成"
fi fi
done done

View File

@ -2,42 +2,42 @@
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "1. 查看当前源" echo "1. 查看当前源"
echo "2. 换源" echo "2. 换源"
declare pick declare user_choice
read -p "请输入:" pick read -p "请输入:" user_choice
case $pick in case $user_choice in
'1') '1')
grep -oP '(https?://[^\"]+)' /etc/docker/daemon.json grep -oP '(https?://[^\"]+)' /etc/docker/daemon.json
;; ;;
'2') '2')
declare -A img_dick declare -A mirror_options
declare -a img_number declare -a mirror_list
declare img_pick=0 declare mirror_choice=0
img_dick['Daocloud(默认)']='https://docker.m.daocloud.io' mirror_options['Daocloud(默认)']='https://docker.m.daocloud.io'
img_dick['官方']='docker.io' mirror_options['官方']='docker.io'
for i in "${!img_dick[@]}"; for mirror in "${!mirror_options[@]}";
do do
img_pick=$(( img_pick+1 )) mirror_choice=$(( mirror_choice+1 ))
img_number[$img_pick]=$i mirror_list[$mirror_choice]=$mirror
echo "${img_pick}.${i}" echo "${mirror_choice}.${mirror}"
done done
read -p "请输入要选择的镜像,也可直接输入镜像网站:" img_pick read -p "请输入要选择的镜像,也可直接输入镜像网站:" selected_mirror
if [[ -z $img_pick ]];then if [[ -z $selected_mirror ]];then
declare url='https://docker.m.daocloud.io' declare url='https://docker.m.daocloud.io'
elif [[ $img_pick =~ [\w\.]+ ]];then elif [[ $selected_mirror =~ [\w\.]+ ]];then
declare url=$img_pick declare url=$selected_mirror
elif [[ ${img_pick} =~ [1-${!img_dick[*]}] ]];then elif [[ ${selected_mirror} =~ [1-${!mirror_options[*]}] ]];then
img_pick=${img_number[$img_pick]} selected_mirror=${mirror_list[$selected_mirror]}
declare url=${img_dick[$img_pick]} declare url=${mirror_options[$selected_mirror]}
else else
echo "输入错误" echo "输入错误"
exit exit
fi fi
echo "正在写入配置文件" echo "正在写入配置文件"
echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json" echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json"
echo "正在重启docker" echo "正在重启 Docker"
systemctl restart docker 2>> /dev/null || echo "docker 重启失败"&&exit systemctl restart docker 2>> /dev/null || echo "Docker 重启失败"&&exit
echo "换源成功" echo "换源成功"
;; ;;

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
if ! command -v docker &> /dev/null; then if ! command -v docker &> /dev/null; then
echo "docker未安装" echo "Docker 未安装"
exit 1 exit 1
fi fi

View File

@ -39,7 +39,6 @@ declare url
echo "请选择脚本的下载地址" echo "请选择脚本的下载地址"
url_dick['github(default)']='https://github.com/lsy2246/linuxtool.git' url_dick['github(default)']='https://github.com/lsy2246/linuxtool.git'
url_dick['gitee']='https://gitee.com/lsy22/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 for i in "${!url_dick[@]}" ; do
url_number=$(( url_number+1 )) url_number=$(( url_number+1 ))

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
declare path=$(cat /etc/profile | grep "tool=" | awk -F "=" '{print $2}' | tr -d "'") declare tool_path=$(cat /etc/profile | grep "tool=" | awk -F "=" '{print $2}' | tr -d "'")
path=$(dirname $path) tool_path=$(dirname $tool_path)
rm -rf $path rm -rf $tool_path
if [[ -e "${HOME}/.bashrc" ]];then if [[ -e "${HOME}/.bashrc" ]];then
sed -i '/alias tool.*/d' "${HOME}/.bashrc" sed -i '/alias tool.*/d' "${HOME}/.bashrc"
source "${HOME}/.bashrc" &> /dev/null source "${HOME}/.bashrc" &> /dev/null
@ -18,5 +18,5 @@ if [[ -e "${HOME}/.zshrc" ]];then
fi fi
sed -i '/alias tool.*/d' "/etc/profile" sed -i '/alias tool.*/d' "/etc/profile"
echo "脚本已经卸载完整,公众号 lsy22 可以获取一键安装脚本" echo "脚本已完整卸载,公众号 lsy22 可获取一键安装脚本"
kill $PPID &> /dev/null kill $PPID &> /dev/null

View File

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
declare version=$(uname -r | awk -F "." '{print $1}') declare kernel_version=$(uname -r | awk -F "." '{print $1}')
if ! [[ $version -ge 5 ]];then if ! [[ $kernel_version -ge 5 ]];then
echo "系统内核版本过低" echo "系统内核版本过低"
exit exit
fi 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.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" 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 -p || echo "BBR 开启失败"
sysctl net.ipv4.tcp_available_congestion_control | grep bbr && echo "bbr 开启成功" sysctl net.ipv4.tcp_available_congestion_control | grep bbr && echo "BBR 开启成功"

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
declare lang declare language_choice
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "1. 中文" echo "1. 中文"
echo "2. 英文" echo "2. 英文"
read -p "请输入:" lang read -p "请输入:" language_choice
if [[ -f "/usr/bin/apt-get" ]];then if [[ -f "/usr/bin/apt-get" ]];then
apt-get update -y apt-get update -y
apt-get install -y locales apt-get install -y locales
@ -21,7 +21,7 @@ sed -i '/^#/! s/^/# /' /etc/locale.gen
if ! grep LC_ALL /etc/default/locale &> /dev/null; then if ! grep LC_ALL /etc/default/locale &> /dev/null; then
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
fi fi
case $lang in case $language_choice in
'1') '1')
sed -i 's/.*zh_CN.UTF-8.*/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen 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/^LANG.*/LANG=zh_CN.UTF-8/g" /etc/default/locale

View File

@ -1,54 +1,54 @@
#!/bin/bash #!/bin/bash
declare pick declare server_choice
declare server declare download_server
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "请选择下载服务器" echo "请选择下载服务器"
echo "1. 国内服务器" echo "1. 国内服务器"
echo "2.国外服务器(默认)" echo "2. 国外服务器(默认)"
read -p "请输入:" pick read -p "请输入:" server_choice
if [[ $pick == '1' ]];then if [[ $server_choice == '1' ]];then
server="https://jihulab.com/bin456789/reinstall/-/raw/main/reinstall.sh" download_server="https://jihulab.com/bin456789/reinstall/-/raw/main/reinstall.sh"
else else
server="https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh" download_server="https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh"
fi fi
declare -A imags_dick declare -A image_options
declare -a imags_arr declare -a image_list
declare imags_number=0 declare image_count=0
imags_dick['arch']="" image_options['arch']=""
imags_dick['kali']="" image_options['kali']=""
imags_dick['debian']="8 9 10 11 12" image_options['debian']="8 9 10 11 12"
imags_dick['Ubuntu']="16.04 18.04 20.04 22.04 24.04" image_options['Ubuntu']="16.04 18.04 20.04 22.04 24.04"
for i in "${!imags_dick[@]}" ; do for image in "${!image_options[@]}" ; do
imags_number=$(( imags_number+1 )) image_count=$(( image_count+1 ))
imags_arr[$imags_number]=$i image_list[$image_count]=$image
echo "${imags_number}.${i}" echo "${image_count}.${image}"
done done
read -p "请选择需要安装的镜像序号:" pick read -p "请选择需要安装的镜像序号:" selected_image
if [[ $pick =~ [1-"${#imags_dick[@]}"\ ] ]];then if [[ $selected_image =~ [1-"${#image_options[@]}"\ ] ]];then
declare img=${imags_arr[$pick]} declare selected_image_name=${image_list[$selected_image]}
declare version='' declare selected_version=''
declare -a version_arr declare -a version_list
declare version_number=0 declare version_count=0
if [[ ! -z ${imags_dick[$img]} ]];then if [[ ! -z ${image_options[$selected_image_name]} ]];then
echo "请输入要安装的版本(默认最新)" echo "请输入要安装的版本(默认最新)"
for i in ${imags_dick[$img]} ; do for version in ${image_options[$selected_image_name]} ; do
version_number=$(( version_number+1 )) version_count=$(( version_count+1 ))
version_arr[$version_number]=$i version_list[$version_count]=$version
echo "${version_number}.${i}" echo "${version_count}.${version}"
done done
read -p "请输入:" pick read -p "请输入:" selected_version
if [ -z $pick ]; then if [ -z $selected_version ]; then
version=${version_arr[$version_number]} selected_version=${version_list[$version_count]}
elif [[ $pick =~ [1-$version_number] ]];then elif [[ $selected_version =~ [1-$version_count] ]];then
version=${version_arr[$pick]} selected_version=${version_list[$selected_version]}
fi fi
fi fi
eval "bash <(curl -Ls ${server}) ${img} ${version}" eval "bash <(curl -Ls ${download_server}) ${selected_image_name} ${selected_version}"
echo "重启后开始重装系统" echo "重启后开始重装系统"
echo "用服务器厂家的 VNC 连接可以看到重装进度" echo "用服务器厂家的 VNC 连接可以看到重装进度"
else else
echo "选择错误" echo "选择错误"

View File

@ -2,21 +2,21 @@
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "1. 生成密钥" echo "1. 生成密钥"
echo "2. 安装密钥" echo "2. 安装密钥"
echo "输入其他返回主页" echo "输入其他字符返回主页"
declare pick declare user_choice
read -p "请输入要选择的命令:" pick read -p "请输入要选择的命令:" user_choice
function open_key() { function configure_key() {
chmod 600 "$HOME/.ssh/authorized_keys" chmod 600 "$HOME/.ssh/authorized_keys"
chmod 700 "$HOME/.ssh" chmod 700 "$HOME/.ssh"
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
declare pick2 declare user_input
echo "是否关闭密码登录:" echo "是否关闭密码登录:"
read -p "输入 n 取消关闭:" pick2 read -p "输入 n 取消关闭:" user_input
if [[ ! $pick2 =~ [Nn] ]];then if [[ ! $user_input =~ [Nn] ]];then
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
fi fi
@ -25,90 +25,90 @@ function open_key() {
echo "密钥安装完成" echo "密钥安装完成"
} }
case $pick in case $user_choice in
'1') '1')
declare site="${HOME}/.ssh" declare key_directory="${HOME}/.ssh"
read -p "请输入密钥安装位置,默认 ${site}" pick read -p "请输入密钥安装位置, 默认:${key_directory}" user_input
if [[ -d $pick ]]; then if [[ -d $user_input ]]; then
site=$pick key_directory=$user_input
elif [[ ! -z $pick ]];then elif [[ ! -z $user_input ]];then
echo "该路径没有文件夹" echo "该路径没有文件夹"
exit exit
fi fi
declare bit="" declare key_size=""
declare type="" declare key_type=""
declare phrase="" declare passphrase=""
declare -A type_dick declare -A key_options
type_dick['rsa']="2048 4096" key_options['rsa']="2048 4096"
type_dick['ed25519']="" key_options['ed25519']=""
declare print_number=0 declare option_count=0
declare -a print_arr declare -a option_array
for i in "${!type_dick[@]}" ; do for i in "${!key_options[@]}" ; do
print_number=$(( print_number+1 )) option_count=$(( option_count+1 ))
print_arr[$print_number]=$i option_array[$option_count]=$i
echo "${print_number}.${i}" echo "${option_count}.${i}"
done done
read -p "请选择要生成的密钥类型:" pick read -p "请选择要生成的密钥类型:" user_input
if ! [[ $pick =~ [1-${#type_dick[@]}] ]]; then if ! [[ $user_input =~ [1-${#key_options[@]}] ]]; then
echo "选择错误" echo "选择错误"
exit exit
fi fi
type=${print_arr[$pick]} key_type=${option_array[$user_input]}
if [ ! -z "${type_dick[$type]}" ]; then if [ ! -z "${key_options[$key_type]}" ]; then
print_number=0 option_count=0
echo "请选择密钥位大小" echo "请选择密钥位大小"
for i in ${type_dick[$type]} ; do for i in ${key_options[$key_type]} ; do
print_number=$(( print_number+1 )) option_count=$(( option_count+1 ))
print_arr[$print_number]=$i option_array[$option_count]=$i
echo "${print_number}.${i}" echo "${option_count}.${i}"
done done
read -p "请选择:" pick read -p "请选择:" user_input
if ! [[ $pick =~ [1-${#print_arr[@]}] ]]; then if ! [[ $user_input =~ [1-${#option_array[@]}] ]]; then
echo "选择错误" echo "选择错误"
exit exit
fi fi
bit="-b ${print_arr[$pick]}" key_size="-b ${option_array[$user_input]}"
fi fi
read -p "是否开启密钥短语,输入y开启,请输入:" pick read -p "是否开启密钥短语输入y开启请输入" user_input
if [[ $pick =~ [Yy] ]]; then if [[ $user_input =~ [Yy] ]]; then
read -p "请输入要设置的密钥短语" phrase read -p "请输入要设置的密钥短语" passphrase
fi fi
eval "ssh-keygen -t ${type} ${bit} -N '${phrase}' -f '${site}/key' -q" eval "ssh-keygen -t ${key_type} ${key_size} -N '${passphrase}' -f '${key_directory}/key' -q"
echo "密钥安装成功" echo "密钥安装成功"
echo "私钥:${site}/key" echo "私钥:${key_directory}/key"
echo "公钥:${site}/key.pub" echo "公钥:${key_directory}/key.pub"
read -p "是否开启密钥登录,输入n取消" pick read -p "是否开启密钥登录输入n取消" user_input
if ! [[ $pick =~ [Nn] ]]; then if ! [[ $user_input =~ [Nn] ]]; then
mkdir -p "$HOME/.ssh" mkdir -p "$HOME/.ssh"
echo "${site}/key.pub" > "$HOME/.ssh/authorized_keys" echo "${key_directory}/key.pub" > "$HOME/.ssh/authorized_keys"
open_key configure_key
fi fi
;; ;;
'2') '2')
declare key declare public_key
echo "请输入公钥或文件路径:" echo "请输入公钥或文件路径:"
echo "默认:$HOME/.ssh/id_rsa.pub" echo "默认:$HOME/.ssh/id_rsa.pub"
read -p "回车默认:" key read -p "回车默认:" public_key
if [[ -z $key ]];then if [[ -z $public_key ]];then
key="$HOME/.ssh/id_rsa.pub" public_key="$HOME/.ssh/id_rsa.pub"
fi fi
if [[ -f $key ]];then if [[ -f $public_key ]];then
key=$(cat "$key") public_key=$(cat "$public_key")
fi fi
if [[ ! $key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then if [[ ! $public_key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then
echo "公钥不合法" echo "公钥不合法"
exit 1 exit 1
fi fi
mkdir -p "$HOME/.ssh" mkdir -p "$HOME/.ssh"
echo "$key" > "$HOME/.ssh/authorized_keys" echo "$public_key" > "$HOME/.ssh/authorized_keys"
open_key configure_key
esac esac

View File

@ -1,64 +1,63 @@
#!/bin/bash #!/bin/bash
declare pick declare user_choice
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "1. 新建用户" echo "1. 新建用户"
echo "2. 查看所有用户" echo "2. 查看所有用户"
echo "3. 删除用户" echo "3. 删除用户"
echo "4. 修改用户密码" echo "4. 修改用户密码"
echo "任意输入返回主菜单" echo "任意输入返回主菜单"
read -p "请输入要使用的功能:" pick read -p "请输入要使用的功能:" user_choice
case $pick in case $user_choice in
'1') '1')
declare user_name declare new_user_name
read -p "请输入你想创建的用户名:" user_name read -p "请输入要创建的用户名:" new_user_name
if id "$user_name" &>/dev/null; then if id "$new_user_name" &>/dev/null; then
echo "用户 $user_name 已存在。" echo "用户 $new_user_name 已存在。"
exit 1 exit 1
fi fi
useradd -m -s /bin/bash "$user_name" useradd -m -s /bin/bash "$new_user_name"
if grep -q "^$user_name " /etc/sudoers;then if grep -q "^$new_user_name " /etc/sudoers;then
sed -i "s/^#\?$user_name.*/$user_name ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers sed -i "s/^#\?$new_user_name.*/$new_user_name ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers
else else
echo "$user_name ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers echo "$new_user_name ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
fi fi
declare login_method_choice
declare pick
echo "用户登录方式" echo "用户登录方式"
echo "y. 密码登录" echo "y. 密码登录"
echo "n. 使用 root 用户公钥" echo "n. 使用 root 用户公钥"
read -p "默认y请输入" pick read -p "默认 y请输入" login_method_choice
if [[ ! $pick =~ [Nn] ]];then if [[ ! $login_method_choice =~ [Nn] ]];then
declare password declare user_password
read -p "请输入密码:" password read -p "请输入密码:" user_password
echo "$user_name:$password" |chpasswd echo "$new_user_name:$user_password" |chpasswd
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config; sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
echo "创建成功" echo "创建成功"
echo "账号:$user_name" echo "账号:$new_user_name"
echo "密码:$password" echo "密码:$user_password"
else else
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'" su "$new_user_name" -c "mkdir -p '/home/$new_user_name/.ssh'"
cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys" cp "/root/.ssh/authorized_keys" "/home/$new_user_name/.ssh/authorized_keys"
chown "$user_name:$user_name" "/home/$user_name/.ssh/authorized_keys" chown "$new_user_name:$new_user_name" "/home/$new_user_name/.ssh/authorized_keys"
su "$user_name" -c "chmod 600 '/home/$user_name/.ssh/authorized_keys'" su "$new_user_name" -c "chmod 600 '/home/$new_user_name/.ssh/authorized_keys'"
su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'" su "$new_user_name" -c "chmod 700 '/home/$new_user_name/.ssh/'"
echo "创建成功" echo "创建成功"
echo "账号:$user_name" echo "账号:$new_user_name"
echo "密钥登录" echo "密钥登录"
fi fi
declare pick2 declare root_login_choice
echo "是否关闭root登录" echo "是否关闭 root 用户登录"
read -p "输入 n 取消关闭:" pick2 read -p "输入 n 取消关闭:" root_login_choice
if [[ ! $pick2 =~ [Nn] ]];then if [[ ! $root_login_choice =~ [Nn] ]];then
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
echo "root 用户登录已关闭" echo "root 用户登录已关闭"
fi fi
@ -70,33 +69,33 @@ case $pick in
cut -d: -f1 /etc/passwd cut -d: -f1 /etc/passwd
;; ;;
'3') '3')
declare user_name declare user_to_delete
read -p "请输入需要删除的用户" user_name read -p "请输入需要删除的用户名:" user_to_delete
if ! id $user_name &> /dev/nuull ;then if ! id $user_to_delete &> /dev/null ;then
echo "系统内没有该用户" echo "系统内没有该用户"
exit exit
fi fi
sed -i "/^#\?$user_name.*/d" /etc/sudoers &> /dev/null sed -i "/^#\?$user_to_delete.*/d" /etc/sudoers &> /dev/null
pkill -u $user_name pkill -u $user_to_delete
userdel -r $user_name &> /dev/null userdel -r $user_to_delete &> /dev/null
rm -rf "/home/${user_name}" rm -rf "/home/${user_to_delete}"
echo "用户删除成功" echo "用户删除成功"
;; ;;
'4') '4')
declare password declare new_password
declare user_name declare user_name
read -p "请输入需要修改密码的用户" user_name read -p "请输入需要修改密码的用户" user_name
if ! id $user_name &> /dev/null;then if ! id $user_name &> /dev/null;then
echo "系统内没有该用户" echo "系统内没有该用户"
exit exit
fi fi
read -p "请输入${user_name}需要修改的密码:" password read -p "请输入${user_name}密码:" new_password
echo "${user_name}:${password}" |chpasswd echo "${user_name}:${new_password}" |chpasswd
if [[ ${user_name} == "root" ]]; then if [[ ${user_name} == "root" ]]; then
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
fi fi
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
systemctl restart sshd.service systemctl restart sshd.service
echo "修改成功,用户${user_name}的密码为:${password}" echo "修改成功, 用户 ${user_name} 密码为:${new_password}"
;; ;;
esac esac

View File

@ -1,68 +1,68 @@
#!/bin/bash #!/bin/bash
declare pick declare user_choice
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "1.更换ssh端口" echo "1. 更换 SSH 端口"
echo "2.修改ssh登录方式" echo "2. 修改 SSH 登录方式"
echo "任意输入返回主菜单" echo "任意输入返回主菜单"
read -p "请输入要使用的功能:" pick read -p "请输入要使用的功能:" user_choice
case $pick in case $user_choice in
'1') '1')
read -p "请输入需要修改的端口号(默认22): " port_number read -p "请输入需要修改的端口号默认22: " new_port
if [[ -z $port_number ]];then if [[ -z $new_port ]];then
port_number=22 new_port=22
fi fi
if ! [[ $port_number =~ ^[0-9]+$ ]] || ! ((port_number > 0 && port_number < 65535)); then if ! [[ $new_port =~ ^[0-9]+$ ]] || ! ((new_port > 0 && new_port < 65535)); then
echo "端口不合法" echo "端口不合法"
exit exit
fi fi
if lsof -i :$port_number -t >/dev/null; then if lsof -i :$new_port -t >/dev/null; then
echo "$port_number 端口已被占用" echo "$new_port 端口已被占用"
exit exit
fi fi
sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config sed -i "s/^#\?Port.*/Port $new_port/g" /etc/ssh/sshd_config
systemctl restart sshd.service systemctl restart sshd.service
echo "端口已经修改为$port_number,记得防火墙放行" echo "端口已修改为$new_port,请确保防火墙放行该端口"
;; ;;
'2') '2')
declare pick_root declare root_login_choice
declare pick2_key declare password_auth_choice
declare pick2_password declare key_auth_choice
echo "是否关闭root登录" echo "是否关闭 root 用户登录"
read -p "输入 n 关闭:" pick_root read -p "输入 n 关闭:" root_login_choice
echo "是否关闭密码登录" echo "是否关闭密码登录"
read -p "输入 n 关闭:" pick2_password read -p "输入 n 关闭:" password_auth_choice
echo "是否关闭密钥登录" echo "是否关闭密钥登录"
read -p "输入 n 关闭:" pick2_key read -p "输入 n 关闭:" key_auth_choice
if [[ ! $pick_root =~ [Nn] ]];then if [[ ! $root_login_choice =~ [Nn] ]];then
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
echo "root用户登录:开启" echo "root 用户登录:开启"
else else
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
echo "root用户登录:关闭" echo "root 用户登录:关闭"
fi fi
if [[ ! $pick2_password =~ [Nn] ]];then if [[ ! $password_auth_choice =~ [Nn] ]];then
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
echo "密码登录:开启" echo "密码登录:开启"
else else
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
echo "密码登录:关闭" echo "密码登录:关闭"
fi fi
if [[ ! $pick2_key =~ [Nn] ]];then if [[ ! $key_auth_choice =~ [Nn] ]];then
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
echo "密钥登录:开启" echo "密钥登录:开启"
else else
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config
echo "密钥登录:关闭" echo "密钥登录:关闭"
fi fi
systemctl restart sshd.service systemctl restart sshd.service

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
if ! command -v ssh &> /dev/null; then if ! command -v ssh &> /dev/null; then
echo "ssh未安装" echo "SSH 客户端未安装"
exit exit
fi fi

View File

@ -1,39 +1,38 @@
#!/bin/bash #!/bin/bash
declare pick_mode=$1 declare selected_mode=$1
declare domain=$2 declare domain_names=$2
if ! [[ $pick_mode == "nginx" ]]; then if ! [[ $selected_mode == "nginx" ]]; then
pick_mode="" selected_mode=""
domain="" domain_names=""
fi fi
declare domain_str declare domain_string
if [[ ! $domain ]];then if [[ ! $domain_names ]];then
echo "请输入需要申请SSL证书的域名" echo "请输入需要申请SSL证书的域名"
read -p "请输入要绑定的域名多个用 空格 隔开:" domain read -p "请输入要绑定的域名多个用空格隔开" domain_names
fi fi
for i in ${domain_names} ; do
for i in ${domain} ; do
if [[ ! $i =~ [\w+\.]+ ]];then if [[ ! $i =~ [\w+\.]+ ]];then
echo "域名不合法" echo "域名不合法"
exit exit
else else
domain_str="$domain_str -d $i" domain_string="$domain_string -d $i"
fi fi
done done
if [[ -z $domain_str ]]; then if [[ -z $domain_string ]]; then
echo "需要添加的域名不能为空" echo "需要添加的域名不能为空"
exit exit
fi fi
echo "1.http验证" echo "1.http验证"
echo "2.dns验证" echo "2.dns验证"
read -p "请选择验证模式:" pick_mode read -p "请选择验证模式:" selected_mode
case $pick_mode in case $selected_mode in
'1') '1')
declare mode declare mode
if command -v nginx &> /dev/null; then if command -v nginx &> /dev/null; then
@ -41,7 +40,7 @@ case $pick_mode in
cat > "/etc/nginx/conf.d/test.conf" << EOF cat > "/etc/nginx/conf.d/test.conf" << EOF
server { server {
listen 80; # 监听80端口 listen 80; # 监听80端口
server_name ${domain}; # 服务器名称(本地) server_name ${domain_names}; # 服务器名称(本地)
location / { location / {
root /usr/share/nginx/html; # 指定根目录 root /usr/share/nginx/html; # 指定根目录
@ -56,26 +55,26 @@ EOF
fi fi
echo "请到服务器将80和443端口开启,将域名解析到本机" echo "请到服务器将80和443端口开启,将域名解析到本机"
read -p "解析完成请回车:" read -p "解析完成请回车:"
eval "${HOME}/.acme.sh/acme.sh --issue ${domain_str} --${mode}" eval "${HOME}/.acme.sh/acme.sh --issue ${domain_string} --${mode}"
rm /etc/nginx/conf.d/test.conf rm /etc/nginx/conf.d/test.conf
;; ;;
'2') '2')
declare pick=0 declare pick=0
declare -a mode_arr declare -a mode_array
mode_arr[1]="TXT记录" mode_array[1]="TXT记录"
mode_arr[2]='cloudflare' mode_array[2]='cloudflare'
for i in "${!mode_arr[@]}"; do for i in "${!mode_array[@]}"; do
((pick++)) ((pick++))
echo "${pick}. ${mode_arr[$i]}" echo "${pick}. ${mode_array[$i]}"
done done
read -p "请选择验证模式:" pick_mode read -p "请选择验证模式:" selected_mode
if [[ ! $pick_mode =~ [1-${pick}] ]]; then if [[ ! $selected_mode =~ [1-${pick}] ]]; then
exit exit
fi fi
case ${mode_arr[$pick_mode]} in case ${mode_array[$selected_mode]} in
'TXT记录') 'TXT记录')
declare log_output=$(${HOME}/.apple.sh/apple.sh --issue --dns $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please) declare log_output=$(${HOME}/.apple.sh/apple.sh --issue --dns $domain_string --yes-I-know-dns-manual-mode-enough-go-ahead-please)
declare -a domain=($( echo "$log_output" | grep "Domain:" | awk -F ": " '{print $2}')) 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}')) declare -a txt_value=($(echo "$log_output" | grep "TXT value:" | awk -F ": " '{print $2}'))
echo "请到dns系统解析TXT记录" echo "请到dns系统解析TXT记录"
@ -85,12 +84,12 @@ EOF
echo "文本记录:${txt_value[$i]}" echo "文本记录:${txt_value[$i]}"
done done
read -p "解析完成请输入 y" pick read -p "解析完成请输入 y" selected_mode
if [[ $pick =~ [Yy] ]]; then if [[ $selected_mode =~ [Yy] ]]; then
eval "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please" eval "${HOME}/.acme.sh/acme.sh --renew $domain_string --yes-I-know-dns-manual-mode-enough-go-ahead-please"
else else
echo "解析完成后请输入下面的命令完成验证" echo "解析完成后请输入下面的命令完成验证"
echo "${HOME}/.acme.sh/acme.sh --renew $domain_str --yes-I-know-dns-manual-mode-enough-go-ahead-please" echo "${HOME}/.acme.sh/acme.sh --renew $domain_string --yes-I-know-dns-manual-mode-enough-go-ahead-please"
fi fi
;; ;;
'cloudflare') 'cloudflare')
@ -104,7 +103,7 @@ EOF
read -p "请输入cloudflare的密钥" CF_Key read -p "请输入cloudflare的密钥" CF_Key
export CF_Key=$CF_Key export CF_Key=$CF_Key
export CF_Email=$CF_Email export CF_Email=$CF_Email
eval "${HOME}/.acme.sh/acme.sh --issue $domain_str --dns dns_cf" eval "${HOME}/.acme.sh/acme.sh --issue $domain_string --dns dns_cf"
esac esac
;; ;;
esac esac

View File

@ -1,32 +1,32 @@
#!/bin/bash #!/bin/bash
echo "1.查看已经成功申请证书的域名" echo "1.查看已经成功申请证书的域名"
declare pick declare user_choice
read -p "请输入" pick read -p "请输入选择:" user_choice
case $pick in case $user_choice in
'1') '1')
declare print_name declare certificate_name
declare print_number=0 declare certificate_count=0
declare -a print_arr declare -a certificate_array
for i in "${HOME}/.acme.sh"/* ; do for i in "${HOME}/.acme.sh"/* ; do
print_name=$(basename $i ) certificate_name=$(basename $i )
if ! echo "$print_name" | grep -q "_ecc" ; then if ! echo "$certificate_name" | grep -q "_ecc" ; then
continue continue
fi fi
print_name=$(echo $print_name | sed "s/_ecc//g" ) certificate_name=$(echo $certificate_name | sed "s/_ecc//g" )
print_number=$(( print_number+1 )) certificate_count=$(( certificate_count+1 ))
print_arr[$print_number]=$print_name certificate_array[$certificate_count]=$certificate_name
echo "${print_number}.${print_name}" echo "${certificate_count}.${certificate_name}"
done done
if [ ${#print_arr[@]} == 0 ]; then if [ ${#certificate_array[@]} == 0 ]; then
echo "暂时没有安装证书" echo "暂时没有安装证书"
exit exit
fi fi
read -p "请输入要查看证书详细信息的序号:" pick read -p "请输入要查看证书详细信息的序号:" user_choice
if [[ $pick =~ [1-${#print_arr[@]}] ]]; then if [[ $user_choice =~ [1-${#certificate_array[@]}] ]]; then
bash "${HOME}/.acme.sh/acme.sh -info -d ${print_arr[$pick]}" bash "${HOME}/.acme.sh/acme.sh -info -d ${certificate_array[$user_choice]}"
else else
echo "选择错误" echo "选择错误"
fi fi

View File

@ -10,19 +10,19 @@ if ! command -v socat &> /dev/null; then
pacman -Syu --noconfirm pacman -Syu --noconfirm
pacman -Sy --noconfirm socat pacman -Sy --noconfirm socat
else else
echo "socat未安装" echo "socat未安装,请手动安装"
exit exit
fi fi
fi fi
if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
rm -rf ${HOME}/.apple.sh rm -rf ${HOME}/.apple.sh
declare mail declare email_address
read -p "请输入用来申请域名的邮箱:" mail read -p "请输入用来申请域名的邮箱:" email_address
if [[ ! $mail =~ .*@.* ]];then if [[ ! $email_address =~ .*@.* ]];then
echo "邮箱不合法" echo "邮箱不合法"
exit exit
fi fi
curl https://get.acme.sh | sh -s "email=$mail" curl https://get.acme.sh | sh -s "email=$email_address"
fi fi

View File

@ -1,56 +1,56 @@
declare domain declare domain_names
read -p "请输入要绑定的域名多个用 空格 隔开:" domain read -p "请输入要绑定的域名多个用空格隔开" domain_names
declare ssl_certificate declare ssl_cert_path
declare ssl_certificate_key declare ssl_key_path
declare ssl_domain=$(echo "${domain}" | awk '{print $1}') declare primary_domain=$(echo "${domain_names}" | awk '{print $1}')
echo "ssl证书" echo "SSL证书选择"
echo "1.自动申请(默认)" echo "1.自动申请(默认)"
echo "2.手动输入" echo "2.手动输入"
read -p "请输入" pick read -p "请输入选择:" user_choice
if [[ $pick == 2 ]]; then if [[ $user_choice == 2 ]]; then
echo "证书,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer" echo "证书路径, 默认 ${HOME}/.acme.sh/${primary_domain}_ecc/fullchain.cer"
read -p "请输入证书地址:" ssl_certificate read -p "请输入证书地址:" ssl_cert_path
if [[ -z $ssl_certificate ]];then if [[ -z $ssl_cert_path ]];then
ssl_certificate="${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer" ssl_cert_path="${HOME}/.acme.sh/${primary_domain}_ecc/fullchain.cer"
fi fi
echo "密钥,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key" echo "密钥路径, 默认 ${HOME}/.acme.sh/${primary_domain}_ecc/${primary_domain}.key"
read -p "请输入密钥地址:" ssl_certificate_key read -p "请输入密钥地址:" ssl_key_path
if [[ -z $ssl_certificate_key ]];then if [[ -z $ssl_key_path ]];then
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key" ssl_key_path="${HOME}/.acme.sh/${primary_domain}_ecc/${primary_domain}.key"
fi fi
else else
echo "1.nginx(默认)" echo "1.nginx(默认)"
read -p "请选择:" pick read -p "请选择:" user_choice
bash "$(dirname $(dirname $0))/acme/test.sh" bash "$(dirname $(dirname $0))/acme/test.sh"
bash "$(dirname $(dirname $0))/acme/apply.sh" "nginx" "${domain}" bash "$(dirname $(dirname $0))/acme/apply.sh" "nginx" "${domain_names}"
ssl_certificate="${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer" ssl_cert_path="${HOME}/.acme.sh/${primary_domain}_ecc/fullchain.cer"
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key" ssl_key_path="${HOME}/.acme.sh/${primary_domain}_ecc/${primary_domain}.key"
fi fi
declare name declare config_file_name
read -p "请输入配置文件名,默认为域名:" name read -p "请输入配置文件名(默认为域名):" config_file_name
if [[ -z $name ]]; then if [[ -z $config_file_name ]]; then
name=$ssl_domain config_file_name=$primary_domain
fi fi
echo "工作方式" echo "工作方式选择"
echo "1.反向代理(默认)" echo "1.反向代理(默认)"
echo "2.静态文件" echo "2.静态文件"
read -p "请选择:" pick read -p "请选择:" user_choice
declare path declare site_path
if [[ $pick == 2 ]]; then if [[ $user_choice == 2 ]]; then
read -p "请输入要代理的站点路径" path read -p "请输入要代理的站点路径" site_path
cat > "/etc/nginx/sites-available/${name}.conf" << EOF cat > "/etc/nginx/sites-available/${config_file_name}.conf" << EOF
server { server {
listen 443 ssl http2; # 监听 443 端口并启用 SSL 和 HTTP/2 listen 443 ssl http2; # 监听 443 端口并启用 SSL 和 HTTP/2
server_name ${domain}; # 替换为你的域名 server_name ${domain_names}; # 替换为你的域名
# SSL 证书配置 # SSL 证书配置
ssl_certificate ${ssl_certificate}; # 证书文件路径 ssl_certificate ${ssl_cert_path}; # 证书文件路径
ssl_certificate_key ${ssl_certificate_key}; # 证书密钥文件路径 ssl_certificate_key ${ssl_key_path}; # 证书密钥文件路径
ssl_protocols TLSv1.2 TLSv1.3; # 仅使用安全的 TLS 协议版本 ssl_protocols TLSv1.2 TLSv1.3; # 仅使用安全的 TLS 协议版本
ssl_ciphers HIGH:!aNULL:!MD5; # 安全的密码套件 ssl_ciphers HIGH:!aNULL:!MD5; # 安全的密码套件
ssl_prefer_server_ciphers on; # 优先使用服务器的密码套件 ssl_prefer_server_ciphers on; # 优先使用服务器的密码套件
@ -75,7 +75,7 @@ server {
large_client_header_buffers 4 16k; # 设置较大的客户端头部缓冲区,防止上传大文件时出现 413 错误 large_client_header_buffers 4 16k; # 设置较大的客户端头部缓冲区,防止上传大文件时出现 413 错误
# 静态文件目录 # 静态文件目录
root ${path}; root ${site_path};
index index.html index.htm; index index.html index.htm;
# 日志 # 日志
@ -102,7 +102,7 @@ server {
# HTTP 到 HTTPS 重定向 # HTTP 到 HTTPS 重定向
server { server {
listen 80; # 监听 80 端口 listen 80; # 监听 80 端口
server_name ${domain}; server_name ${domain_names};
# 将所有 HTTP 请求重定向到 HTTPS # 将所有 HTTP 请求重定向到 HTTPS
return 301 https://\$host\$request_uri; return 301 https://\$host\$request_uri;
@ -110,18 +110,18 @@ server {
EOF EOF
else else
read -p "请输入后端服务器的地址,如果只输入数字代表端口:" path read -p "请输入后端服务器的地址,如果只输入数字代表端口:" site_path
if [[ $path =~ [0-9]+ ]]; then if [[ $site_path =~ [0-9]+ ]]; then
path="http://127.0.0.1:${path}" site_path="http://127.0.0.1:${site_path}"
fi fi
cat > "/etc/nginx/sites-available/${name}.conf" << EOF cat > "/etc/nginx/sites-available/${config_file_name}.conf" << EOF
server { server {
listen 443 ssl http2; # 监听 443 端口,并启用 HTTP/2 listen 443 ssl http2; # 监听 443 端口,并启用 HTTP/2
server_name ${domain}; # 替换为你的域名 server_name ${domain_names}; # 替换为你的域名
# SSL 证书配置 # SSL 证书配置
ssl_certificate ${ssl_certificate}; # 证书文件路径 ssl_certificate ${ssl_cert_path}; # 证书文件路径
ssl_certificate_key ${ssl_certificate_key}; # 证书密钥文件路径 ssl_certificate_key ${ssl_key_path}; # 证书密钥文件路径
ssl_protocols TLSv1.2 TLSv1.3; # 使用安全的 TLS 协议版本 ssl_protocols TLSv1.2 TLSv1.3; # 使用安全的 TLS 协议版本
ssl_ciphers HIGH:!aNULL:!MD5; # 安全密码套件 ssl_ciphers HIGH:!aNULL:!MD5; # 安全密码套件
ssl_prefer_server_ciphers on; ssl_prefer_server_ciphers on;
@ -134,8 +134,8 @@ server {
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# 日志设置 # 日志设置
access_log /var/log/nginx/${name}_access.log; access_log /var/log/nginx/${config_file_name}_access.log;
error_log /var/log/nginx/${name}_error.log; error_log /var/log/nginx/${config_file_name}_error.log;
# 错误页面配置 # 错误页面配置
error_page 404 /404.html; error_page 404 /404.html;
@ -159,7 +159,7 @@ server {
# 反向代理到后台应用 (常规 HTTP/HTTPS) # 反向代理到后台应用 (常规 HTTP/HTTPS)
location / { location / {
proxy_pass ${path}; # 反向代理到后端应用服务器 proxy_pass ${site_path}; # 反向代理到后端应用服务器
proxy_set_header Host \$host; # 保持原始主机头 proxy_set_header Host \$host; # 保持原始主机头
proxy_set_header X-Real-IP \$remote_addr; # 传递客户端的真实 IP 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-For \$proxy_add_x_forwarded_for; # 传递代理链中的 IP
@ -177,7 +177,7 @@ server {
# WebSocket 反向代理到后台应用 # WebSocket 反向代理到后台应用
location /ws { location /ws {
proxy_pass ${path}; # 反向代理到 WebSocket 应用服务器 proxy_pass ${site_path}; # 反向代理到 WebSocket 应用服务器
proxy_http_version 1.1; # WebSocket 必须使用 HTTP 1.1 proxy_http_version 1.1; # WebSocket 必须使用 HTTP 1.1
proxy_set_header Upgrade \$http_upgrade; # 升级请求头,用于 WebSocket proxy_set_header Upgrade \$http_upgrade; # 升级请求头,用于 WebSocket
proxy_set_header Connection "Upgrade"; # 持久连接,保持 WebSocket 连接 proxy_set_header Connection "Upgrade"; # 持久连接,保持 WebSocket 连接
@ -203,7 +203,7 @@ server {
# HTTP 到 HTTPS 重定向 # HTTP 到 HTTPS 重定向
server { server {
listen 80; # 监听 HTTP 80 端口 listen 80; # 监听 HTTP 80 端口
server_name ${domain}; # 替换为你的域名 server_name ${domain_names}; # 替换为你的域名
# 将所有 HTTP 请求重定向到 HTTPS # 将所有 HTTP 请求重定向到 HTTPS
return 301 https://\$host\$request_uri; return 301 https://\$host\$request_uri;
@ -211,6 +211,6 @@ server {
EOF EOF
fi fi
ln -s "/etc/nginx/sites-available/${name}.conf" "/etc/nginx/sites-enabled" &> /dev/null ln -s "/etc/nginx/sites-available/${config_file_name}.conf" "/etc/nginx/sites-enabled" &> /dev/null
nginx -s reload &> /dev/null nginx -s reload &> /dev/null
echo "配置完成" echo "配置完成"

View File

@ -1,53 +1,53 @@
#!/bin/bash #!/bin/bash
declare pick declare user_choice
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
echo "1.查看已有站点配置文件" echo "1.查看已有站点配置文件"
echo "2.删除站点配置文件" echo "2.删除站点配置文件"
read -p "请选择" pick read -p "请选择操作:" user_choice
case $pick in case $user_choice in
'1') '1')
declare -a site_arr declare -a site_array
declare site_name declare site_name
declare site_number=0 declare site_count=0
for i in "/etc/nginx/sites-available"/* ; do for i in "/etc/nginx/sites-available"/* ; do
if [[ $i == "/etc/nginx/sites-available/*" ]];then if [[ $i == "/etc/nginx/sites-available/*" ]];then
echo "暂时没有配置文件" echo "暂时没有配置文件"
exit exit
fi fi
site_number=$(( site_number+1 )) site_count=$(( site_count+1 ))
site_name=$(basename $i) site_name=$(basename $i)
echo "${site_number}.${site_name}" echo "${site_count}.${site_name}"
site_arr[$site_number]=$site_name site_array[$site_count]=$site_name
done done
if [ ${#site_arr[@]} == 0 ]; then if [ ${#site_array[@]} == 0 ]; then
echo "暂时没有配置文件" echo "暂时没有配置文件"
exit exit
fi fi
;; ;;
'2') '2')
declare -a site_arr declare -a site_array
declare site_name declare site_name
declare site_number=0 declare site_count=0
for i in "/etc/nginx/sites-available"/* ; do for i in "/etc/nginx/sites-available"/* ; do
if [[ $i == "/etc/nginx/sites-available/*" ]];then if [[ $i == "/etc/nginx/sites-available/*" ]];then
echo "暂时没有配置文件" echo "暂时没有配置文件"
exit exit
fi fi
site_number=$(( site_number+1 )) site_count=$(( site_count+1 ))
site_name=$(basename $i) site_name=$(basename $i)
echo "${site_number}.${site_name}" echo "${site_count}.${site_name}"
site_arr[$site_number]=$site_name site_array[$site_count]=$site_name
done done
if [ ${#site_arr[@]} == 0 ]; then if [ ${#site_array[@]} == 0 ]; then
echo "暂时没有配置文件" echo "暂时没有配置文件"
exit exit
fi fi
read -p "请输入要删除的序号,多个用 空格 隔开:" site_name read -p "请输入要删除的序号,多个用 空格 隔开:" site_name
for i in $site_name ; do for i in $site_name ; do
if [[ $i =~ [1-${#site_arr[*]}] ]]; then if [[ $i =~ [1-${#site_array[*]}] ]]; then
echo "开始删除 ${site_arr[$i]}" echo "开始删除 ${site_array[$i]}"
rm -rf "/etc/nginx/sites-available/${site_arr[$i]}" &> /dev/null rm -rf "/etc/nginx/sites-available/${site_array[$i]}" &> /dev/null
rm -rf "/etc/nginx/sites-enabled/${site_arr[$i]}" &> /dev/null rm -rf "/etc/nginx/sites-enabled/${site_array[$i]}" &> /dev/null
echo "删除完成" echo "删除完成"
fi fi
done done

View File

@ -11,7 +11,7 @@ if ! command -v nginx &> /dev/null; then
pacman -Syu --noconfirm pacman -Syu --noconfirm
pacman -Sy --noconfirm nginx pacman -Sy --noconfirm nginx
else else
echo "nginx未安装" echo "nginx未安装,请手动安装"
exit exit
fi fi
fi fi

View File

@ -1,115 +1,114 @@
#!/bin/bash #!/bin/bash
echo "正在更新系统包管理器" echo "正在更新系统包管理器"
declare install_str declare install_command
declare version="$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')" declare os_version="$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')"
declare status=0 declare install_status=0
declare pkg declare package_manager
if [[ -f "/usr/bin/apt-get" ]];then if [[ -f "/usr/bin/apt-get" ]];then
pkg='apt-get' package_manager='apt-get'
install_str+="${pkg} install -y" install_command+="${package_manager} install -y"
apt-get update -y apt-get update -y
elif [[ -f "/usr/bin/apt" ]];then elif [[ -f "/usr/bin/apt" ]];then
pkg='apt' package_manager='apt'
install_str+="${pkg} install -y" install_command+="${package_manager} install -y"
apt update -y apt update -y
elif [[ -f "/usr/bin/pacman" ]];then elif [[ -f "/usr/bin/pacman" ]];then
pkg='pacman' package_manager='pacman'
install_str+="${pkg} -Sy --noconfirm" install_command+="${package_manager} -Sy --noconfirm"
pacman -Syu --noconfirm pacman -Syu --noconfirm
else else
echo "暂不支持该系统一键安装常用软件" echo "暂不支持该系统一键安装常用软件"
exit exit
fi fi
declare selected_packages
declare pick declare package_count
declare soft_number declare -A package_options
declare -A soft_dick declare -a package_names
declare -a soft_array package_options['git']=0
soft_dick['git']=0 package_options['vim']=0
soft_dick['vim']=0 package_options['wget']=0
soft_dick['wget']=0 package_options['curl']=0
soft_dick['curl']=0 package_options['sudo']=0
soft_dick['sudo']=0 package_options['ssh']=0
soft_dick['ssh']=0 package_options['zsh']=0
soft_dick['zsh']=0 package_options['zsh-beautify']=1
soft_dick['zsh-beautify']=1 package_options['docker']=1
soft_dick['docker']=1 package_options['x-cmd']=1
soft_dick['x-cmd']=1
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
for i in "${!soft_dick[@]}" ; do for i in "${!package_options[@]}" ; do
soft_number=$(( soft_number+1 )) package_count=$(( package_count+1 ))
soft_array[$soft_number]=$i package_names[$package_count]=$i
echo "${soft_number}.${i}" echo "${package_count}.${i}"
done done
echo "请输入需要安装的软件序号(默认安装全部)" echo "请输入需要安装的软件序号(默认安装全部)"
read -p "用 空格 隔开:" pick read -p "用 空格 隔开:" selected_packages
if [[ -z $pick ]];then if [[ -z $selected_packages ]];then
for (( i = 1; i <= ${#soft_dick[@]}; i++ )); do for (( i = 1; i <= ${#package_options[@]}; i++ )); do
if [[ $i != 1 ]]; then if [[ $i != 1 ]]; then
pick="$pick $i" selected_packages="$selected_packages $i"
else else
pick="$i" selected_packages="$i"
fi fi
done done
elif ! [[ $pick -ge 1 && $pick -le ${#soft_dick[@]} || $pick =~ ([1-${#soft_dick[@]}][\s]?)+ ]];then elif ! [[ $selected_packages -ge 1 && $selected_packages -le ${#package_options[@]} || $selected_packages =~ ([1-${#package_options[@]}][\s]?)+ ]];then
echo "输入错误" echo "输入错误"
exit exit
fi fi
for i in $pick ; do for i in $selected_packages ; do
if [[ ${soft_dick[${soft_array[$i]}]} == 0 ]]; then if [[ ${package_options[${package_names[$i]}]} == 0 ]]; then
eval "$install_str ${soft_array[$i]}" eval "$install_command ${package_names[$i]}"
else else
soft_dick[${soft_array[$i]}]=2 package_options[${package_names[$i]}]=2
fi fi
done done
if [[ ${soft_dick['x-cmd']} == 2 ]];then if [[ ${package_options['x-cmd']} == 2 ]];then
eval "$(curl https://get.x-cmd.com)" eval "$(curl https://get.x-cmd.com)"
fi fi
if [[ ${soft_dick['docker']} == 2 ]];then if [[ ${package_options['docker']} == 2 ]];then
echo "请选择docker下载镜像站" echo "请选择docker下载镜像站"
declare -A docker_imgs declare -A docker_mirrors
docker_imgs['官方']='https://download.docker.com' docker_mirrors['官方']='https://download.docker.com'
docker_imgs['清华大学']='https://mirrors.tuna.tsinghua.edu.cn/docker-ce' docker_mirrors['清华大学']='https://mirrors.tuna.tsinghua.edu.cn/docker-ce'
docker_imgs['阿里云']='https://mirrors.aliyun.com/docker-ce' docker_mirrors['阿里云']='https://mirrors.aliyun.com/docker-ce'
docker_imgs['网易云']='https://mirrors.163.com/docker-ce' docker_mirrors['网易云']='https://mirrors.163.com/docker-ce'
declare -a docker_img_number declare -a docker_mirror_options
declare docker_img_number_pick=0 declare docker_mirror_choice=0
for i in "${!docker_imgs[@]}"; do for i in "${!docker_mirrors[@]}"; do
docker_img_number_pick=$((docker_img_number_pick + 1)) docker_mirror_choice=$((docker_mirror_choice + 1))
docker_img_number[$docker_img_number_pick]=$i docker_mirror_options[$docker_mirror_choice]=$i
echo "${docker_img_number_pick}.${i}" echo "${docker_mirror_choice}.${i}"
done done
read -p "请选择Docker镜像站(默认 1)" docker_img_number_pick read -p "请选择Docker镜像站(默认 1)" docker_mirror_choice
declare docker_img declare docker_mirror
if [[ $docker_img_number_pick =~ [1-${#docker_imgs[@]}] ]];then if [[ $docker_mirror_choice =~ [1-${#docker_mirrors[@]}] ]];then
docker_img_number_pick=${docker_img_number[$docker_img_number_pick]} docker_mirror_choice=${docker_mirror_options[$docker_mirror_choice]}
docker_img=${docker_imgs[$docker_img_number_pick]} docker_mirror=${docker_mirrors[$docker_mirror_choice]}
else else
docker_img=${docker_imgs[${docker_img_number[1]}]} docker_mirror=${docker_mirrors[${docker_mirror_options[1]}]}
fi fi
if [[ ${pkg} == 'apt' || ${pkg} == 'apt-get' ]];then if [[ ${package_manager} == 'apt' || ${package_manager} == 'apt-get' ]];then
${pkg} update ${package_manager} update
${pkg} install ca-certificates curl -y ${package_manager} install ca-certificates curl -y
install -m 0755 -d /etc/apt/keyrings install -m 0755 -d /etc/apt/keyrings
curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc curl -fsSL "${docker_mirror}/linux/${os_version}/gpg" -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc chmod a+r /etc/apt/keyrings/docker.asc
echo \ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_img}/linux/${version} \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_mirror}/linux/${os_version} \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null tee /etc/apt/sources.list.d/docker.list > /dev/null
${pkg} update ${package_manager} update
${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y ${package_manager} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
elif [[ ${pkg} == 'pacman' ]];then elif [[ ${package_manager} == 'pacman' ]];then
pacman -Sy docker --noconfirm pacman -Sy docker --noconfirm
systemctl start docker.service systemctl start docker.service
systemctl enable docker.service systemctl enable docker.service
@ -118,8 +117,7 @@ if [[ ${soft_dick['docker']} == 2 ]];then
fi fi
fi fi
if [[ ${package_options['zsh-beautify']} == 2 ]];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 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 while [[ ! -d "$HOME/.oh-my-zsh" ]]; do
sleep 3 sleep 3
@ -133,6 +131,4 @@ if [[ ${soft_dick['zsh-beautify']} == 2 ]];then
exec zsh -l exec zsh -l
fi fi
echo "软件已经全部安装成功" echo "软件已经全部安装成功"

View File

@ -1,87 +1,84 @@
#!/bin/bash #!/bin/bash
declare version=$(cat /etc/os-release | grep VERSION_CODENAME | awk -F '=' '{print $2}') declare os_version=$(cat /etc/os-release | grep VERSION_CODENAME | awk -F '=' '{print $2}')
declare system=$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}') declare os_id=$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')
declare status=0 declare update_status=0
declare -A sources_dick declare -A mirror_sources
sources_dick['中国科技技术大学(默认)']='http://mirrors.ustc.edu.cn' mirror_sources['中国科技技术大学(默认)']='http://mirrors.ustc.edu.cn'
sources_dick['清华大学']='https://mirrors.tuna.tsinghua.edu.cn' mirror_sources['清华大学']='https://mirrors.tuna.tsinghua.edu.cn'
sources_dick['阿里云']='https://mirrors.aliyun.com' mirror_sources['阿里云']='https://mirrors.aliyun.com'
sources_dick['网易云']='https://mirrors.163.com' mirror_sources['网易云']='https://mirrors.163.com'
declare -a pcik_array declare -a selected_sources
declare pick=0 declare source_choice=0
echo "========$(basename $0 .sh)========" echo "========$(basename $0 .sh)========"
for i in "${!sources_dick[@]}"; for i in "${!mirror_sources[@]}";
do do
pick=$(( pick+1 )) source_choice=$(( source_choice+1 ))
pcik_array[$pick]=$i selected_sources[$source_choice]=$i
echo "${pick}.${i}" echo "${source_choice}.${i}"
done done
read -p "请输入" pick read -p "请输入选择的源:" source_choice
if [[ -z $source_choice ]];then
if [[ -z $pick ]];then declare selected_url='http://mirrors.ustc.edu.cn'
declare url='http://mirrors.ustc.edu.cn' elif [[ ${source_choice} =~ [1-${#mirror_sources[@]}] ]];then
elif [[ ${pick} =~ [1-${#sources_dick[@]}] ]];then source_choice=${selected_sources[$source_choice]}
pick=${pcik_array[$pick]} declare selected_url=${mirror_sources[$source_choice]}
declare url=${sources_dick[$pick]}
else else
echo "输入错误" echo "输入错误"
exit exit
fi fi
case "$version" in case "$os_version" in
'bookworm') 'bookworm')
cat > "/etc/apt/sources.list" << EOF cat > "/etc/apt/sources.list" << EOF
deb ${url}/debian/ bookworm main contrib non-free non-free-firmware deb ${selected_url}/debian/ bookworm main contrib non-free non-free-firmware
deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware deb ${selected_url}/debian/ bookworm-updates main contrib non-free non-free-firmware
deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware deb ${selected_url}/debian/ bookworm-backports main contrib non-free non-free-firmware
EOF EOF
apt update -y apt update -y
apt-get update -y apt-get update -y
status=1 update_status=1
;; ;;
'bullseye') 'bullseye')
cat > "/etc/apt/sources.list" << EOF cat > "/etc/apt/sources.list" << EOF
deb ${url}/debian/ bullseye main contrib non-free deb ${selected_url}/debian/ bullseye main contrib non-free
deb ${url}/debian/ bullseye-updates main contrib non-free deb ${selected_url}/debian/ bullseye-updates main contrib non-free
deb ${url}/debian/ bullseye-backports main contrib non-free deb ${selected_url}/debian/ bullseye-backports main contrib non-free
EOF EOF
apt update -y apt update -y
apt-get update -y apt-get update -y
status=1 update_status=1
;; ;;
esac esac
case "$system" in case "$os_id" in
'arch') 'arch')
pacman -Sy pacman-key --noconfirm pacman -Sy pacman-key --noconfirm
sed -i '/^Server.*/d' "/etc/pacman.conf" sed -i '/^Server.*/d' "/etc/pacman.conf"
echo "Server = ${url}/archlinuxcn/\$arch" echo "Server = ${selected_url}/archlinuxcn/\$arch"
pacman-key --lsign-key "farseerfc@archlinux.org" pacman-key --lsign-key "farseerfc@archlinux.org"
pacman -Syyu pacman -Syyu
status=1 update_status=1
;; ;;
'ubuntu') 'ubuntu')
cat > "/etc/apt/sources.list" << EOF cat > "/etc/apt/sources.list" << EOF
deb ${url}/ubuntu/ ${version} main restricted universe multiverse deb ${selected_url}/ubuntu/ ${os_version} main restricted universe multiverse
deb ${url}/ubuntu/ ${version}-security main restricted universe multiverse deb ${selected_url}/ubuntu/ ${os_version}-security main restricted universe multiverse
deb ${url}/ubuntu/ ${version}-updates main restricted universe multiverse deb ${selected_url}/ubuntu/ ${os_version}-updates main restricted universe multiverse
deb ${url}/ubuntu/ ${version}-backports main restricted universe multiverse deb ${selected_url}/ubuntu/ ${os_version}-backports main restricted universe multiverse
EOF EOF
apt update -y apt update -y
apt-get update -y apt-get update -y
status=1 update_status=1
;; ;;
esac esac
if [[ $update_status == 0 ]]; then
if [[ $status == 0 ]]; then
echo "暂不支持该系统一键换源" echo "暂不支持该系统一键换源"
exit exit
fi fi
echo "换源成功" echo "换源成功"

View File

@ -1,23 +1,23 @@
#!/bin/bash #!/bin/bash
declare vpn_number=0 declare vpn_count=0
declare -a vpn_index declare -a vpn_options
declare -A vpn_array declare -A vpn_commands
declare vpn_pick declare user_choice
vpn_array["v2ray"]='bash <(curl -s -L https://git.io/v2ray.sh)' vpn_commands["v2ray"]='bash <(curl -s -L https://git.io/v2ray.sh)'
vpn_array["v2ray-agent"]='wget -P /root -N --no-check-certificate "https://raw.githubusercontent.com/mack-a/v2ray-agent/master/install.sh" && chmod 700 /root/install.sh && /root/install.sh' vpn_commands["v2ray-agent"]='wget -P /root -N --no-check-certificate "https://raw.githubusercontent.com/mack-a/v2ray-agent/master/install.sh" && chmod 700 /root/install.sh && /root/install.sh'
vpn_array["x-ui"]='bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install.sh)' vpn_commands["x-ui"]='bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install.sh)'
vpn_array["V2bX"]='wget -N https://raw.githubusercontent.com/wyx2685/V2bX-script/master/install.sh && bash install.sh' vpn_commands["V2bX"]='wget -N https://raw.githubusercontent.com/wyx2685/V2bX-script/master/install.sh && bash install.sh'
for i in "${!vpn_array[@]}";do for i in "${!vpn_commands[@]}";do
vpn_number=$((vpn_number+1)) vpn_count=$((vpn_count+1))
vpn_index[${vpn_number}]=${i} vpn_options[${vpn_count}]=${i}
echo "${vpn_number}.${i}" echo "${vpn_count}.${i}"
done done
read -p "请输入要选择的序号:" vpn_pick read -p "请输入要选择的序号:" user_choice
if [[ $vpn_pick =~ [1-${#vpn_array[@]}] ]];then if [[ $user_choice =~ [1-${#vpn_commands[@]}] ]];then
eval "${vpn_array[${vpn_index[$vpn_pick]}]}" eval "${vpn_commands[${vpn_options[$user_choice]}]}"
echo "安装完成" echo "安装完成"
else else
echo "输入错误" echo "输入错误"

79
README.md Normal file
View File

@ -0,0 +1,79 @@
## 功能概述
### 1. Automation自动化脚本管理
- **作用**:该分类包含与自动化脚本相关的功能,主要用于管理和执行各种自动化任务。
- **主要文件**
- `manage.sh`:提供用户管理脚本的功能,如查看和删除已安装的脚本。
- `acme_update.sh`:用于更新 ACME 脚本和强制续订所有证书。
- `backup.sh`:实现数据备份功能,支持本地、百度网盘和阿里云盘备份。
- `menu.sh`:提供交互式菜单,允许用户选择并执行不同的功能。
- `up-docker_compose.sh`:用于更新 Docker Compose 服务。
- `update.sh`:自动更新系统包管理器的配置。
### 2. DockerDocker 相关功能)
- **作用**:该分类专注于 Docker 相关的功能和服务管理。
- **主要文件**
- `image.sh`:管理 Docker 镜像的查看、停止和删除功能。
- `manage.sh`:提供对 Docker 服务的管理功能。
- `source.sh`:用于配置 Docker 镜像源。
- `test.sh`:检查 Docker 是否安装。
- `alist.sh`、`gitea.sh`、`nginx-proxy-manager.sh`、`safeline.sh`、`siyuan.sh`、`typecho.sh`、`vaultwarden.sh`、`xboard.sh`:这些脚本用于安装和配置不同的 Docker 应用程序。
### 3. Manage系统管理
- **作用**:该分类包含与系统管理相关的功能。
- **主要文件**
- `install.sh`:用于安装和配置系统工具。
- `unInstall.sh`:用于卸载系统工具和清理相关配置。
### 4. Other其他功能
- **作用**:该分类包含一些其他的实用功能。
- **主要文件**
- `bbr_open.sh`:用于开启 BBR 加速。
- `language.sh`:用于更改系统语言设置。
- `reinstall.sh`:用于重新安装系统工具。
### 5. User用户管理
- **作用**:该分类包含与用户和权限管理相关的功能。
- **主要文件**
- `key.sh`:用于管理 SSH 密钥。
- `manage.sh`:提供用户管理功能,如创建、删除用户。
- `ssh.sh`:用于管理和配置 SSH 服务。
- `test.sh`:检查 SSH 客户端是否安装。
### 6. Web网页相关功能
- **作用**:该分类主要涉及与网页相关的功能。
- **主要文件**
- `acme`:包含与 SSL 证书管理相关的脚本,如申请、管理和测试。
- `apply.sh`:用于申请 SSL 证书。
- `manage.sh`:管理已申请的证书。
- `test.sh`:测试 SSL 证书的有效性。
- `nginx`:包含与 Nginx 配置相关的脚本。
- `install.sh`:用于安装 Nginx。
- `manage.sh`:管理 Nginx 配置。
- `test.sh`:测试 Nginx 是否正常运行。
### 7. Sources源管理
- **作用**:用于管理软件源的配置。
- **主要文件**
- `sources.sh`:提供查看和更换软件源的功能。
### 8. VPNVPN 管理)
- **作用**:用于管理和配置 VPN 服务。
- **主要文件**
- `vpn.sh`:提供 VPN 服务的安装和管理功能。
### 9. Software软件管理
- **作用**:用于安装常用软件包。
- **主要文件**
-
### 菜单机制
该系统通过菜单提供了一个用户友好的界面,允许用户选择可用的脚本进行执行。菜单机制包括以下两个子功能:
#### 1. test 菜单
- **功能**test 菜单用于执行特定的测试脚本,验证系统功能的正常运行。用户可以选择要测试的功能,系统会根据选择执行相应的测试脚本。
- **作用**:确保用户在执行其他操作之前,系统的相关功能正常,避免因环境问题导致的错误。
#### 2. menu 菜单
- **功能**menu 菜单提供了一个用户友好的界面,允许用户选择可用的脚本进行执行。用户通过输入对应的序号来选择脚本,系统会根据用户的选择执行相应的操作。
- **作用**:作为系统的入口,用户可以通过它访问其他功能,包括执行脚本、配置定时任务等。

63
run.sh
View File

@ -5,59 +5,58 @@ if [[ $UID != 0 ]]; then
exit exit
fi fi
declare -a pick_array declare -a function_array
declare pick_number declare selected_function
declare pick declare script_path=$(dirname $0)
declare path_script=$(dirname $0) script_path="${script_path}/Config"
path_script="${path_script}/Config" declare local_path=$script_path
declare path_local=$path_script declare script_name
declare file_name
while true while true
do do
if [[ -e "${path_local}/test.sh" ]]; then if [[ -e "${local_path}/test.sh" ]]; then
bash "${path_local}/test.sh" bash "${local_path}/test.sh"
if [[ $? -eq 1 ]]; then if [[ $? -eq 1 ]]; then
path_local=$path_script local_path=$script_path
fi fi
fi fi
if [[ -e "${path_local}/menu.sh" ]]; then if [[ -e "${local_path}/menu.sh" ]]; then
clear clear
bash "${path_local}/menu.sh" "$path_local" bash "${local_path}/menu.sh" "$local_path"
path_local=$path_script local_path=$script_path
fi fi
pick_number=0 selected_function=0
pick_array=() function_array=()
echo "======$(basename $path_local .sh)======" echo "======$(basename $local_path .sh)======"
for i in "${path_local}"/* for i in "${local_path}"/*
do do
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)") script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
if [[ $file_name == "test" ]]; then if [[ $script_name == "test" ]]; then
continue continue
fi fi
pick_number=$((pick_number + 1)) selected_function=$((selected_function + 1))
pick_array[$pick_number]=$file_name function_array[$selected_function]=$script_name
echo "${pick_number}.${pick_array[$pick_number]}" echo "${selected_function}.${function_array[$selected_function]}"
done done
if [[ $path_local != $path_script ]]; then if [[ $local_path != $script_path ]]; then
echo "输入任意返回主页" echo "输入任意返回主页"
fi fi
read -p "请输入要使用的功能:" pick read -p "请输入要使用的功能:" user_choice
if [[ "${pick}" =~ [1-${#pick_array[*]}] ]];then if [[ "${user_choice}" =~ [1-${#function_array[*]}] ]];then
clear clear
if [[ -d "${path_local}/${pick_array[$pick]}" ]]; then if [[ -d "${local_path}/${function_array[$user_choice]}" ]]; then
path_local="${path_local}/${pick_array[$pick]}" local_path="${local_path}/${function_array[$user_choice]}"
elif [[ -e "${path_local}/${pick_array[$pick]}.sh" ]]; then elif [[ -e "${local_path}/${function_array[$user_choice]}.sh" ]]; then
bash "${path_local}/${pick_array[$pick]}.sh" bash "${local_path}/${function_array[$user_choice]}.sh"
path_local=$path_script local_path=$script_path
fi fi
else else
if [[ $path_local == $path_script ]]; then if [[ $local_path == $script_path ]]; then
exit exit
fi fi
path_local=$path_script local_path=$script_path
fi fi
done done