2024-09-27 13:11:37 +08:00
|
|
|
|
#!/bin/bash
|
2024-11-19 16:47:40 +08:00
|
|
|
|
|
2024-11-19 00:06:43 +08:00
|
|
|
|
echo "1. 查看已安装的脚本"
|
|
|
|
|
echo "2. 删除脚本"
|
|
|
|
|
|
2024-11-19 17:07:26 +08:00
|
|
|
|
declare user_choice
|
2024-11-19 00:06:43 +08:00
|
|
|
|
read -p "请输入您的选择:" user_choice
|
|
|
|
|
|
2024-11-19 17:07:26 +08:00
|
|
|
|
declare script_directory="/var/script"
|
|
|
|
|
echo "请输入脚本安装目录,默认是 ${script_directory}:"
|
|
|
|
|
read -p "请输入:" input_directory
|
2024-11-19 16:47:40 +08:00
|
|
|
|
|
|
|
|
|
if [[ -n $input_directory ]]; then
|
|
|
|
|
script_directory="$input_directory"
|
|
|
|
|
fi
|
2024-11-19 00:06:43 +08:00
|
|
|
|
|
2024-11-19 16:47:40 +08:00
|
|
|
|
if [[ ! -d $script_directory ]]; then
|
2024-11-19 00:06:43 +08:00
|
|
|
|
echo "该目录不存在"
|
2024-11-19 16:47:40 +08:00
|
|
|
|
exit 1
|
2024-11-19 00:06:43 +08:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
function list_scripts() {
|
2024-11-19 16:47:40 +08:00
|
|
|
|
local script_count=0
|
2024-11-19 16:43:40 +08:00
|
|
|
|
for script in "$script_directory"/*; do
|
2024-11-19 16:47:40 +08:00
|
|
|
|
if [[ ! -e $script ]]; then
|
2024-11-19 00:00:28 +08:00
|
|
|
|
echo "该目录没有脚本"
|
2024-11-19 16:47:40 +08:00
|
|
|
|
return
|
2024-11-19 00:00:28 +08:00
|
|
|
|
fi
|
2024-11-19 16:47:40 +08:00
|
|
|
|
local script_name=$(basename "$script" | awk -F '.' '{print $1}')
|
2024-11-19 00:00:28 +08:00
|
|
|
|
if [[ $script_name == "linuxtool" ]]; then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
2024-11-19 16:43:40 +08:00
|
|
|
|
script_count=$((script_count + 1))
|
2024-11-19 00:06:43 +08:00
|
|
|
|
echo "${script_count}.${script_name}"
|
2024-11-19 17:07:26 +08:00
|
|
|
|
installed_scripts[$script_count]=$script_name
|
2024-11-19 00:00:28 +08:00
|
|
|
|
done
|
2024-11-19 16:47:40 +08:00
|
|
|
|
|
|
|
|
|
if [[ ${#installed_scripts[@]} -eq 0 ]]; then
|
2024-11-19 00:00:28 +08:00
|
|
|
|
echo "该目录没有脚本"
|
2024-11-19 16:47:40 +08:00
|
|
|
|
return
|
2024-11-19 00:00:28 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
case $user_choice in
|
2024-11-19 16:47:40 +08:00
|
|
|
|
'1')
|
|
|
|
|
list_scripts
|
|
|
|
|
;;
|
|
|
|
|
'2')
|
2024-11-19 17:07:26 +08:00
|
|
|
|
declare -a installed_scripts
|
|
|
|
|
list_scripts
|
2024-11-19 16:47:40 +08:00
|
|
|
|
read -p "请输入要删除的序号(多个用空格隔开):" script_indices
|
|
|
|
|
|
|
|
|
|
for index in $script_indices; do
|
|
|
|
|
if [[ $index =~ ^[1-9][0-9]*$ ]] && [ $index -le ${#installed_scripts[@]} ]; then
|
|
|
|
|
local script_to_delete=${installed_scripts[$((index - 1))]}
|
|
|
|
|
echo "开始删除 ${script_to_delete}"
|
|
|
|
|
(crontab -l 2>/dev/null | grep -v "$script_to_delete") | crontab - && echo "已删除脚本的自动任务"
|
|
|
|
|
rm -rf "$script_directory/$script_to_delete" &>/dev/null
|
|
|
|
|
echo "删除完成"
|
|
|
|
|
else
|
|
|
|
|
echo "无效的序号: $index"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "无效的选择"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
2024-11-19 16:43:40 +08:00
|
|
|
|
esac
|