Skip to content

Commit

Permalink
feat: get emby version modularization
Browse files Browse the repository at this point in the history
  • Loading branch information
DDSRem committed Jan 7, 2025
1 parent 50200e8 commit c01a2b8
Showing 1 changed file with 55 additions and 82 deletions.
137 changes: 55 additions & 82 deletions all_in_one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,45 @@ function pull_run_glue_xh() {

}

function get_emby_version() {

local emby_name emby_image_name emby_config_dir CURRENT_ULIMIT
emby_name=$(cat "${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt")
if ! docker container inspect "${emby_name}" > /dev/null 2>&1; then
WARN "未检测到 Emby 容器,请确保您已安装 Emby!"
return 1
fi
emby_image_name="$(docker container inspect -f '{{.Config.Image}}' "${emby_name}")"
if [ -z "${emby_image_name}" ]; then
WARN "获取 Emby 镜像标签失败"
return 1
fi
emby_config_dir="$(docker inspect --format='{{range $v,$conf := .Mounts}}{{$conf.Source}}:{{$conf.Destination}}{{$conf.Type}}~{{end}}' "${emby_name}" | tr '~' '\n' | grep bind | sed 's/bind//g' | grep ":/config$" | awk -F: '{print $1}')"
if [ -z "${emby_config_dir}" ] || ! check_path "${emby_config_dir}"; then
WARN "Emby 配置目录获取失败,使用 /tmp 目录替代!"
emby_config_dir=/tmp
fi
if [ -f "${emby_config_dir}/EmbyServer.deps.json" ]; then
rm -f "${emby_config_dir}/EmbyServer.deps.json"
fi
CURRENT_ULIMIT=$(ulimit -n)
ulimit -n 65535
docker run --rm --ulimit nofile=65535:65535 --entrypoint cp -v "${emby_config_dir}:/data" "${emby_image_name}" /system/EmbyServer.deps.json /data
ulimit -n "${CURRENT_ULIMIT}"
if [ ! -f "${emby_config_dir}/EmbyServer.deps.json" ]; then
WARN "Emby 版本数据文件复制失败!"
return 1
fi
emby_version=$(grep "EmbyServer" "${emby_config_dir}/EmbyServer.deps.json" | head -n 1 | sed -n 's|.*EmbyServer/\(.*\)":.*|\1|p')
rm -f "${emby_config_dir}/EmbyServer.deps.json"
if [ -z "${emby_version}" ]; then
WARN "当前 Emby 版本获取失败!"
return 1
fi
return 0

}

function set_emby_server_infuse_api_key() {

get_docker0_url
Expand Down Expand Up @@ -2366,27 +2405,7 @@ function download_unzip_xiaoya_emby_new_config() {
if [[ "${OPERATE}" == [Nn] ]]; then
exit 0
fi
local emby_name emby_image_name emby_version
emby_name="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"
emby_image_name="$(docker container inspect -f '{{.Config.Image}}' "${emby_name}")"
if [ -z "${emby_image_name}" ]; then
ERROR "获取 Emby 镜像标签失败,请确保您已安装 Emby!"
exit 1
fi
if [ -f "${MEDIA_DIR}/EmbyServer.deps.json" ]; then
rm -f "${MEDIA_DIR}/EmbyServer.deps.json"
fi
CURRENT_ULIMIT=$(ulimit -n)
ulimit -n 65535
docker run --rm --ulimit nofile=65535:65535 --entrypoint cp -v "${MEDIA_DIR}:/data" "${emby_image_name}" /system/EmbyServer.deps.json /data
ulimit -n "${CURRENT_ULIMIT}"
if [ ! -f "${MEDIA_DIR}/EmbyServer.deps.json" ]; then
ERROR "Emby 版本数据文件复制失败!"
exit 1
fi
emby_version=$(grep "EmbyServer" "${MEDIA_DIR}/EmbyServer.deps.json" | head -n 1 | sed -n 's|.*EmbyServer/\(.*\)":.*|\1|p')
rm -f "${MEDIA_DIR}/EmbyServer.deps.json"
if [ -n "${emby_version}" ]; then
if get_emby_version; then
INFO "当前 Emby 版本:${emby_version}"
else
ERROR "当前 Emby 版本获取失败!"
Expand All @@ -2398,8 +2417,8 @@ function download_unzip_xiaoya_emby_new_config() {
fi

INFO "关闭 Emby 容器中..."
if ! docker stop "${emby_name}"; then
if ! docker kill "${emby_name}"; then
if ! docker stop "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"; then
if ! docker kill "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"; then
ERROR "关闭 Emby 容器失败!"
exit 1
fi
Expand Down Expand Up @@ -2442,7 +2461,7 @@ function download_unzip_xiaoya_emby_new_config() {

__unzip_metadata "config.new.mp4"

docker start "${emby_name}"
docker start "$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)"
sleep 5
wait_emby_start

Expand Down Expand Up @@ -3120,54 +3139,6 @@ function install_emby_xiaoya_all_emby() {

function oneclick_upgrade_emby() {

function check_emby_version() {

if [ "${1}" == "${2}" ]; then
return 0
fi

if [ "$(echo -e "${1}\n${2}" | sort -V | head -n1)" == "${1}" ]; then
return 1
else
return 0
fi

}

function get_emby_version() {

local emby_name emby_image_name emby_config_dir CURRENT_ULIMIT
emby_name=$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)
emby_image_name="$(docker container inspect -f '{{.Config.Image}}' "${emby_name}")"
emby_config_dir="$(docker inspect --format='{{range $v,$conf := .Mounts}}{{$conf.Source}}:{{$conf.Destination}}{{$conf.Type}}~{{end}}' "${emby_name}" | tr '~' '\n' | grep bind | sed 's/bind//g' | grep ":/config$" | awk -F: '{print $1}')"
if [ -z "${emby_image_name}" ]; then
WARN "获取 Emby 镜像标签失败,请确保您已安装 Emby!"
return 1
fi
if [ -z "${emby_config_dir}" ] || ! check_path "${emby_config_dir}"; then
WARN "Emby 配置目录获取失败,使用 /tmp 目录替代!"
emby_config_dir=/tmp
fi
if [ -f "${emby_config_dir}/EmbyServer.deps.json" ]; then
rm -f "${emby_config_dir}/EmbyServer.deps.json"
fi
CURRENT_ULIMIT=$(ulimit -n)
ulimit -n 65535
docker run --rm --ulimit nofile=65535:65535 --entrypoint cp -v "${emby_config_dir}:/data" "${emby_image_name}" /system/EmbyServer.deps.json /data
ulimit -n "${CURRENT_ULIMIT}"
if [ ! -f "${emby_config_dir}/EmbyServer.deps.json" ]; then
WARN "Emby 版本数据文件复制失败!"
return 1
fi
emby_version=$(grep "EmbyServer" "${emby_config_dir}/EmbyServer.deps.json" | head -n 1 | sed -n 's|.*EmbyServer/\(.*\)":.*|\1|p')
rm -f "${emby_config_dir}/EmbyServer.deps.json"
if [ -z "${emby_version}" ]; then
WARN "当前 Emby 版本获取失败!"
return 1
fi

}

local emby_name
emby_name=$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)
if docker inspect ddsderek/runlike:latest > /dev/null 2>&1; then
Expand Down Expand Up @@ -3225,15 +3196,16 @@ function oneclick_upgrade_emby() {
;;
*)
ERROR "输入无效,请重新选择"
check_emby_version_status=false
;;
esac
if [ "${check_emby_version_status}" == true ]; then
if check_emby_version "${choose_emby_version}" "${emby_version}"; then
break
else
if [ "${check_emby_version_status}" == true ] && [ -n "${choose_emby_version}" ]; then
if version_lt "${choose_emby_version}" "${emby_version}"; then
ERROR "您选择升级的 Emby 版本低于当前安装 Emby 版本,Emby 版本无法降级,请重新选择"
else
break
fi
elif [ "${check_emby_version_status}" == false ] && [ -n "${choose_emby_version}" ]; then
break
fi
fi
elif [ "${old_image_name}" == "lovechen/embyserver" ]; then
Expand Down Expand Up @@ -3266,15 +3238,16 @@ function oneclick_upgrade_emby() {
;;
*)
ERROR "输入无效,请重新选择"
check_emby_version_status=false
;;
esac
if [ "${check_emby_version_status}" == true ]; then
if check_emby_version "${choose_emby_version}" "${emby_version}"; then
break
else
if [ "${check_emby_version_status}" == true ] && [ -n "${choose_emby_version}" ]; then
if version_lt "${choose_emby_version}" "${emby_version}"; then
ERROR "您选择升级的 Emby 版本低于当前安装 Emby 版本,Emby 版本无法降级,请重新选择"
else
break
fi
elif [ "${check_emby_version_status}" == false ] && [ -n "${choose_emby_version}" ]; then
break
fi
fi
done
Expand Down

0 comments on commit c01a2b8

Please sign in to comment.