linuxtool/Menus/Docker.sh

61 lines
1.6 KiB
Bash
Raw Normal View History

2024-07-23 20:50:16 +08:00
#!/bin/bash
2024-09-21 16:25:44 +08:00
declare path_script=$1
declare file_name=$(basename $0 .sh)
2024-07-23 20:50:16 +08:00
declare pick_array
declare pick_number=6
declare pick
echo "========$(basename $0 .sh)========"
2024-07-23 20:50:16 +08:00
echo "1.换源"
echo "2.清除所有未使用镜像"
2024-07-23 20:50:16 +08:00
echo "-----一键搭建软件-----"
for i in "${path_script}/Config/${file_name}"/*;do
2024-07-23 20:50:16 +08:00
pick_number=$((pick_number + 1))
pick_array[$pick_number]=$(awk -F '.' '{print $1}' <<< "$(basename $i)")
2024-07-23 20:50:16 +08:00
echo "${pick_number}.${pick_array[$pick_number]}"
done
echo "-----一键搭建软件-----"
echo "任意输入返回主菜单"
2024-07-23 20:50:16 +08:00
read -p "请输入要使用的功能:" pick
clear
2024-07-23 20:50:16 +08:00
if [[ $pick == '1' ]];then
declare -A img_dick
declare -a img_number
declare img_pick=0
2024-07-24 14:20:04 +08:00
img_dick['Daocloud(默认)']='https://docker.m.daocloud.io'
for i in "${!img_dick[@]}";
do
img_pick=$(( img_pick+1 ))
img_number[$img_pick]=$i
echo "${img_pick}.${i}"
done
read -p "请输入要选择的镜像,也可直接输入镜像网站:" img_pick
if [[ -z $img_pick ]];then
2024-07-24 14:20:04 +08:00
declare url='https://docker.m.daocloud.io'
elif [[ $img_pick =~ [\w\.]+ ]];then
declare url=$img_pick
elif [[ ${img_pick} =~ [1-${!img_dick[*]}] ]];then
img_pick=${img_number[$img_pick]}
declare url=${img_dick[$img_pick]}
else
echo "输入错误"
exit
fi
2024-09-23 17:59:28 +08:00
echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json"
systemctl restart docker 2>> /dev/null|| echo "docker 重启失败"&&exit
echo "换源成功"
elif [[ $pick == '2' ]];then
2024-09-23 17:59:28 +08:00
docker system prune -af
echo "清理完成"
elif [[ "${pick}" =~ [${pick_number}-${#pick_array[*]}] ]];then
2024-07-23 20:50:16 +08:00
fi