From 10d29913e520a03ae08a009833da0c9ae3dca53e Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:21:19 +0800 Subject: [PATCH] chore: clean up redundant files --- .github/workflows/backup.yml | 38 - .github/workflows/test.yml | 13 - .github/workflows/xiaoyahelper.yml | 60 -- README.md | 2 +- .../.github/workflows/emby_library.yml | 65 -- deprecation/.github/workflows/glue.yml | 65 -- deprecation/emby_library/Dockerfile | 25 - deprecation/emby_library/entrypoint.sh | 49 - deprecation/emby_library/install.sh | 125 --- deprecation/emby_library/module.sh | 118 --- deprecation/glue/Dockerfile | 3 - deprecation/glue/docker_address.sh | 80 -- xiaoyahelper/Dockerfile | 14 - xiaoyahelper/README.md | 65 -- xiaoyahelper/aliyun_clear.sh | 959 ------------------ 15 files changed, 1 insertion(+), 1680 deletions(-) delete mode 100644 .github/workflows/backup.yml delete mode 100644 .github/workflows/xiaoyahelper.yml delete mode 100644 deprecation/.github/workflows/emby_library.yml delete mode 100644 deprecation/.github/workflows/glue.yml delete mode 100644 deprecation/emby_library/Dockerfile delete mode 100644 deprecation/emby_library/entrypoint.sh delete mode 100644 deprecation/emby_library/install.sh delete mode 100644 deprecation/emby_library/module.sh delete mode 100644 deprecation/glue/Dockerfile delete mode 100644 deprecation/glue/docker_address.sh delete mode 100644 xiaoyahelper/Dockerfile delete mode 100644 xiaoyahelper/README.md delete mode 100644 xiaoyahelper/aliyun_clear.sh diff --git a/.github/workflows/backup.yml b/.github/workflows/backup.yml deleted file mode 100644 index 9d668d2..0000000 --- a/.github/workflows/backup.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: backup - -on: - workflow_dispatch: - push: - branches: - - master - paths: - - "xiaoyahelper/**" - - ".github/workflows/backup.yml" - schedule: - - cron: '0 */12 * * *' - -jobs: - - xiaoyahelper: - runs-on: ubuntu-latest - name: xiaoyahelper - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: xiaoyahelper - run: | - mv ./xiaoyahelper/aliyun_clear.sh ./xiaoyahelper/aliyun_clear.sh.backup - wget -O ./xiaoyahelper/aliyun_clear.sh https://xiaoyahelper.zengge99.eu.org/aliyun_clear.sh - if [ -f ./xiaoyahelper/aliyun_clear.sh ]; then - rm -rf ./xiaoyahelper/aliyun_clear.sh.backup - else - mv ./xiaoyahelper/aliyun_clear.sh.backup ./xiaoyahelper/aliyun_clear.sh - fi - - - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: 'chore: backup xiaoyahelper' - branch: master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46aea7c..b19cf31 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,18 +6,6 @@ on: pull_request: jobs: - # test: - # runs-on: ubuntu-latest - # name: Test - # steps: - # - - # name: Checkout - # uses: actions/checkout@v4 - - # - name: Test - # run: | - # bash main.sh test - sh-checker: runs-on: ubuntu-latest name: sh-checker @@ -34,7 +22,6 @@ jobs: SHFMT_OPTS: -d -i 4 -sr with: sh_checker_comment: true - sh_checker_exclude: "^deprecation/* ^xiaoyahelper/*" ruff: runs-on: ubuntu-latest diff --git a/.github/workflows/xiaoyahelper.yml b/.github/workflows/xiaoyahelper.yml deleted file mode 100644 index ad06dcb..0000000 --- a/.github/workflows/xiaoyahelper.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: xiaoyahelper - -on: - workflow_dispatch: - push: - branches: - - master - paths: - - "xiaoyahelper/**" - - ".github/workflows/xiaoyahelper.yml" - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ secrets.DOCKER_USERNAME }}/xiaoyakeeper - tags: | - type=raw,value=latest - - - name: Set Up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set Up Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build - uses: docker/build-push-action@v6 - with: - context: ./xiaoyahelper - file: xiaoyahelper/Dockerfile - platforms: | - linux/amd64,linux/arm64/v8,linux/arm/v7 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha,scope=${{ github.workflow }}_xiaoyahelper - cache-to: type=gha,scope=${{ github.workflow }}_xiaoyahelper - - - name: Docker Hub Description - uses: peter-evans/dockerhub-description@v4 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ${{ secrets.DOCKER_USERNAME }}/xiaoyakeeper - short-description: 小雅Alist的相关周边 - readme-filepath: ./xiaoyahelper/README.md diff --git a/README.md b/README.md index 1b829dc..3e27ec0 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ Docker镜像源选择 -> 9 6 ## 小雅周边工具集合 - [Xiaoya-convert](https://github.com/ypq123456789/xiaoya-convert): 自动批量将阿里云盘分享链接转换为小雅`alishare_list.txt`中的格式 -- [Xiaoyahelper](https://github.com/xiaoyaDev/xiaoya-alist/tree/master/xiaoyahelper): 一劳永逸的小雅转存清理工具 +- [Xiaoyahelper](https://github.com/xiaoyaDev/xiaoyahelper): 一劳永逸的小雅转存清理工具 - [Alist-TVBox](https://hub.docker.com/r/haroldli/alist-tvbox): 一个基于`AList`和`xiaoya`的`TVBox`管理工具 - [`strm`文件生成](https://xiaoyaliu.notion.site/strm-2c8d136ceb37445fb6c0222eafb966ce): 小雅官方提供的一键生成`strm`文件脚本 - [monlor/docker-xiaoya](https://github.com/monlor/docker-xiaoya): Docker Compose 方式一键部署小雅全家桶 diff --git a/deprecation/.github/workflows/emby_library.yml b/deprecation/.github/workflows/emby_library.yml deleted file mode 100644 index 1d2c44b..0000000 --- a/deprecation/.github/workflows/emby_library.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: xiaoya emby library - -on: - workflow_dispatch: - push: - branches: - - master - paths: - - "emby_library/**" - - ".github/workflows/emby_library.yml" - -jobs: - build: - runs-on: ubuntu-latest - name: Build Docker Image - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ secrets.DOCKER_USERNAME }}/xiaoya-emby-library - tags: | - type=raw,value=latest - - - - name: Set Up QEMU - uses: docker/setup-qemu-action@v3 - - - - name: Set Up Buildx - uses: docker/setup-buildx-action@v3 - - - - name: Login DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - - name: Build Image - uses: docker/build-push-action@v6 - with: - context: ./emby_library - file: emby_library/Dockerfile - platforms: | - linux/amd64 - linux/arm64/v8 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - - - name: Docker Hub Description - uses: peter-evans/dockerhub-description@v4 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ${{ secrets.DOCKER_USERNAME }}/xiaoya-emby-library - short-description: 小雅Alist的相关周边 - readme-filepath: ./README.md \ No newline at end of file diff --git a/deprecation/.github/workflows/glue.yml b/deprecation/.github/workflows/glue.yml deleted file mode 100644 index 6c70e11..0000000 --- a/deprecation/.github/workflows/glue.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: xiaoya glue - -on: - workflow_dispatch: - push: - branches: - - master - paths: - - "glue/**" - - ".github/workflows/glue.yml" - -jobs: - build: - runs-on: ubuntu-latest - name: Build Docker Image - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ secrets.DOCKER_USERNAME }}/xiaoya-glue - tags: | - type=raw,value=latest - - - - name: Set Up QEMU - uses: docker/setup-qemu-action@v3 - - - - name: Set Up Buildx - uses: docker/setup-buildx-action@v3 - - - - name: Login DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - - name: Build Image - uses: docker/build-push-action@v6 - with: - context: ./glue - file: glue/Dockerfile - platforms: | - linux/amd64 - linux/arm64/v8 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - - - name: Docker Hub Description - uses: peter-evans/dockerhub-description@v4 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ${{ secrets.DOCKER_USERNAME }}/xiaoya-glue - short-description: 小雅Alist的相关周边 - readme-filepath: ./README.md \ No newline at end of file diff --git a/deprecation/emby_library/Dockerfile b/deprecation/emby_library/Dockerfile deleted file mode 100644 index 10f58bb..0000000 --- a/deprecation/emby_library/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM alpine:3.21 - -ENV LANG=C.UTF-8 \ - PS1="\[\e[32m\][\[\e[m\]\[\e[36m\]\u \[\e[m\]\[\e[37m\]@ \[\e[m\]\[\e[34m\]\h\[\e[m\]\[\e[32m\]]\[\e[m\] \[\e[37;35m\]in\[\e[m\] \[\e[33m\]\w\[\e[m\] \[\e[32m\][\[\e[m\]\[\e[37m\]\d\[\e[m\] \[\e[m\]\[\e[37m\]\t\[\e[m\]\[\e[32m\]]\[\e[m\] \n\[\e[1;31m\]$ \[\e[0m\]" \ - TZ=Asia/Shanghai - -RUN set -ex && \ - apk add --no-cache \ - jq \ - bash \ - tzdata \ - grep \ - sqlite \ - docker \ - curl \ - tini && \ - rm -rf \ - /root/.cache \ - /tmp/* - -WORKDIR /app - -COPY --chmod=755 . /app - -ENTRYPOINT ["tini", "-g", "--", "/app/entrypoint.sh"] \ No newline at end of file diff --git a/deprecation/emby_library/entrypoint.sh b/deprecation/emby_library/entrypoint.sh deleted file mode 100644 index 57dedbc..0000000 --- a/deprecation/emby_library/entrypoint.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# —————————————————————————————————————————————————————————————————————————————————— -# __ ___ _ _ _ -# \ \ / (_) /\ | (_) | | -# \ V / _ __ _ ___ _ _ __ _ / \ | |_ ___| |_ -# > < | |/ _` |/ _ \| | | |/ _` | / /\ \ | | / __| __| -# / . \| | (_| | (_) | |_| | (_| | / ____ \| | \__ \ |_ -# /_/ \_\_|\__,_|\___/ \__, |\__,_| /_/ \_\_|_|___/\__| -# __/ | -# |___/ -# -# Copyright (c) 2023 DDSRem -# -# This is free software, licensed under the GNU General Public License v3.0. -# -# —————————————————————————————————————————————————————————————————————————————————— -# -# https://github.com/duckeaty/update_xiaoya_emby_config_library - -Green="\033[32m" -Red="\033[31m" -Yellow='\033[33m' -Font="\033[0m" -INFO="[${Green}INFO${Font}]" -ERROR="[${Red}ERROR${Font}]" -WARN="[${Yellow}WARN${Font}]" -function INFO() { - echo -e "${INFO} ${1}" -} -function ERROR() { - echo -e "${ERROR} ${1}" -} -function WARN() { - echo -e "${WARN} ${1}" -} - -bash /app/module.sh update_config -bash /app/module.sh update_policy - -crontab -r -echo -e "${CRON} bash /app/module.sh update_config && bash /app/module.sh update_policy" >> /tmp/crontab.list -INFO "设置定时任务中..." -crontab /tmp/crontab.list -INFO "定时任务预览:" -crontab -l -rm -f /tmp/crontab.list - -exec crond -f \ No newline at end of file diff --git a/deprecation/emby_library/install.sh b/deprecation/emby_library/install.sh deleted file mode 100644 index 8984385..0000000 --- a/deprecation/emby_library/install.sh +++ /dev/null @@ -1,125 +0,0 @@ -function get_embyurl(){ - if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_emby_url.txt ]; then - OLD_EMBY_URL=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_emby_url.txt) - INFO "已读取小雅Emby地址:${OLD_EMBY_URL} (默认不更改回车继续,如果需要更改请输入新地址)" - read -ep "请输入: " EMBY_URL - [[ -z "${EMBY_URL}" ]] && EMBY_URL=${OLD_EMBY_URL} - echo ${EMBY_URL} > ${DDSREM_CONFIG_DIR}/xiaoya_emby_url.txt - else - INFO "请输入你的小雅Emby的内网访问地址,如:http://192.168.1.1:2345" - read -ep "请输入: " EMBY_URL - touch ${DDSREM_CONFIG_DIR}/xiaoya_emby_url.txt - echo ${EMBY_URL} > ${DDSREM_CONFIG_DIR}/xiaoya_emby_url.txt - fi -} - -function get_embyapi(){ - if [ -f ${DDSREM_CONFIG_DIR}/xiaoya_emby_api.txt ]; then - OLD_EMBY_API=$(cat ${DDSREM_CONFIG_DIR}/xiaoya_emby_api.txt) - INFO "已读取小雅Emby的API密钥:${OLD_EMBY_API} (默认不更改回车继续,如果需要更改请输入新的API密钥)" - read -ep "请输入: " EMBY_API - [[ -z "${EMBY_API}" ]] && EMBY_API=${OLD_EMBY_API} - echo ${EMBY_API} > ${DDSREM_CONFIG_DIR}/xiaoya_emby_api.txt - else - INFO "请输入小雅Emby的API密钥" - read -ep "请输入: " EMBY_API - touch ${DDSREM_CONFIG_DIR}/xiaoya_emby_api.txt - echo ${EMBY_API} > ${DDSREM_CONFIG_DIR}/xiaoya_emby_api.txt - fi -} - -function install_emby_library(){ - - get_media_dir - - get_embyapi - - get_embyurl - - INFO "请输入小雅Emby的容器名(默认 $(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt) )" - read -ep "EMBY_NAME:" EMBY_NAME - [[ -z "${EMBY_NAME}" ]] && EMBY_NAME="$(cat ${DDSREM_CONFIG_DIR}/container_name/xiaoya_emby_name.txt)" - - INFO "请输入计划时间,例:30 6 * * *,这个代表每天6点30分,注意,数字和*之前都有空格,格式一定要正确!(默认 30 6 * * * )" - read -ep "CRON:" CRON - [[ -z "${CRON}" ]] && CRON="30 6 * * *" - - INFO "是否自动删除旧Emby容器重新配置 [Y/n](默认 y)" - read -ep "REMOVE:" REMOVE - [[ -z "${REMOVE}" ]] && REMOVE="y" - if [[ ${REMOVE} == [Yy] ]]; then - docker stop ${EMBY_NAME} - docker rm ${EMBY_NAME} - if [ ! -d ${MEDIA_DIR}/config_data ]; then - mkdir -p ${MEDIA_DIR}/config_data - fi - cp -rf ${MEDIA_DIR}/config/data/* ${MEDIA_DIR}/config_data/ - MOUNT="-v ${MEDIA_DIR}/config_data:/config/data" - install_emby_xiaoya_all_emby - fi - if [[ ${REMOVE} == [Nn] ]]; then - INFO "请手动删除Emby容器,并添加一个目录映射:-v ${MEDIA_DIR}/config_data:/config/data" - read -ep "按任意键继续..." abcdefg - fi - - INFO "开始安装xiaoya-emby-library-update..." - docker run -itd \ - --name=xiaoya-emby-library-update \ - -v ${MEDIA_DIR}:/data \ - -v /var/run/docker.sock:/var/run/docker.sock:ro \ - --net=host \ - -e EMBY_NAME=${EMBY_NAME} \ - -e EMBY_API=${EMBY_API} \ - -e EMBY_URL=${EMBY_URL} \ - -e "CRON=${CRON}" \ - --restart=always \ - ddsderek/xiaoya-emby-library:latest - - INFO "安装完成!" - -} - -function uninstall_emby_library(){ - - for i in `seq -w 3 -1 0` - do - echo -en "即将开始卸载自动同步Emby数据库${Blue} $i ${Font}\r" - sleep 1; - done - docker stop xiaoya-emby-library-update - docker rm xiaoya-emby-library-update - docker ddsderek/xiaoya-emby-library:latest - INFO "卸载成功!" - -} - -function main_emby_library(){ - - echo -e "——————————————————————————————————————————————————————————————————————————————————" - echo -e "${Blue}自动同步Emby数据库${Font}\n" - echo -e "1、安装" - echo -e "2、卸载" - echo -e "3、返回上级" - echo -e "——————————————————————————————————————————————————————————————————————————————————" - read -ep "请输入数字 [1-3]:" num - case "$num" in - 1) - clear - install_emby_library - ;; - 2) - clear - uninstall_emby_library - ;; - 3) - clear - main_xiaoya_all_emby - ;; - *) - clear - ERROR '请输入正确数字 [1-3]' - main_emby_library - ;; - esac - -} \ No newline at end of file diff --git a/deprecation/emby_library/module.sh b/deprecation/emby_library/module.sh deleted file mode 100644 index 8a6fd2d..0000000 --- a/deprecation/emby_library/module.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash -# -# —————————————————————————————————————————————————————————————————————————————————— -# __ ___ _ _ _ -# \ \ / (_) /\ | (_) | | -# \ V / _ __ _ ___ _ _ __ _ / \ | |_ ___| |_ -# > < | |/ _` |/ _ \| | | |/ _` | / /\ \ | | / __| __| -# / . \| | (_| | (_) | |_| | (_| | / ____ \| | \__ \ |_ -# /_/ \_\_|\__,_|\___/ \__, |\__,_| /_/ \_\_|_|___/\__| -# __/ | -# |___/ -# -# Copyright (c) 2023 DDSRem -# -# This is free software, licensed under the GNU General Public License v3.0. -# -# —————————————————————————————————————————————————————————————————————————————————— -# -# https://github.com/duckeaty/update_xiaoya_emby_config_library - -Green="\033[32m" -Red="\033[31m" -Yellow='\033[33m' -Font="\033[0m" -INFO="[${Green}INFO${Font}]" -ERROR="[${Red}ERROR${Font}]" -WARN="[${Yellow}WARN${Font}]" -function INFO() { - echo -e "${INFO} ${1}" -} -function ERROR() { - echo -e "${ERROR} ${1}" -} -function WARN() { - echo -e "${WARN} ${1}" -} - -emby_config_data=/data/config/data -emby_config_data_new=/data/config_data - -function update_policy(){ - clear - echo -e "——————————————————————————————————————————————————————————————————————————————————" - INFO "开始获取EMBY用户信息" - echo -e "——————————————————————————————————————————————————————————————————————————————————" - USER_URL="${EMBY_URL}/Users?api_key=${EMBY_API}" - response=$(curl -s "${USER_URL}") - USER_COUNT=$(echo "${response}" | jq '. | length') - for(( i=0 ; i < $USER_COUNT ; i++ )) - do - read -r name <<< "$(echo "${response}" | jq -r ".[$i].Name")" # 使用read命令读取名字 - read -r id <<< "$(echo "${response}" | jq -r ".[$i].Id")" # 使用read命令读取ID - read -r policy <<< "$(echo "${response}" | jq -r ".[$i].Policy | to_entries | from_entries | tojson")" - USER_URL_2="${EMBY_URL}/Users/$id/Policy?api_key=${EMBY_API}" - curl -i -H "Content-Type: application/json" -X POST -d "$policy" "$USER_URL_2" - INFO "【$name】用户策略更新成功!" - echo -e "" - echo -e "——————————————————————————————————————————————————————————————————————————————————" - done - INFO "所有用户策略更新成功!" - echo -e "——————————————————————————————————————————————————————————————————————————————————" -} - -function update_config(){ - clear - echo -e "——————————————————————————————————————————————————————————————————————————————————" - INFO "小雅EMBY_CONFIG同步" - echo -e "——————————————————————————————————————————————————————————————————————————————————" - INFO "开始更新CONFIG" - docker stop ${EMBY_NAME} - if [ -f /root/xiaoya_emby_library_user.sql ]; then - rm -f /root/xiaoya_emby_library_user.sql - fi - if [ ! -d ${emby_config_data_new} ]; then - mkdir -p ${emby_config_data_new} - cp -rf ${emby_config_data}/* ${emby_config_data_new}/ - fi - if [ ! -d ${emby_config_data_new}/library_bak ]; then - mkdir -p ${emby_config_data_new}/library_bak - fi - sqlite3 ${emby_config_data_new}/library.db ".dump UserDatas" > /root/xiaoya_emby_library_user.sql - mv -f ${emby_config_data_new}/library.db* ${emby_config_data_new}/library_bak/ - cp -f ${emby_config_data}/library.db ${emby_config_data_new}/ - sqlite3 ${emby_config_data_new}/library.db "DROP TABLE IF EXISTS UserDatas;" - sqlite3 ${emby_config_data_new}/library.db ".read /root/xiaoya_emby_library_user.sql" - chmod 777 ${emby_config_data_new}/library.db* - docker start ${EMBY_NAME} - echo -e "——————————————————————————————————————————————————————————————————————————————————" - INFO "正在重启EMBY..." - SINCE_TIME=$(date +"%Y-%m-%dT%H:%M:%S") - CONTAINER_NAME=${EMBY_NAME} - TARGET_LOG_LINE_SUCCESS="All entry points have started" - TARGET_LOG_LINE_FAIL="sending all processes the KILL signal and exiting" - while true; do - line=$(docker logs --since "$SINCE_TIME" "$CONTAINER_NAME" | tail -n 1) - echo $line - if [[ "$line" == *"$TARGET_LOG_LINE_SUCCESS"* ]]; then - echo -e "——————————————————————————————————————————————————————————————————————————————————" - INFO "更新CONFIG完成" - rm -rf ${emby_config_data_new}/library_bak - break - elif [[ "$line" == *"$TARGET_LOG_LINE_FAIL"* ]]; then - echo -e "——————————————————————————————————————————————————————————————————————————————————" - ERROR "EMBY启动失败" - INFO "正在恢复数据库并重启EMBY" - docker stop ${EMBY_NAME} - rm -f ${emby_config_data_new}/library.db* - mv -f ${emby_config_data_new}/library_bak/library.db* ${emby_config_data_new}/ - rm -rf ${emby_config_data_new}/library_bak - docker start ${EMBY_NAME} - INFO "已恢复数据库" - break - fi - sleep 3 - done -} - -$1 diff --git a/deprecation/glue/Dockerfile b/deprecation/glue/Dockerfile deleted file mode 100644 index 640f310..0000000 --- a/deprecation/glue/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM xiaoyaliu/glue:latest - -COPY --chmod=755 docker_address.sh /docker_address.sh \ No newline at end of file diff --git a/deprecation/glue/docker_address.sh b/deprecation/glue/docker_address.sh deleted file mode 100644 index 4e1225a..0000000 --- a/deprecation/glue/docker_address.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -Green="\033[32m" -Red="\033[31m" -Yellow='\033[33m' -Font="\033[0m" -INFO="[${Green}INFO${Font}]" -ERROR="[${Red}ERROR${Font}]" -WARN="[${Yellow}WARN${Font}]" -function INFO() { - echo -e "${INFO} ${1}" -} -function ERROR() { - echo -e "${ERROR} ${1}" -} -function WARN() { - echo -e "${WARN} ${1}" -} - -trap 'onCtrlC' INT -function onCtrlC () { - #捕获CTRL+C,当脚本被ctrl+c的形式终止时同时终止程序的后台进程 - kill -9 ${do_sth_pid} ${progress_pid} - exit 1 -} - -do_sth() { - #运行的主程序 - fdfind --extension strm --exec sed \-i "s#http://xiaoya.host:5678#$docker_addr#g; s# #%20#g; s#|#%7C#g" {} \; - chmod -R 777 * -} - -progress() { - #进度条程序 - local main_pid=$1 - local length=50 - local ratio=1 - while [ "$(ps -p ${main_pid} | wc -l)" -ne "1" ] ; do - mark='>' - progress_bar= - for i in $(seq 1 "${length}"); do - if [ "$i" -gt "${ratio}" ] ; then - mark='-' - fi - progress_bar="${progress_bar}${mark}" - done - printf "替换DOCKER_ADDRESS: ${progress_bar}\r" - ratio=$((ratio+1)) - if [ "${ratio}" -gt "${length}" ] ; then - ratio=1 - fi - sleep 0.5 - done -} - -cd /media/xiaoya - -docker_addr=$(head -n1 /etc/xiaoya/docker_address.txt) - -for i in `seq -w 3 -1 0` -do - echo -en "${INFO} 即将开始替换地址:${docker_addr}${Blue} $i ${Font}\r" -sleep 1; -done - -INFO "执行替换DOCKER_ADDRESS " -start_time2=`date +%s` - -do_sth & -do_sth_pid=$(jobs -p | tail -1) - -progress "${do_sth_pid}" & -progress_pid=$(jobs -p | tail -1) - -wait "${do_sth_pid}" - -end_time2=`date +%s` -total_time2=$((end_time2 - start_time2)) -total_time2=$((total_time2 / 60)) -printf "${INFO} 替换执行时间:$total_time2 分钟 \n" \ No newline at end of file diff --git a/xiaoyahelper/Dockerfile b/xiaoyahelper/Dockerfile deleted file mode 100644 index 4b3257d..0000000 --- a/xiaoyahelper/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM alpine:3.21 - -ENV LANG=zh_CN.UTF-8 \ - TZ=Asia/Shanghai - -RUN apk add --no-cache \ - docker-cli \ - curl \ - tzdata \ - bash - -COPY --chmod=755 aliyun_clear.sh /etc/xiaoya/aliyun_clear.sh - -CMD ["sh", "/etc/xiaoya/aliyun_clear.sh", "5"] diff --git a/xiaoyahelper/README.md b/xiaoyahelper/README.md deleted file mode 100644 index fb46adf..0000000 --- a/xiaoyahelper/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# 一劳永逸的小雅转存清理工具 - -## 说明 - -本仓库镜像备份了xiaoyakeeper,意旨提供稳定高效的服务! - -服务状态查看:https://uptime.ddsrem.com/status/xiaoyahelper - -## 使用 - -**模式0**:每天自动清理一次。如果系统重启需要手动重新运行或把命令加入系统启动。 -```shell -bash -c "$(curl -sLk https://xiaoyahelper.ddsrem.com/aliyun_clear.sh | tail -n +2)" -s 0 -tg -``` - -**模式1**:一次性清理,一般用于测试效果。 -```shell -bash -c "$(curl -sLk https://xiaoyahelper.ddsrem.com/aliyun_clear.sh | tail -n +2)" -s 1 -tg -``` - -**模式2**:已废弃,不再支持 - -**模式3**:创建一个名为 xiaoyakeeper 的docker定时运行小雅转存清理并升级小雅镜像 -```shell -bash -c "$(curl -sLk https://xiaoyahelper.ddsrem.com/aliyun_clear.sh | tail -n +2)" -s 3 -tg -``` - -**模式4**:同模式3 - -**模式5**:与模式3的区别是实时清理,只要产生了播放缓存一分钟内立即清理。签到和定时升级同模式3 -```shell -bash -c "$(curl -sLk https://xiaoyahelper.ddsrem.com/aliyun_clear.sh | tail -n +2)" -s 5 -tg -``` - -**其它模式**:也可以把脚本下载下来自己魔改。 - -### 签到功能说明: - -1. 执行时机和清理缓存完全相同 -2. 可以手动创建`/etc/xiaoya/mycheckintoken.txt`,定义多个网盘签到的32位`refresh token`,每行一个,不添加文件就是默认小雅转存的网盘签到。 -3. 自动刷新`/etc/xiaoya/mycheckintoken.txt`、`/etc/xiaoya/mytoken.txt`(可能可以延长`refresh token`时效,待观察) - -### 关于模式0/3/4/5定时运行的说明: - -1. 默认从运行脚本的下一分钟开始,每天运行一次 -2. 运行的时间也可以通过手动创建`/etc/xiaoya/myruntime.txt`修改,比如06:00,18:00就是每天早晚6点各运行一次 - -### 关于自动升级: - -1. 定时升级的命令保存在`/etc/xiaoya/mycmd.txt`中,删除该文件变成定时重启小雅 -2. 完成清理和签到后自动执行`/etc/xiaoya/mycmd.txt`中的命令,该文件中的内容默认升级小雅镜像,可以修改该文件改编脚本的行为,不建议修改。 - -### 关于tg推送: - -所有模式加上`-tg`功能均可绑定消息推送的TG账号,只有第1次运行需要加`-tg`参数 - -**问题反馈**: 联系[Telegram群](https://t.me/xiaoyaliu00)里的heiheigui - -## 免责声明 - -- 请勿将 xiaoyahelper 用于商业用途。 -- 请勿将 xiaoyahelper 用于任何违反法律法规的行为。 -- 本仓库 xiaoyahelper 基于官方作者仓库备份,使用请自行承担数据损失但不限于此的风险。 -- 此项目 xiaoyahelper 开启`Telegram通知`时会收集用户`ChatID`,用于消息通知和数据分析,使用即代表默认同意。 -- 此项目 xiaoyahelper 所有`API`均使用阿里云官方渠道。 \ No newline at end of file diff --git a/xiaoyahelper/aliyun_clear.sh b/xiaoyahelper/aliyun_clear.sh deleted file mode 100644 index 148e1a2..0000000 --- a/xiaoyahelper/aliyun_clear.sh +++ /dev/null @@ -1,959 +0,0 @@ -#!/bin/bash - -ver="202407272055" - -upgrade_url="https://xiaoyahelper.ddsrem.com/aliyun_clear.sh" -upgrade_url_backup="http://xiaoyahelper.zngle.cf/aliyun_clear.sh" -tg_push_api_url="https://xiaoyapush.ddsrem.com" - -hash_function() { - str="$1" - hash=0 - - # DJB2 hash algorithm - i=0 - while [ "$i" -lt "${#str}" ]; do - char=$(printf "%s" "$str" | cut -c "$((i + 1))") - char_value=$(printf "%d" "'$char") - hash=$(((hash * 33) ^ char_value)) - hash=$((hash & 0xFFFFFF)) - i=$((i + 1)) - done - - hash=$((hash & 0xFFFFFF)) # 4-byte integer (32-bit) - echo "$hash" -} - -# Function to convert a 4-byte integer to IP address -int_to_ip() { - ip="" - for i in 0 1 2 3; do - octet=$((($1 >> (8 * (3 - i))) & 0xFF)) - if [ -z "$ip" ]; then - ip="$octet" - else - ip="$ip.$octet" - fi - done - echo "$ip" -} - -# Function to hash a string and convert it to IP address -hash_to_ip() { - input_string="$1" - hashed_value=$(hash_function "$input_string") - hashed_ip=$(int_to_ip "$hashed_value") - echo "$hashed_ip" | sed 's/^0\./1\./g' -} - -fast_triger_update() { - if [ ! -f /docker-entrypoint.sh ]; then - return 0 - fi - - if [ ! $(($(date +%-M) % 5)) -eq 0 ]; then - return 0 - fi - - if [ "$sche" -eq 0 ]; then - local_ip_ver="$(hash_to_ip "$ver")" - remote_ip_ver="$(ping -c 1 -W 1 xiaoyakeeper.u.1996999.xyz 2>&1 | grep -Eo "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | head -n1 | grep "^1\.")" - if [ -z "$remote_ip_ver" ]; then - return 0 - fi - - if [ "$local_ip_ver"x = "$remote_ip_ver"x ]; then - return 0 - fi - fi - - newsh=$(curl --connect-timeout 5 -m 5 -k -s "$upgrade_url" 2>/dev/null) - if [ -z "$(echo "$newsh" | grep "^#!/bin/bash")" ]; then - newsh=$(curl --connect-timeout 5 -m 5 -k -s "$upgrade_url_backup" 2>/dev/null) - fi - latest_ver=$(echo "$newsh" | grep "^ver=" | tr -d '"ver=') - if [ "$latest_ver"x = x ] || [ "$ver"x = "$latest_ver"x ]; then - return 0 - fi - - myecho "检测到新版本$latest_ver,即将自动重启容器升级,重启前会补做一次签到和清理" - - clear_aliyun_all_docker_pre_update - sleep 60 - #docker restart xiaoyakeeper - exit 0 -} - -g_p=$@ -para() { - i=$(echo ~$1 | tr -d '~' | tr '-' '~') - if [ "$(echo ~$g_p | tr -d '~' | tr '-' '~' | grep -Eo "$i")"x = x ]; then - return 1 - fi - return 0 -} - -retry_command() { - # 重试次数和最大重试次数 - retries=0 - max_retries=10 - local cmd="$1" - local success=false - local output="" - - while ! $success && [ $retries -lt $max_retries ]; do - output=$(eval "$cmd" 2>&1) - if [ $? -eq 0 ]; then - success=true - else - retries=$(($retries + 1)) - echo "#Failed to execute command \"$(echo "$cmd" | awk '{print $1}')\", retrying in 1 seconds (retry $retries of $max_retries)..." >&2 - sleep 1 - fi - done - - if $success; then - echo "$output" - return 0 - else - echo "#Failed to execute command after $max_retries retries: $cmd" >&2 - echo "#Command output: $output" >&2 - return 1 - fi -} - -#检查脚本更新 -if which curl &>/dev/null; then - newsh=$(retry_command "curl --connect-timeout 5 -m 5 -k -s \"$upgrade_url\" 2>/dev/null") - if [ -z "$(echo "$newsh" | grep "^#!/bin/bash")" ]; then - newsh=$(retry_command "curl --connect-timeout 5 -m 5 -k -s \"$upgrade_url_backup\" 2>/dev/null") - fi -fi -latest_ver=$(echo "$newsh" | grep "^ver=" | tr -d '"ver=') -if [ ! "$latest_ver"x = x ] && [ ! "$ver"x = "$latest_ver"x ]; then - filename=${0} - dir=$(dirname "$filename") - if [ "$dir"x = x ]; then - filename="./$filename" - fi - if [ ! "$(echo "$dir" | awk -F/ '{print $1}')"x = x ]; then - filename="./$filename" - fi - - shell_cmd="sh" - which "bash" >/dev/null - if [ $? -eq 0 ]; then - shell_cmd="bash" - fi - - if [ -n "$(cat "$filename" | head -n 1 | grep "^#!/bin/bash")" ]; then - echo "$newsh" >"$filename" - chmod +x "$filename" - echo "脚本已自动更新到最新版本$latest_ver" - $shell_cmd $filename "$@" - exit 0 - fi -fi - -get_Header() { - response=$(curl --connect-timeout 5 -m 5 -s -H "Content-Type: application/json" \ - -d '{"grant_type":"refresh_token", "refresh_token":"'$refresh_token'"}' \ - https://api.aliyundrive.com/v2/account/token) - - access_token=$(echo "$response" | sed -n 's/.*"access_token":"\([^"]*\).*/\1/p') - - HEADER="Authorization: Bearer $access_token" - if [ -z "$HEADER" ]; then - echo "获取access token失败" >&2 - return 1 - fi - - response="$(curl --connect-timeout 5 -m 5 -s -H "$HEADER" -H "Content-Type: application/json" -X POST -d '{}' "https://user.aliyundrive.com/v2/user/get")" - - lagacy_drive_id=$(echo "$response" | sed -n 's/.*"default_drive_id":"\([^"]*\).*/\1/p') - - drive_id=$(echo "$response" | sed -n 's/.*"resource_drive_id":"\([^"]*\).*/\1/p') - - if [ -z "$drive_id" ]; then - drive_id=$lagacy_drive_id - fi - - if [ "$folder_type"x = "b"x ]; then - drive_id=$lagacy_drive_id - fi - - if [ -z "$drive_id" ]; then - echo "获取drive_id失败" >&2 - return 1 - fi - - echo "HEADER=\"$HEADER\"" - echo "drive_id=\"$drive_id\"" - return 0 -} - -get_rawList() { - waittime=10 - if [ -n "$1" ]; then - waittime="$1" - fi - _res=$(curl --connect-timeout 5 -m 5 -s -H "$HEADER" -H "Content-Type: application/json" -X POST -d '{"drive_id": "'$drive_id'","parent_file_id": "'$file_id'"}' "https://api.aliyundrive.com/adrive/v2/file/list") - if [ ! $? -eq 0 ] || [ -z "$(echo "$_res" | grep "items")" ]; then - echo "获取文件列表失败:folder_id=$file_id,drive_id=$drive_id" >&2 - return 1 - fi - echo "$_res" - #简单规避小雅转存后还没来得及获取直链就被删除的问题,降低发生概率 - sleep "$waittime" - return 0 -} - -get_List() { - _res=$raw_list - - #echo "$_res" | tr '{' '\n' | grep -v "folder" | grep -o "\"file_id\":\"[^\"]*\"" | cut -d':' -f2- | tr -d '"' - echo "$_res" | tr '{' '\n' | grep -o "\"file_id\":\"[^\"]*\"" | cut -d':' -f2- | tr -d '"' - return 0 -} - -get_Path() { - _path="$(curl --connect-timeout 5 -m 5 -s -H "$HEADER" -H "Content-Type: application/json" -X POST -d "{\"drive_id\": \"$drive_id\", \"file_id\": \"$file_id\"}" "https://api.aliyundrive.com/adrive/v1/file/get_path" | grep -o "\"name\":\"[^\"]*\"" | cut -d':' -f2- | tr -d '"' | tr '\n' '/' | awk -F'/' '{for(i=NF-1;i>0;i--){printf("/%s",$i)}; printf("%s\n",$NF)}')" - if [ -z "$_path" ]; then - return 1 - fi - echo "$_path" - return 0 -} - -delete_File() { - _file_id=$1 - _name="$(echo "$raw_list" | grep -o "\"name\":\"[^\"]*\"" | cut -d':' -f2- | tr -d '"' | grep -n . | grep "^$(echo "$raw_list" | grep -o "\"file_id\":\"[^\"]*\"" | cut -d':' -f2- | tr -d '"' | grep -n . | grep "$_file_id" | awk -F: '{print $1}'):" | awk -F: '{print $2}')" - - _res=$(curl --connect-timeout 5 -m 5 -s -H "$HEADER" -H "Content-Type: application/json" -X POST -d '{ - "requests": [ - { - "body": { - "drive_id": "'$drive_id'", - "file_id": "'$_file_id'" - }, - "headers": { - "Content-Type": "application/json" - }, - "id": "'$_file_id'", - "method": "POST", - "url": "/file/delete" - } - ], - "resource": "file" -}' "https://api.aliyundrive.com/v3/batch" | grep "\"status\":204") - if [ -z "$_res" ]; then - return 1 - fi - - drive_root="资源盘" - if [ "$folder_type"x = "b"x ]; then - drive_root="备份盘" - fi - - myecho "彻底删除文件:/$drive_root$path/$_name" - - return 0 -} - -get_docker_info() { - if [ "$1"x != x ]; then - get_docker_info | awk '"'$1'"==$1' - return - fi - images=$(docker images --no-trunc) - for line in $(docker ps | tail -n +2 | grep -v "xiaoyakeeper" | awk '{print $NF}'); do - id=$(docker inspect --format='{{.Image}}' $line | awk -F: '{print $2}') - echo "$line $(echo "$images" | grep $id | head -n 1)" | tr ':' ' ' | awk '{printf("%s %s %s\n",$1,$2,$5)}' - done -} - -get_Xiaoya() { - get_docker_info | grep "xiaoyaliu/alist\|haroldli/xiaoya-tvbox\|ailg/alist" | awk '{print $1}' -} - -# 签到是抄小雅的 -get_json_value() { - local json=$1 - local key=$2 - - if [[ -z "$3" ]]; then - local num=1 - else - local num=$3 - fi - - local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p) - echo ${value} -} - -get_Reward() { - _res=$(curl --connect-timeout 5 -m 5 -s -H "$HEADER" -H "Content-Type: application/json" -X POST -d '{"signInDay": '$day'}' "https://member.aliyundrive.com/v1/activity/sign_in_reward?_rx-s=mobile" | grep "success") - if [ -z "$_res" ]; then - reurn 1 - fi - _name=$(get_json_value "$_res" "name") - _dsc=$(get_json_value "$_res" "description") - echo "$_name-$_dsc" | tr -d ' ' - return 0 -} - -checkin() { - local _refresh_token=$1 - local _token=$(curl --connect-timeout 5 -m 5 -s -X POST -H "Content-Type: application/json" -d '{"grant_type": "refresh_token", "refresh_token": "'"$_refresh_token"'"}' https://auth.aliyundrive.com/v2/account/token) - local _access_token=$(get_json_value $_token "access_token") - - nick_name=$(get_json_value $_token "nick_name") - - if [ -z "$nick_name" ]; then - nick_name="阿里云盘" - fi - - _output="\n[$(date '+%Y/%m/%d %H:%M:%S')][$nick_name]的签到信息" - - HEADER="Authorization:Bearer $_access_token" - - local _sign=$(curl --connect-timeout 5 -m 5 -s -X POST -H "Content-Type: application/json" -H "$HEADER" -d '{"grant_type": "refresh_token", "refresh_token": "'"$_refresh_token"'"}' https://member.aliyundrive.com/v1/activity/sign_in_list) - - local _fmt_sign=$(echo "$_sign" | tr -d '\n' | sed 's/{"day"/\n{"day"/g' | tr -d ' ') - - local _days=$(echo "$_fmt_sign" | grep '"status":"normal"' | grep '"isReward":false' | grep -Eo '"day":[0-9]{1,2}' | awk -F: '{print $2}' | sed '/^$/d') - - _today_cards="" - for day in $_days; do - _today_cards="$_today_cards\n$(retry_command "get_Reward" | grep "-")" - done - - raw_cards=$(echo -e "$_today_cards" | tr -d ' ') - _card="" - for card in $(echo -e "$raw_cards" | sort | uniq | grep -v null); do - _card="$(echo "$_card\n--$card:$(echo -e "$raw_cards" | grep "$card" | wc -l)张")" - done - - if [ -n "$(echo -e "$_today_cards" | tr -d ' ' | sed '/^$/d')" ]; then - _output="$_output\n$(echo -e "今日获得奖励:\n$_card" | sed '/^$/d')" - fi - - _cards=$_today_cards - for day in $(echo "$_fmt_sign" | grep -v '"status":"miss"' | grep -Eo '"day":[0-9]{1,2}'); do - day_sign=$(echo "$_fmt_sign" | grep "$day") - _cards="$_cards\n""$(get_json_value "$day_sign" "name")"-"$(get_json_value "$day_sign" "description")" - done - - raw_cards=$(echo -e "$_cards" | tr -d ' ') - _card="" - for card in $(echo -e "$raw_cards" | sort | uniq | grep -v null); do - _card="$(echo "$_card\n--$card:$(echo -e "$raw_cards" | grep "$card" | wc -l)张")" - done - - local _signInCount=$(get_json_value "$_sign" "signInCount") - - local _success=$(echo $_sign | cut -f1 -d, | cut -f2 -d:) - if [ "$_success"x = "true"x ]; then - _output="$_output\n$(echo -e "本月累计签到$_signInCount天,获得奖励:\n$_card" | sed '/^$/d')" - myecho -e "$_output" - return 0 - else - echo "阿里签到失败" - return 1 - fi -} - -aliyun_update_checkin_single() { - tokens="$(retry_command "read_File $1")" - echo "$tokens" | sed '/^$/d' | while read token; do - retry_command "checkin $token" - response=$(curl --connect-timeout 5 -m 5 -s -H "Content-Type: application/json" \ - -d '{"grant_type":"refresh_token", "refresh_token":"'$token'"}' \ - https://api.aliyundrive.com/v2/account/token) - new_refresh_token=$(echo "$response" | sed -n 's/.*"refresh_token":"\([^"]*\).*/\1/p') - if [ -n "$new_refresh_token" ]; then - docker exec "$XIAOYA_NAME" sed -i 's/'"$token"'/'"$new_refresh_token"'/g' "/data/$1" - fi - done -} - -aliyun_update_checkin() { - aliyun_update_checkin_single "mycheckintoken.txt" - aliyun_update_checkin_single "mytoken.txt" -} - -_clear_aliyun() { - #eval "$(retry_command "get_Header")" - raw_list=$(retry_command "get_rawList") - path=$(retry_command "get_Path") - _list="$(get_List)" - echo "$_list" | sed '/^$/d' | while read line; do - retry_command "delete_File \"$line\"" - done - return "$(echo "$_list" | sed '/^$/d' | wc -l)" -} - -clear_aliyun() { - eval "$(retry_command "get_Header")" - raw_list=$(retry_command "get_rawList 0") - _list="$(get_List)" - if [ -z "$(echo "$_list" | sed '/^$/d')" ]; then - return 0 - fi - - myecho -e "\n[$(date '+%Y/%m/%d %H:%M:%S')]开始清理小雅$XIAOYA_NAME转存" - - _res=1 - _filenum=0 - while [ ! $_res -eq 0 ]; do - _clear_aliyun - _res=$? - _filenum=$(($_filenum + $_res)) - done - - myecho "本次共清理小雅$XIAOYA_NAME转存文件$_filenum个" - -} - -get_PostCmd() { - pos=$(read_File mycmd.txt | grep -n "#xiaoyakeeper-$XIAOYA_NAME-begin\|#xiaoyakeeper-$XIAOYA_NAME-end" | awk -F: '{print $1}') - if [ "$(echo "$pos" | wc -l)" -lt 2 ]; then - return - fi - pos="$(echo "$pos" | tr '\n' ':')" - begin="$(echo "$pos" | awk -F: '{print $1}')" - end="$(echo "$pos" | awk -F: '{print $2}')" - read_File mycmd.txt | head -n "$end" | tail -n +"$begin" -} - -init_para() { - XIAOYA_NAME="$1" - refresh_token="$(retry_command "read_File mytoken.txt" | head -n1)" - - post_cmd="$(get_PostCmd)" - #if [ -z "$post_cmd" ];then - #post_cmd='docker restart "'$XIAOYA_NAME'" >/dev/null 2>&1' - #fi - - file_id=$(retry_command "read_File temp_transfer_folder_id.txt") - - folder_type=$(read_File "folder_type.txt") - - _file_time="$(retry_command "read_File myruntime.txt" | grep -Eo "[0-9]{2}:[0-9]{2}" | tr '\n' ' ')" - - chat_id="$(retry_command "read_File mychatid.txt")" - echo " chat_id:$chat_id " >&6 - - run_time="$script_run_time" - if [ -n "$_file_time" ]; then - run_time="$_file_time" - fi - -} - -clear_aliyun_realtime() { - xiaoya_name="$(echo "$XIAOYA_NAME" | tr '-' '_')" - #eval "_file_count_new_$xiaoya_name=$(docker logs $XIAOYA_NAME 2>&1 | grep https | grep security-token | wc -l)" - eval "_file_count_new_$xiaoya_name=$(docker logs $XIAOYA_NAME 2>&1 | wc -l)" - eval "_file_count_new=\"\$_file_count_new_$xiaoya_name\"" - eval "_file_count_old=\"\$_file_count_old_$xiaoya_name\"" - if [ "$_file_count_new"x != "$_file_count_old"x ]; then - clear_aliyun - fi - eval "_file_count_old_$xiaoya_name=\"\$_file_count_new_$xiaoya_name\"" -} - -clear_aliyun_single_docker() { - init_para "$1" - copy_tvbox_files - case "$run_mode" in - 0) - for time in $(echo "$run_time" | tr ',' ' '); do - if [ "$current_time" = "$time" ]; then - clear_aliyun - aliyun_update_checkin - eval "$post_cmd" - sche=1 - fi - done - ;; - 55) - clear_aliyun_realtime - for time in $(echo "$run_time" | tr ',' ' '); do - if [ "$current_time" = "$time" ]; then - clear_aliyun - aliyun_update_checkin - eval "$post_cmd" - sche=1 - fi - done - ;; - 1) - clear_aliyun - aliyun_update_checkin - ;; - *) - return 1 - ;; - esac -} - -clear_aliyun_all_docker_pre_update() { - org_run_mode=$run_mode - run_mode=1 - for line in $(echo -e "$dockers" | sed '/^$/d'); do - clear_aliyun_single_docker "$line" - done - run_mode=$org_run_mode -} - -clear_aliyun_all_docker() { - dockers="$(get_Xiaoya)" - current_time="$(date +%H:%M)" - for line in $(echo -e "$dockers" | sed '/^$/d'); do - clear_aliyun_single_docker "$line" - done -} - -copy_tvbox_files() { - docker exec "$XIAOYA_NAME" bash -c 'copy_tvbox_files() { - source_dir="/data" - target_dir1="/www/tvbox" - target_dir2="/www/tvbox/json" - target_dir3="/www/tvbox/libs" - target_dir4="/www/tvbox/cat" - target_dir5="/www/tvbox/cat/libs" - target_dir6="/www/tvbox/cat/lib" - - mkdir -p "$target_dir1" - mkdir -p "$target_dir2" - mkdir -p "$target_dir3" - mkdir -p "$target_dir4" - mkdir -p "$target_dir5" - mkdir -p "$target_dir6" - ali_tiken="$(cat /data/mytoken.txt)" - - copy_files_by_extension() { - local ext=$1 - local target_dir=$2 - - shopt -s nullglob - local files=("$source_dir"/*."$ext") - - for file in "${files[@]}"; do - file_name=$(basename "$file") - target_file="$target_dir/$file_name" - src_content="$(cat "$file" | sed "s/ALI_SHORT_TOKEN/$ali_tiken/g")" - if [ -f "$target_file" ]; then - dst_content="$(cat "$target_file")" - if [ "$src_content"x != "$dst_content"x ]; then - echo "$src_content" > "$target_file" - else - : - fi - else - echo "$src_content" > "$target_file" - fi - done - } - - recursive_copy() { - local source="$1" - local destination="$2" - mkdir -p "$destination" - - for item in "$source"/*; do - local filename=$(basename "$item") - local dest_path="$destination/$filename" - - if [ -d "$item" ]; then - if [ ! -d "$dest_path" ]; then - mkdir "$dest_path" - fi - recursive_copy "$item" "$dest_path" - elif [ -f "$item" ]; then - src_content="$(cat "$item" | sed "s/ALI_SHORT_TOKEN/$ali_tiken/g")" - if [ -f "$dest_path" ]; then - dst_content="$(cat "$dest_path")" - if [ "$src_content"x != "$dst_content"x ]; then - echo "$src_content" > "$dest_path" - else - : - fi - else - echo "$src_content" > "$dest_path" - fi - fi - done -} - - recursive_copy "/data/tvbox" "/www/tvbox" - copy_files_by_extension "json" "$target_dir1" - copy_files_by_extension "json" "$target_dir2" - copy_files_by_extension "js" "$target_dir3" - copy_files_by_extension "json" "$target_dir4" - copy_files_by_extension "js" "$target_dir4" - copy_files_by_extension "js" "$target_dir5" - copy_files_by_extension "js" "$target_dir6" -} - -copy_tvbox_files' -} - -docker_pull() { - repo_tag="$1" - mirrors="$(curl --insecure -fsSL https://ddsrem.com/xiaoya/all_in_one.sh | awk '/mirrors=\(/,/\)/' | sed -n 's/^[[:space:]]*"\(.*\)"[[:space:]]*$/\1/p' | grep -v "docker\.io")" - mirrors="$( - for line in $mirrors; do - curl -s -o /dev/null -m 4 -w '%{time_total} '$line'\n' --head --request GET "$line" & - done - wait - )" - mirrors="$(echo "$mirrors" | sort -n | awk '{print $2}')" - repo="$(echo "$repo_tag" | awk -F: '{print $1}')" - tag="$(echo "$repo_tag" | awk -F: '{print $2}')" - old_image_id="$(docker images | grep "$repo" | grep "$tag" | grep -Eo "[0-9a-f]{6,128}")" - for mirror in $mirrors; do - echo "尝试使用镜像源拉取:$mirror/$repo_tag" - docker tag "$repo_tag" "$mirror/$para_i" > /dev/null 2>&1 - docker rmi "$repo_tag" > /dev/null 2>&1 - docker pull "$mirror/$repo_tag" - res=$? - docker tag "$mirror/$repo_tag" "$repo_tag" > /dev/null 2>&1 - docker rmi "$mirror/$repo_tag" > /dev/null 2>&1 - if [ $res -eq 0 ]; then - break - fi - done - new_image_id="$(docker images | grep "$repo" | grep "$tag" | grep -Eo "[0-9a-f]{6,128}")" - if [ "$new_image_id"x != "$old_image_id"x ];then - docker tag "$old_image_id" "$repo:none" > /dev/null 2>&1 - fi -} - -update_xiaoya() { - sleep 60 - para_v="$(docker inspect --format='{{range $v,$conf := .Mounts}}-v {{$conf.Source}}:{{$conf.Destination}} {{$conf.Type}}~{{end}}' $XIAOYA_NAME | tr '~' '\n' | grep bind | sed 's/bind//g' | grep -Eo "\-v .*:.*" | tr '\n' ' ')" - para_n="$(docker inspect --format='{{range $m, $conf := .NetworkSettings.Networks}}--network={{$m}}{{end}}' $XIAOYA_NAME | grep -Eo "\-\-network=host")" - tag="latest" - if [ "$(get_docker_info $XIAOYA_NAME | grep "ailg/alist")"x != x ]; then - tag="test" - fi - if [ "$para_n"x != x ]; then - tag="hostmode" - fi - para_p="$(docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}~{{$p}}{{$conf}} {{end}}' $XIAOYA_NAME | tr '~' '\n' | tr '/' ' ' | tr -d '[]{}' | awk '{printf("-p %s:%s\n",$3,$1)}' | grep -Eo "\-p [0-9]{1,10}:[0-9]{1,10}" | tr '\n' ' ')" - para_i="$(get_docker_info $XIAOYA_NAME | awk '{print $2}'):$tag" - para_e="$(docker inspect --format='{{range $p, $conf := .Config.Env}}~{{$conf}}{{end}}' $XIAOYA_NAME 2>/dev/null | sed '/^$/d' | tr '~' '\n' | sed '/^$/d' | awk '{printf("-e \"%s\"\n",$0)}' | tr '\n' ' ')" - #docker pull "$para_i" 2>&1 - docker_pull "$para_i" - cur_image=$(get_docker_info $XIAOYA_NAME | awk '{print $3}') - latest_image=$(docker images --no-trunc | tail -n +2 | tr ':' ' ' | awk '{printf("%s:%s %s\n",$1,$2,$4)}' | grep "$para_i" | awk '{print $2}') - - if [ "$cur_image"x != "$latest_image"x ]; then - docker stop "$XIAOYA_NAME" - docker rm -v "$XIAOYA_NAME" - eval "$(echo docker run -d "$para_n" "$para_v" "$para_p" "$para_e" --restart=always --name="$XIAOYA_NAME" "$para_i")" - else - docker restart "$XIAOYA_NAME" - fi - - docker rmi -f $(docker images | grep "$(echo $para_i | awk -F: '{print $1}')" | grep none | grep -Eo "[0-9a-f]{6,128}") >/dev/null 2>&1 -} - -session="$((RANDOM % 90000000 + 10000000))" -gen_post_cmd_single() { - init_para "$1" - if [ "$cmd_delay" -eq 0 ]; then - cmd='#tag:'$session',命令只能写在以下begin和end之间,否则不会被执行 -#xiaoyakeeper-'$XIAOYA_NAME'-begin -#update_xiaoya是一个内置命令,如果小雅镜像有更新则更新小雅容器,否则重启小雅容器。可以替换成你自己的命令,如果不懂则不建议修改。 -update_xiaoya -#xiaoyakeeper-'$XIAOYA_NAME'-end -' - else - cmd='#tag:'$session',命令只能写在以下begin和end之间,否则不会被执行 -#xiaoyakeeper-'$XIAOYA_NAME'-begin -{ -sleep '$cmd_delay' -#update_xiaoya是一个内置命令,如果小雅镜像有更新则更新小雅容器,否则重启小雅容器。可以替换成你自己的命令,如果不懂则不建议修改。 -update_xiaoya -}& -#xiaoyakeeper-'$XIAOYA_NAME'-end -' - fi - write_File_ClearIfNoTag mycmd.txt "$cmd" "#tag:$session" - #write_File mycmd.txt "$cmd" -} - -gen_post_cmd_all() { - if [ -f /docker-entrypoint.sh ]; then - return 0 - fi - dockers="$(get_Xiaoya)" - cmd_delay=0 - for line in $(echo -e "$dockers" | sed '/^$/d'); do - gen_post_cmd_single "$line" - cmd_delay=$((cmd_delay + 600)) - done -} - -install_env() { - if [ ! -f /docker-entrypoint.sh ]; then - return 0 - fi - - #http://mirrors.ustc.edu.cn/alpine/v3.18/main - #http://mirrors.ustc.edu.cn/alpine/v3.18/community - #echo 'https://mirrors.nju.edu.cn/alpine/v3.18/main - #https://mirrors.nju.edu.cn/alpine/v3.18/community' > /etc/apk/repositories - - if ! docker --help &>/dev/null; then - apk add docker-cli - fi - - if ! docker --help &>/dev/null; then - echo "安装docker工具失败" - return 1 - fi - - if ! curl --help &>/dev/null; then - apk add curl - fi - - if ! curl --help &>/dev/null; then - echo "安装curl工具失败" - return 1 - fi - - if [ -z "$(date | grep "CST")" ]; then - apk add tzdata - cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime - echo "Asia/Shanghai" >/etc/timezone - fi -} - -install_keeper() { - #docker image prune -af - #docker volume prune -f - #docker volume prune -af 2>/dev/null - dockers="$(get_Xiaoya)" - XIAOYA_NAME="$(echo -e "$dockers" | sed '/^$/d' | head -n1)" - #XIAOYA_ROOT="$(docker inspect --format='{{range $v,$conf := .Mounts}}{{$conf.Source}}:{{$conf.Destination}}{{$conf.Type}}~{{end}}' "$XIAOYA_NAME" | tr '~' '\n' | grep bind | sed 's/bind//g' | grep ":/data" | awk -F: '{print $1}')" - - #小雅文件夹有可能没权限,换一个目录作为临时目录 - #XIAOYA_ROOT="/var/run" - - if [ -z "$newsh" ] && [ -n "$(cat "$0" | head -n 1 | grep "^#!/bin/bash")" ]; then - newsh="$(cat "$0")" - fi - - if [ -z "$newsh" ]; then - echo "网络问题,下载脚本失败,请多尝试几次、科学上网安装或下载TG群文件中的aliyun_clear.sh离线安装:bash ./aliyun_clear.sh 5,其中参数“5”是指模式5,可以改为其它模式" - return 0 - fi - - #echo "$newsh" > "$XIAOYA_ROOT/aliyun_clear.sh" - docker rm -f -v xiaoyakeeper >/dev/null 2>&1 - network="--network=host" - if para -b; then - network="" - fi - docker_pull "ddsderek/xiaoyakeeper:latest" - docker run --name xiaoyakeeper --restart=always $network --privileged -v /var/run/docker.sock:/var/run/docker.sock -e TZ="Asia/Shanghai" -d ddsderek/xiaoyakeeper:latest sh -c "if [ -f /etc/xiaoya/aliyun_clear.sh ];then sh /etc/xiaoya/aliyun_clear.sh $1;else sleep 60;fi" - docker exec xiaoyakeeper touch /docker-entrypoint.sh - docker exec xiaoyakeeper sh -c "mkdir /etc/xiaoya > /dev/null 2>&1" - #docker cp $XIAOYA_ROOT/aliyun_clear.sh xiaoyakeeper:/etc/xiaoya/aliyun_clear.sh - echo "$newsh" | docker exec -i xiaoyakeeper sh -c 'cp /dev/stdin /etc/xiaoya/aliyun_clear.sh' - - docker exec xiaoyakeeper chmod +x "/etc/xiaoya/aliyun_clear.sh" - #rm -f "$XIAOYA_ROOT/aliyun_clear.sh" - docker restart xiaoyakeeper - - if [ -z "$(docker ps | grep xiaoyakeeper)" ]; then - echo "启动失败,请把命令报错信息以及以下信息反馈给作者修改" - echo "系统信息:$(uname -a)" - echo "docker路径:$(which docker)" - echo "docker状态:$(docker ps | grep xiaoyakeeper)" - echo "docker运行日志:" - echo "$(docker logs --tail 10 xiaoyakeeper)" - else - echo "小雅看护docker(xiaoyakeeper)已启动" - fi -} - -read_File() { - _r=0 - _res="" - if docker exec "$XIAOYA_NAME" [ -f "/data/$1" ]; then - _res="$(docker exec "$XIAOYA_NAME" cat "/data/$1")" - _r=$? - fi - echo "$_res" - return $_r -} - -write_File() { - docker exec "$XIAOYA_NAME" bash -c "echo -e \"$2\" > \"/data/$1\"" - return $? -} - -apend_File() { - docker exec "$XIAOYA_NAME" bash -c "echo -e \"$2\" >> \"/data/$1\"" - return $? -} - -write_File_ClearIfNoTag() { - if [ -z "$(read_File "$1" | grep "$3")" ]; then - write_File "$1" "" - fi - apend_File "$1" "$2" -} - -if ! install_env; then - echo "小雅守护初始化失败,即将重试10次" - retry_command "install_env" - if ! install_env; then - echo "重试10次后初始化失败,可能遇到了网络问题,1小时后将重启容器继续重试" - sleep 3600 - exit 0 - fi -fi - -run_mode=0 -next_min=$(($(date +%s) + 60)) -script_run_time="$(date -d "@$next_min" +'%H:%M')" - -if [ -n "$1" ]; then - run_mode="$1" -fi - -if [ ! -f /docker-entrypoint.sh ]; then - touch /var/run/xiaoyakeeper.pid - kill -9 "$(cat /var/run/xiaoyakeeper.pid)" &>/dev/null - echo $$ >/var/run/xiaoyakeeper.pid -fi - -dockers="$(get_Xiaoya)" -if [ -z "$(echo -e "$dockers" | sed '/^$/d' | head -n1)" ]; then - echo "你还没有安装小雅docker,请先安装!" - exit 0 -fi - -get_ChatId() { - code="$((RANDOM % 90000000 + 10000000))" - echo "请先发送验证码$code给机器人@xiaoyahelper_bot,发送成功后请敲回车键继续,不发验证码直接敲回车表示用上次验证的账号推送,如果从来没有验证过则不推送。请2分钟内完成,超时自动跳过。" - sleep 2 - read -t 120 line - chat_id="$(curl --connect-timeout 5 -m 5 -H "User-Agent: xiaoyapush" $tg_push_api_url/getUpdates -d "$code" 2>/dev/null | sed 's/{"message_id"/\n{"message_id"/g' | grep "$code" | grep -Eo '"id":[0-9]{1,20}' | tail -n 1 | tr -d '"' | awk -F: '{print $2}')" - if [ -z "$chat_id" ]; then - return 0 - fi - - dockers="$(get_Xiaoya)" - echo -e "$dockers" | sed '/^$/d' | while read line; do - org_chat_id=$chat_id - init_para "$line" - chat_id=$org_chat_id - write_File "mychatid.txt" "$org_chat_id" - done -} - -myecho() { - echo "$@" - echo "$@" >&6 -} - -push_msg() { - _chat_id="$(echo "$@" | grep -Eo "chat_id:[0-9]{1,20}" | awk -F: '{print $2}' | tail -n 1)" - if [ -n "$_chat_id" ]; then - chat_id=$_chat_id - fi - text="$(echo "$@" | grep -v 'chat_id:')" - if [ -n "$chat_id" ] && [ -n "$text" ]; then - curl --connect-timeout 5 -m 5 -s -X POST -H "User-Agent: xiaoyapush;ver=$ver" -H 'Content-Type: application/json' -d '{"chat_id": '$chat_id',"text": "'"$text"'"}' "$tg_push_api_url/sendMessage" &>/dev/null - fi -} - -tmp_fifofile="./$$.fifo" -mkfifo $tmp_fifofile &>/dev/null -if [ ! $? -eq 0 ]; then - mknod $tmp_fifofile p -fi -exec 6<>$tmp_fifofile -rm -f $tmp_fifofile - -if para -tg; then - get_ChatId -fi - -start_push_proc() { - { - msg="" - while [ -n "$(ps | sed "s/^/ /" | grep " $$ " | grep -v grep)" ]; do - if read -t 20 -u 6 line; then - msg="$msg\n$line" - else - if [ -n "$(echo -e "$msg" | tail -n +2)" ]; then - push_msg "$(echo -e "$msg" | tail -n +2)" - fi - msg="" - fi - sleep 1 - done - } & -} - -push_proc_keeper() { - if ! which pgrep &>/dev/null; then - return - fi - count=$(pgrep -P $$ -l | grep -v sleep | grep -v grep | wc -l) - if [ $count -gt 1 ]; then - return - fi - start_push_proc -} - -if [ ! -f /docker-entrypoint.sh ]; then - if [ "$run_mode" -eq 0 ] || [ "$run_mode" -eq 1 ]; then - echo "你正在使用不推荐的模式$run_mode,建议使用模式3或模式5" - fi -fi - -start_push_proc -case "$run_mode" in -0 | 55) - myecho -e "\n[$(date '+%Y/%m/%d %H:%M:%S')]小雅缓存清理(ver=$ver)运行中" - while :; do - sche=0 - push_proc_keeper - clear_aliyun_all_docker - fast_triger_update - sleep $((60 - $(date +%s) % 60)) - done - ;; -1) - clear_aliyun_all_docker - if [ -n "$chat_id" ]; then - echo "等待完成消息推送中,马上结束运行" - sleep 30 - fi - ;; -2) - echo "本模式已不再支持,建议使用模式3或模式4" - ;; -3 | 4) - gen_post_cmd_all - install_keeper 0 - ;; -5) - gen_post_cmd_all - install_keeper 55 - ;; -*) - echo "不支持的模式" - ;; -esac - -exec 6>&- >/dev/null 2>&1