更新软件结构

This commit is contained in:
lsy 2024-09-26 10:53:51 +08:00
parent db267ea0b9
commit 35c77a1a01
23 changed files with 75 additions and 27 deletions

31
Config/Docker/image.sh Normal file
View File

@ -0,0 +1,31 @@
#!/bin/bash
echo "1.查看当前运行中的镜像"
echo "2.停止镜像"
echo "3.删除没有使用的镜像"
declare pick
read -p "请输入:" pick
case $pick in
'1')
docker ps --format "{{.Names}}"
;;
'2')
declare -a deocker_arr=($(docker ps --format "{{.Names}}"))
declare deocker_number=0
for i in "${!deocker_arr[@]}" ; do
deocker_number=$(( deocker_number+1 ))
echo "${deocker_number}.${i}"
done
echo "要删除的镜像序号,多个镜像用 空格 隔开"
read -p "请输入:" pick
for i in $pick ; do
if [[ $i =~ [1-$deocker_number] ]]; then
docker rmi "${deocker_arr[$i]}"
fi
done
;;
'3')
docker system prune -af
echo "清理完成"
esac

42
Config/Docker/source.sh Normal file
View File

@ -0,0 +1,42 @@
#!/bin/bash
echo "========$(basename $0 .sh)========"
echo "1.查看当前源"
echo "2.换源"
declare pick
read -p "请输入:" pick
case $pick in
'1')
grep -oP '(https?://[^\"]+)' /etc/docker/daemon.json
;;
'2')
declare -A img_dick
declare -a img_number
declare img_pick=0
img_dick['Daocloud(默认)']='https://docker.m.daocloud.io'
img_dick['官方']='docker.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
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
echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json"
systemctl restart docker 2>> /dev/null|| echo "docker 重启失败"&&exit
echo "换源成功"
;;
esac

View File

@ -23,36 +23,10 @@ read -p "请输入要使用的功能:" pick
clear clear
if [[ $pick == '1' ]];then if [[ $pick == '1' ]];then
declare -A img_dick
declare -a img_number
declare img_pick=0
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
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
echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json"
systemctl restart docker 2>> /dev/null|| echo "docker 重启失败"&&exit
echo "换源成功"
elif [[ $pick == '2' ]];then elif [[ $pick == '2' ]];then
docker system prune -af
echo "清理完成"
elif [[ "${pick}" =~ [${pick_number}-${#pick_array[*]}] ]];then elif [[ "${pick}" =~ [${pick_number}-${#pick_array[*]}] ]];then
fi fi

1
Run.sh
View File

@ -27,6 +27,7 @@ if [[ -e "${path_local}/menu.sh" ]]; then
path_local=$path_script path_local=$path_script
fi fi
pick_number=0 pick_number=0
pick_array=()
echo "======$(basename $path_local .sh)======" echo "======$(basename $path_local .sh)======"
for i in "${path_local}"/* for i in "${path_local}"/*
do do