linuxtool/Config/Docker/manage.sh

52 lines
1.4 KiB
Bash
Raw Permalink 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 "该地址不存在目录"
2024-11-19 00:00:28 +08:00
exit 1
2024-09-26 19:31:17 +08:00
fi
2024-11-19 00:00:28 +08:00
function list_sites() {
local site_number=0
for site in "$site_path"/* ; do
if [[ ! -d $site ]]; then
echo "该地址不存在站点"
return
fi
site_number=$(( site_number + 1 ))
site_name=$(awk -F '.' '{print $1}' <<< "$(basename "$site")")
echo "${site_number}.${site_name}"
site_array[$site_number]=$site_name
done
}
case $user_choice in
2024-09-26 19:31:17 +08:00
'1')
2024-11-19 00:00:28 +08:00
list_sites
;;
2024-09-26 19:31:17 +08:00
'2')
2024-11-19 00:00:28 +08:00
declare -a site_array
list_sites
read -p "请输入要删除的序号,多个用空格隔开:" selected_sites
for i in $selected_sites ; do
if [[ $i =~ ^[1-9][0-9]*$ ]] && [ "$i" -le "${#site_array[@]}" ]; then
echo "开始删除 ${site_array[$i]}"
cd "$site_path/${site_array[$i]}" || exit
docker compose down &> /dev/null && echo "站点已停止运行"
rm -rf "$site_path/${site_array[$i]}" &> /dev/null
echo "删除完成"
fi
done
2024-11-19 00:06:43 +08:00
echo "全部删除完成"
2024-11-19 00:00:28 +08:00
;;
2024-09-26 19:31:17 +08:00
esac