2024-09-27 14:22:23 +08:00
|
|
|
#!/bin/bash
|
2024-11-18 23:12:52 +08:00
|
|
|
declare user_choice
|
2024-09-27 14:22:23 +08:00
|
|
|
echo "========$(basename $0 .sh)========"
|
|
|
|
echo "1.查看已有站点配置文件"
|
|
|
|
echo "2.删除站点配置文件"
|
2024-11-18 23:12:52 +08:00
|
|
|
read -p "请选择操作:" user_choice
|
|
|
|
case $user_choice in
|
2024-09-27 14:22:23 +08:00
|
|
|
'1')
|
2024-11-18 23:12:52 +08:00
|
|
|
declare -a site_array
|
2024-09-27 14:22:23 +08:00
|
|
|
declare site_name
|
2024-11-18 23:12:52 +08:00
|
|
|
declare site_count=0
|
2024-09-27 14:22:23 +08:00
|
|
|
for i in "/etc/nginx/sites-available"/* ; do
|
|
|
|
if [[ $i == "/etc/nginx/sites-available/*" ]];then
|
|
|
|
echo "暂时没有配置文件"
|
|
|
|
exit
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
site_count=$(( site_count+1 ))
|
2024-09-27 14:22:23 +08:00
|
|
|
site_name=$(basename $i)
|
2024-11-18 23:12:52 +08:00
|
|
|
echo "${site_count}.${site_name}"
|
|
|
|
site_array[$site_count]=$site_name
|
2024-09-27 14:22:23 +08:00
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
if [ ${#site_array[@]} == 0 ]; then
|
2024-09-27 14:45:16 +08:00
|
|
|
echo "暂时没有配置文件"
|
|
|
|
exit
|
|
|
|
fi
|
2024-09-27 14:22:23 +08:00
|
|
|
;;
|
|
|
|
'2')
|
2024-11-18 23:12:52 +08:00
|
|
|
declare -a site_array
|
2024-09-27 14:22:23 +08:00
|
|
|
declare site_name
|
2024-11-18 23:12:52 +08:00
|
|
|
declare site_count=0
|
2024-09-27 14:22:23 +08:00
|
|
|
for i in "/etc/nginx/sites-available"/* ; do
|
|
|
|
if [[ $i == "/etc/nginx/sites-available/*" ]];then
|
|
|
|
echo "暂时没有配置文件"
|
|
|
|
exit
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
site_count=$(( site_count+1 ))
|
2024-09-27 14:22:23 +08:00
|
|
|
site_name=$(basename $i)
|
2024-11-18 23:12:52 +08:00
|
|
|
echo "${site_count}.${site_name}"
|
|
|
|
site_array[$site_count]=$site_name
|
2024-09-27 14:22:23 +08:00
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
if [ ${#site_array[@]} == 0 ]; then
|
2024-09-27 14:45:16 +08:00
|
|
|
echo "暂时没有配置文件"
|
|
|
|
exit
|
|
|
|
fi
|
2024-09-27 14:22:23 +08:00
|
|
|
read -p "请输入要删除的序号,多个用 空格 隔开:" site_name
|
|
|
|
for i in $site_name ; do
|
2024-11-18 23:12:52 +08:00
|
|
|
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
|
2024-09-27 14:22:23 +08:00
|
|
|
echo "删除完成"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "删除完成"
|
|
|
|
;;
|
|
|
|
esac
|