You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/bin/bash
# -------------------------------------------------------
# 基于nexus-cli的图形化工具
# openai提供技术支持
# 2024.5.16
# -------------------------------------------------------
# 假设nexus-cli已经在PATH中
NEXUS_CLI="nexus-cli"
IFS=" "
list_images() {
# 获取所有的 images 并移除最后的汇总行
readarray -t images <<< `$NEXUS_CLI image ls | grep -v xxl | sed '$d'`
# 检查是否获取到了镜像列表
if [ ${#images[@]} -eq 0 ]; then
whiptail --title "Error" --msgbox "No images found or unable to fetch images." 10 50
exit 1
fi
# 创建 whiptail 菜单选项,每行显示一个image,并在前面加上序号
menu_options=()
for i in "${!images[@]}"; do
menu_options+=("$(($i+1))" "${images[$i]}")
done
# 使用 whiptail 显示可选的 image 列表
selected_index=$(whiptail --title "NEXUS Image Maintenance Tool - Images" --menu "Choose an image" 30 80 20 "${menu_options[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
# 减去 1 是因为数组索引从 0 开始
list_tags "${images[$(($selected_index-1))]}"
fi
}
# 显示选定镜像的tag列表,并允许用户选择
list_tags() {
local image_name=$1
# 获取所有的 tags 并移除最后的汇总行
readarray -t tags <<< `$NEXUS_CLI image tags --name="$image_name" | sed '$d'`
if [ -z "$tags" ]; then
whiptail --title "Error" --msgbox "No tags found for image $image_name or unable to fetch tags." 10 50
return
fi
# 创建 whiptail 菜单选项,每行显示一个image,并在前面加上序号
menu_options=()
for i in "${!tags[@]}"; do
menu_options+=("$(($i+1))" "${tags[$i]}")
done
tag_selection=$(whiptail --title "NEXUS Image Maintenance Tool - Tags" --menu "Choose a tag of $image_name" 30 80 20 "${menu_options[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
show_info "$image_name" "${tags[$(($tag_selection-1))]}"
else
list_images
fi
}
# 显示所选tag的信息
show_info() {
local image_name=$1
local tag_name=$2
info=$($NEXUS_CLI image info --name="$image_name" --tag="$tag_name")
whiptail --title "Information for $image_name:$tag_name" --yes-button "OK" --no-button "Delete" --yesno "$info" 30 80
exit_status=$?
if [ $exit_status -eq 0 ]; then
# 用户选择了 OK
list_tags "$image_name"
else
# 用户选择了 Delete
delete_tag "$image_name" "$tag_name"
fi
}
# 删除指定的tag
delete_tag() {
local image_name=$1
local tag_name=$2
if (whiptail --yesno "Are you sure you want to delete the tag $tag_name of image $image_name?" 10 60); then
$NEXUS_CLI image delete --name="$image_name" --tag="$tag_name"
whiptail --msgbox "Tag $tag_name of image $image_name has been deleted." 10 60
fi
list_tags "$image_name"
}
# 检查nexus-cli是否存在
if ! command -v $NEXUS_CLI &> /dev/null; then
echo "nexus-cli could not be found. Please install it and add it to your PATH."
exit 1
fi
# 运行主程序
list_images
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: