2024-09-27 13:11:37 +08:00
|
|
|
#!/bin/bash
|
2024-11-18 23:12:52 +08:00
|
|
|
echo "1. 查看已安装的脚本"
|
|
|
|
echo "2. 删除脚本"
|
2024-09-27 13:11:37 +08:00
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
declare user_choice
|
|
|
|
read -p "请输入您的选择:" user_choice
|
2024-09-27 13:11:37 +08:00
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
declare script_directory="/var/script"
|
|
|
|
echo "请输入脚本安装目录,默认是 ${script_directory}"
|
|
|
|
read -p "请输入:" script_directory
|
2024-09-27 13:11:37 +08:00
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
if [[ -z $script_directory ]]; then
|
|
|
|
script_directory="/var/script"
|
|
|
|
elif ! [[ -d $script_directory ]]; then
|
|
|
|
echo "该目录不存在"
|
2024-09-27 13:11:37 +08:00
|
|
|
fi
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
case $user_choice in
|
2024-09-27 13:11:37 +08:00
|
|
|
'1')
|
2024-11-18 23:12:52 +08:00
|
|
|
declare -a installed_scripts
|
2024-09-27 14:45:16 +08:00
|
|
|
declare script_name
|
2024-11-18 23:12:52 +08:00
|
|
|
declare script_count=0
|
|
|
|
for script in "$script_directory"/* ; do
|
|
|
|
if [[ $script == "${script_directory}/*" ]];then
|
|
|
|
echo "该目录没有脚本"
|
2024-09-27 14:45:16 +08:00
|
|
|
exit
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $script)")
|
2024-09-27 14:45:16 +08:00
|
|
|
if [[ $script_name == "linuxtool" ]]; then
|
|
|
|
continue
|
2024-09-27 13:11:37 +08:00
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
script_count=$(( script_count+1 ))
|
|
|
|
echo "${script_count}.${script_name}"
|
|
|
|
installed_scripts[$script_count]=$script_name
|
2024-09-27 13:11:37 +08:00
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
if [ ${#installed_scripts[@]} == 0 ]; then
|
|
|
|
echo "该目录没有脚本"
|
2024-09-27 14:45:16 +08:00
|
|
|
exit
|
|
|
|
fi
|
2024-09-27 13:11:37 +08:00
|
|
|
;;
|
|
|
|
'2')
|
2024-11-18 23:12:52 +08:00
|
|
|
declare -a installed_scripts
|
2024-09-27 13:11:37 +08:00
|
|
|
declare script_name
|
2024-11-18 23:12:52 +08:00
|
|
|
declare script_count=0
|
|
|
|
for script in "$script_directory"/* ; do
|
|
|
|
if [[ $script == "${script_directory}/*" ]];then
|
|
|
|
echo "该目录没有脚本"
|
2024-09-27 14:45:16 +08:00
|
|
|
exit
|
2024-09-27 13:11:37 +08:00
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
script_name=$(awk -F '.' '{print $1}' <<< "$(basename $script)")
|
2024-09-27 13:20:43 +08:00
|
|
|
if [[ $script_name == "linuxtool" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
script_count=$(( script_count+1 ))
|
|
|
|
echo "${script_count}.${script_name}"
|
|
|
|
installed_scripts[$script_count]=$script_name
|
2024-09-27 13:11:37 +08:00
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
if [ ${#installed_scripts[@]} == 0 ]; then
|
|
|
|
echo "该目录没有脚本"
|
2024-09-27 14:45:16 +08:00
|
|
|
exit
|
|
|
|
fi
|
2024-11-18 23:12:52 +08:00
|
|
|
read -p "请输入要删除的序号(多个用空格隔开):" script_name
|
2024-09-27 13:11:37 +08:00
|
|
|
for i in $script_name ; do
|
2024-11-18 23:12:52 +08:00
|
|
|
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
|
2024-09-27 13:11:37 +08:00
|
|
|
echo "删除完成"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|