#!/bin/bash

local_sha=$(docker inspect --format='{{index .RepoDigests 0}}' xiaoyaliu/glue:python  |cut -f2 -d:)
remote_sha=$(curl --ipv4 -s "https://hub.docker.com/v2/repositories/xiaoyaliu/glue/tags/python"|grep -o '"digest":"[^"]*' | grep -o '[^"]*$'  |tail -n1 |cut -f2 -d:)
if [ ! "$local_sha" == "$remote_sha" ]; then
        docker rmi xiaoyaliu/glue:python
fi
config_dir="$(docker inspect --format='{{range $v,$conf := .Mounts}}{{$conf.Source}}:{{$conf.Destination}}{{$conf.Type}}~{{end}}' xiaoya | tr '~' '\n' | grep bind | sed 's/bind//g' | grep ":/data$" | awk -F: '{print $1}')"
docker pull xiaoyaliu/glue:python

options=("网页" "IOS" "115 IOS" "安卓" "115安卓" "115 iPad" "115 TV" "115管理" "微信小程序" "支付宝小程序")
english_options=("web" "ios" "115ios" "android" "115android" "115ipad" "tv" "qandroid" "wechatmini" "alipaymini")
echo "请选择一个选项:"
select opt in "${options[@]}"; do
    case $REPLY in
        1) selected_option="${english_options[0]}"; break;;
        2) selected_option="${english_options[1]}"; break;;
        3) selected_option="${english_options[2]}"; break;;
        4) selected_option="${english_options[3]}"; break;;
        5) selected_option="${english_options[4]}"; break;;
        6) selected_option="${english_options[5]}"; break;;
        7) selected_option="${english_options[6]}"; break;;
        8) selected_option="${english_options[7]}"; break;;
        9) selected_option="${english_options[8]}"; break;;
        10) selected_option="${english_options[9]}"; break;;
        *) echo "无效选项,请重试。";;
    esac
done

echo "您选择登入的设备是: $opt"

echo "请扫码"
echo ""

docker run -it --rm -v $config_dir:/data -e LANG=C.UTF-8  xiaoyaliu/glue:python /115cookie.py $selected_option
