用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
${HOME}/.acme.sh/acme.sh --upgrade
${HOME}/.acme.sh/acme.sh --renew-all --force

View File

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

View File

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

View File

@ -1,19 +1,19 @@
#!/bin/bash
declare path="$1"
declare docker_compose_path="$1"
if ! command -v docker &> /dev/null; then
echo "docker未安装"
echo "未安装 Docker"
exit
fi
declare web_path
read -p "请输入数据目录,默认 /var/www " web_path
if [[ -z ${web_path} ]];then
web_path='/var/www'
declare data_directory
read -p "请输入数据目录,默认 /var/www " data_directory
if [[ -z ${data_directory} ]];then
data_directory='/var/www'
fi
cat > "${path}/up-docker_compose.sh" << EOF
cat > "${docker_compose_path}/up-docker_compose.sh" << EOF
#!/bin/bash
for dir in "${web_path}"/*/; do
for dir in "${data_directory}"/*/; do
cd "\$dir" || exit
sudo docker compose pull
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
echo 'sudo apt update -y' >> "${path}/update.sh"
echo 'sudo apt-get dist-upgrad -y' >> "${path}/update.sh"
echo 'sudo apt update -y' >> "${update_path}/update.sh"
echo 'sudo apt-get dist-upgrade -y' >> "${update_path}/update.sh"
elif [[ -f "/usr/bin/apt-get" ]];then
echo 'sudo apt-get update -y' >> "${path}/update.sh"
echo 'sudo apt dist-upgrade -y' >> "${path}/update.sh"
echo 'sudo apt-get update -y' >> "${update_path}/update.sh"
echo 'sudo apt dist-upgrade -y' >> "${update_path}/update.sh"
elif [[ -f "/usr/bin/pacman" ]];then
sudo pacman -Syu --noconfirm
else
rm "${path}/update.sh"
echo "暂不支持该系统配置自动更新软件"
rm "${update_path}/update.sh"
echo "暂不支持该系统的自动更新配置"
exit
fi

View File

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

View File

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

View File

@ -5,18 +5,18 @@ if ! command -v sudo &> /dev/null; then
exit
fi
declare path=$1
declare port=$2
declare installation_directory=$1
declare web_service_port=$2
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 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 'echo "ssh -p '$(( 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 gid=$( id git | awk -F'[=() ]+' '{print $5}' )
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 user_id=$( id git | awk -F'[=() ]+' '{print $2}' )
declare group_id=$( id git | awk -F'[=() ]+' '{print $5}' )
cd $path
cd $installation_directory
cat > "docker-compose.yml" << EOF
networks:
gitea:
@ -26,8 +26,8 @@ services:
image: gitea/gitea:latest
container_name: gitea
environment:
- USER_UID=${uid}
- USER_GID=${gid}
- USER_UID=${user_id}
- USER_GID=${group_id}
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=db:3306
- GITEA__database__NAME=gitea
@ -42,8 +42,8 @@ services:
- /etc/localtime:/etc/localtime:ro
- /home/git/.ssh/:/data/git/.ssh
ports:
- "${port}:3000"
- "$(( port+22 )):22"
- "${web_service_port}:3000"
- "$(( web_service_port+22 )):22"
depends_on:
- db
db:
@ -59,6 +59,6 @@ services:
volumes:
- ./mysql:/var/lib/mysql
EOF
chown -R git:git $path
chown -R git:git $installation_directory
sudo docker compose up -d

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,19 +1,19 @@
#!/bin/bash
declare path=$1
declare port=$2
cd $path
declare install_path=$1
declare service_port=$2
cd $install_path
declare namediv=$(basename $path)
declare project_name=$(basename $install_path)
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
mv Xboard "$namediv"
if [[ "$project_name" != Xboard ]];then
mv Xboard "$project_name"
fi
cd "$path"
cd "$install_path"
docker compose run -it --rm xboard php artisan xboard:install

View File

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

View File

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

View File

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

View File

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

View File

@ -39,7 +39,6 @@ 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 ))

View File

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

View File

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

View File

@ -1,9 +1,9 @@
#!/bin/bash
declare lang
declare language_choice
echo "========$(basename $0 .sh)========"
echo "1.中文"
echo "2.英文"
read -p "请输入:" lang
echo "1. 中文"
echo "2. 英文"
read -p "请输入:" language_choice
if [[ -f "/usr/bin/apt-get" ]];then
apt-get update -y
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
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
fi
case $lang in
case $language_choice 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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,23 +1,23 @@
#!/bin/bash
declare vpn_number=0
declare -a vpn_index
declare -A vpn_array
declare vpn_pick
declare vpn_count=0
declare -a vpn_options
declare -A vpn_commands
declare user_choice
vpn_array["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_array["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["v2ray"]='bash <(curl -s -L https://git.io/v2ray.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_commands["x-ui"]='bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/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
vpn_number=$((vpn_number+1))
vpn_index[${vpn_number}]=${i}
echo "${vpn_number}.${i}"
for i in "${!vpn_commands[@]}";do
vpn_count=$((vpn_count+1))
vpn_options[${vpn_count}]=${i}
echo "${vpn_count}.${i}"
done
read -p "请输入要选择的序号:" vpn_pick
read -p "请输入要选择的序号:" user_choice
if [[ $vpn_pick =~ [1-${#vpn_array[@]}] ]];then
eval "${vpn_array[${vpn_index[$vpn_pick]}]}"
if [[ $user_choice =~ [1-${#vpn_commands[@]}] ]];then
eval "${vpn_commands[${vpn_options[$user_choice]}]}"
echo "安装完成"
else
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
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
declare -a function_array
declare selected_function
declare script_path=$(dirname $0)
script_path="${script_path}/Config"
declare local_path=$script_path
declare script_name
while true
do
if [[ -e "${path_local}/test.sh" ]]; then
bash "${path_local}/test.sh"
if [[ -e "${local_path}/test.sh" ]]; then
bash "${local_path}/test.sh"
if [[ $? -eq 1 ]]; then
path_local=$path_script
local_path=$script_path
fi
fi
if [[ -e "${path_local}/menu.sh" ]]; then
if [[ -e "${local_path}/menu.sh" ]]; then
clear
bash "${path_local}/menu.sh" "$path_local"
path_local=$path_script
bash "${local_path}/menu.sh" "$local_path"
local_path=$script_path
fi
pick_number=0
pick_array=()
echo "======$(basename $path_local .sh)======"
for i in "${path_local}"/*
selected_function=0
function_array=()
echo "======$(basename $local_path .sh)======"
for i in "${local_path}"/*
do
file_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
if [[ $file_name == "test" ]]; then
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
if [[ $script_name == "test" ]]; then
continue
fi
pick_number=$((pick_number + 1))
pick_array[$pick_number]=$file_name
echo "${pick_number}.${pick_array[$pick_number]}"
selected_function=$((selected_function + 1))
function_array[$selected_function]=$script_name
echo "${selected_function}.${function_array[$selected_function]}"
done
if [[ $path_local != $path_script ]]; then
if [[ $local_path != $script_path ]]; then
echo "输入任意返回主页"
fi
read -p "请输入要使用的功能:" pick
if [[ "${pick}" =~ [1-${#pick_array[*]}] ]];then
read -p "请输入要使用的功能:" user_choice
if [[ "${user_choice}" =~ [1-${#function_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
if [[ -d "${local_path}/${function_array[$user_choice]}" ]]; then
local_path="${local_path}/${function_array[$user_choice]}"
elif [[ -e "${local_path}/${function_array[$user_choice]}.sh" ]]; then
bash "${local_path}/${function_array[$user_choice]}.sh"
local_path=$script_path
fi
else
if [[ $path_local == $path_script ]]; then
if [[ $local_path == $script_path ]]; then
exit
fi
path_local=$path_script
local_path=$script_path
fi
done