linuxtool/Config/Docker/manage.sh

53 lines
1.4 KiB
Bash
Raw Normal View History

2024-09-26 19:31:17 +08:00
#!/bin/bash
echo "1. 查看已安装的站点"
echo "2. 删除软件"
2024-09-26 19:31:17 +08:00
declare user_choice
read -p "请输入:" user_choice
2024-09-26 19:31:17 +08:00
declare site_path="/var/www"
echo "请输入站点安装地址,默认 ${site_path}"
read -p "请输入:" site_path
2024-09-26 19:31:17 +08:00
if [[ -z $site_path ]]; then
site_path="/var/www"
elif ! [[ -d $site_path ]]; then
2024-09-26 19:31:17 +08:00
echo "该地址不存在目录"
fi
case $user_choice in
2024-09-26 19:31:17 +08:00
'1')
for site in "$site_path"/* ; do
if [[ $site == "${site_path}/*" ]];then
2024-09-26 19:46:58 +08:00
echo "该地址不存在站点"
fi
echo $site
2024-09-26 19:31:17 +08:00
done
;;
'2')
declare -a site_array
2024-09-26 19:31:17 +08:00
declare site_name
declare site_number=0
for site in "$site_path"/* ; do
if [[ $site == "${site_path}/*" ]];then
2024-09-27 13:11:37 +08:00
echo "该地址不存在站点"
exit
fi
2024-09-26 19:31:17 +08:00
site_number=$(( site_number+1 ))
site_name=$(awk -F '.' '{print $1}' <<< "$(basename $site)")
2024-09-26 19:31:17 +08:00
echo "${site_number}.${site_name}"
site_array[$site_number]=$site_name
2024-09-26 19:31:17 +08:00
done
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
2024-09-26 19:46:58 +08:00
echo "删除完成"
2024-09-26 19:31:17 +08:00
fi
done
echo "删除完成"
;;
esac