From 244f58eccecc3024c1ac3e9460d5169f2bcff1d7 Mon Sep 17 00:00:00 2001 From: shenmo <jifengshenmo@outlook.com> Date: Thu, 13 Mar 2025 12:59:26 +0800 Subject: [PATCH] AUTO_USE_ACE --- tool/ssaudit | 131 +++++++++++++++++++++++++++++++++++++++++-------- tool/ssinstall | 72 ++++++++++++++++++++++++--- 2 files changed, 176 insertions(+), 27 deletions(-) diff --git a/tool/ssaudit b/tool/ssaudit index 711fd4e..06897c9 100755 --- a/tool/ssaudit +++ b/tool/ssaudit @@ -4,6 +4,7 @@ source /opt/durapps/spark-store/bin/bashimport/transhell.amber load_transhell_debug export DEBIAN_FRONTEND=noninteractive +trap 'unlock_file $DEBPATH' EXIT case $(arch) in x86_64) STORE_URL="store" @@ -11,9 +12,13 @@ case $(arch) in aarch64) STORE_URL="aarch64-store" ;; + loongarch64) + STORE_URL="loong64-store" + STORE_LIST_URL="-loong64" + ;; esac -echo "Spark Store Install script. 星火商店审核脚本" +echo "Spark Store Audit script. 星火商店审核脚本" function pkexec_as_current_user() { local user=$(who | awk '{print $1}' | head -n 1) @@ -47,6 +52,7 @@ function exec_create_desktop_file() { } + function zenity() { local user=$(who | awk '{print $1}' | head -n 1) local uid=$(id -u "$user") @@ -54,19 +60,19 @@ function zenity() { } function hash_check() { - if [ ! -e "/var/lib/aptss/lists/cdn.d.store.deepinos.org.cn_${STORE_URL}_Packages" ] && \ + if [ ! -e "/var/lib/aptss/lists/d.spark-app.store_${STORE_URL}_Packages" ] && \ [ ! -e "/var/lib/aptss/lists/d.store.deepinos.org.cn_${STORE_URL}_Packages" ] && \ - [ ! -e "/var/lib/aptss/lists/mirrors.sdu.edu.cn_spark-store-repository_${STORE_URL}_Packages" ]; then + [ ! -e "/var/lib/aptss/lists/mirrors.sdu.edu.cn_spark-store_${STORE_URL}_Packages" ]; then echo "接收星火仓库软件信息中..." aptss ssupdate fi - if [ -e "/var/lib/aptss/lists/cdn.d.store.deepinos.org.cn_${STORE_URL}_Packages" ]; then - PACKAGES_DATA_PATH="/var/lib/aptss/lists/cdn.d.store.deepinos.org.cn_${STORE_URL}_Packages" - echo "星火仓库的Packages位置为 $PACKAGES_DATA_PATH,是星火域名单目录仓库配置" + if [ -e "/var/lib/aptss/lists/d.spark-app.store_${STORE_URL}_Packages" ]; then + PACKAGES_DATA_PATH="/var/lib/aptss/lists/d.spark-app.store_${STORE_URL}_Packages" + echo "星火仓库的Packages位置为 $PACKAGES_DATA_PATH,是星火域名仓库配置" elif [ -e "/var/lib/aptss/lists/d.store.deepinos.org.cn_${STORE_URL}_Packages" ]; then PACKAGES_DATA_PATH="/var/lib/aptss/lists/d.store.deepinos.org.cn_${STORE_URL}_Packages" - echo "星火仓库的Packages位置为 $PACKAGES_DATA_PATH,是星火域名单目录仓库配置" + echo "星火仓库的Packages位置为 $PACKAGES_DATA_PATH,是d域名单目录仓库配置" else PACKAGES_DATA_PATH="/var/lib/aptss/lists/mirrors.sdu.edu.cn_spark-store-repository_${STORE_URL}_Packages" echo "星火仓库的Packages位置为 $PACKAGES_DATA_PATH,是SDU镜像仓库配置" @@ -76,11 +82,47 @@ function hash_check() { echo "Running Spark Package Verify..." DEB_SHA512SUM=$(sha512sum "$1" | cut -d ' ' -f 1) + unset IS_SHA512SUM_CHECKED IS_SHA512SUM_CHECKED=$(cat "$PACKAGES_DATA_PATH" | grep "$DEB_SHA512SUM") } +function lock_file(){ +chattr +i "$1" +} +function unlock_file(){ +chattr -i "$1" +} +function ensure_aptss_exist(){ + + if command -v aptss &>/dev/null; then + aptss update + else + local deb_file="/tmp/spark-store-console-in-container_latest_all.deb" + + # Download package + if ! wget -O "$deb_file" "https://amber-ce-resource.spark-app.store/store/depends/spark-store-console-in-container_latest_all.deb"; then + echo "下载 .deb 安装包失败" >&2 + return 1 + fi + + # Install package + if ! apt install -y "$deb_file"; then + echo "安装 .deb 包失败" >&2 + rm -f "$deb_file" + return 1 + fi + rm -f "$deb_file" + + # Verify installation + if ! command -v aptss &>/dev/null; then + echo "成功安装但未找到 aptss 命令" >&2 + return 1 + fi + fi +} +export -f ensure_aptss_exist #################################### if [ $# -eq 0 ]; then @@ -90,11 +132,7 @@ if [ $# -eq 0 ]; then exit fi -if [ ! -f "$1" ]; then - echo "${TRANSHELL_CONTENT_FILE_NOT_EXIST}" - echo "OMG-IT-GOES-WRONG" - exit 1 -fi + if [ "$(id -u)" != "0" ]; then echo "${TRANSHELL_CONTENT_PLEASE_RUN_AS_ROOT}" @@ -102,28 +140,80 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -DEBPATH=$(realpath "$1") +if [ ! -f "$1" ]; then + echo "${TRANSHELL_CONTENT_FILE_NOT_EXIST},Trying to redownload" + FILEPATH=$(dirname "$1") + FILENAME=$(basename "$1") + PACKAGE_NAME=$(echo "$FILENAME" | sed -r 's/^([^_]+)_.*$/\1/') + VERSION=$(echo "$FILENAME" | sed -r 's/^[^_]+_([^_]+)_.*$/\1/') + pushd ${FILEPATH} + aptss download ${PACKAGE_NAME} + popd + if [ ! -f "$1" ]; then + echo "OMG-IT-GOES-WRONG" + exit 1 + else + DEBPATH=$(realpath "$1") + fi + else + DEBPATH=$(realpath "$1") +fi +lock_file "$DEBPATH" +IS_SHA512SUM_CHECKED=skipped +if [ ! -z "$IS_SHA512SUM_CHECKED" ]; then + echo "校验跳过,开始安装" + echo "----------------------------------------------------------------------------------" package_name=$(dpkg-deb -f "$DEBPATH" Package) echo "Package name is $package_name" - try_run_output=$(/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh test-install-app "$DEBPATH") try_run_ret="$?" +# 安装失败后进行 aptss update 刷新,随后尝试安装 if [ "$try_run_ret" -ne 0 ]; then aptss update try_run_output=$(/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh test-install-app "$DEBPATH") try_run_ret="$?" fi + + if [ "$try_run_ret" -ne 0 ]; then - if [ "$try_run_ret" -ne 0 ]; then - echo "OMG-IT-GOES-WRONG" - echo -e "${try_run_output}" - exit "$try_run_ret" + if [[ "$IS_ACE_ENV" == "" ]];then ## 如果已经在ACE里面则不进入分支 + if command -v bookworm-run ;then + echo "----------------------------------------" + echo "Attention: USING ACE BOOKWORM TO INSTALL" + echo "----------------------------------------" + bookworm-run ensure_aptss_exist + try_run_output=$(bookworm-run aptss install --dry-run "$DEBPATH") + try_run_ret="$?" + if [ "$try_run_ret" -ne 0 ]; then + bookworm-run aptss update + try_run_output=$(bookworm-run aptss install --dry-run "$DEBPATH") + try_run_ret="$?" + fi + if [ "$try_run_ret" -ne 0 ]; then + echo "OMG-IT-GOES-WRONG" + echo -e "${try_run_output}" + echo "----------------------------------------" + echo "Attention: USING ACE BOOKWORM TO INSTALL" + echo "----------------------------------------" + exit "$try_run_ret" + fi + bookworm-run dpkg -i "$DEBPATH" || aptss install "$DEBPATH" -yf + fi + + else + + echo "OMG-IT-GOES-WRONG" + echo -e "${try_run_output}" + exit "$try_run_ret" + fi + else + + dpkg -i "$DEBPATH" || aptss install "$DEBPATH" -yf fi - - dpkg -i "$DEBPATH" || aptss install "$DEBPATH" -yf +### 退出阶段 if [ "$?" = "0" ] && [ "$2" = "--delete-after-install" ]; then if dpkg -s "$package_name" >/dev/null 2>&1; then @@ -147,3 +237,4 @@ DEBPATH=$(realpath "$1") echo "OMG-IT-GOES-WRONG" fi fi +fi diff --git a/tool/ssinstall b/tool/ssinstall index 45fcc1e..3f82677 100755 --- a/tool/ssinstall +++ b/tool/ssinstall @@ -1,6 +1,7 @@ #!/bin/bash source /opt/durapps/spark-store/bin/bashimport/transhell.amber + load_transhell_debug export DEBIAN_FRONTEND=noninteractive @@ -94,6 +95,35 @@ function unlock_file(){ chattr -i "$1" } +function ensure_aptss_exist(){ + + if command -v aptss &>/dev/null; then + aptss update + else + local deb_file="/tmp/spark-store-console-in-container_latest_all.deb" + + # Download package + if ! wget -O "$deb_file" "https://amber-ce-resource.spark-app.store/store/depends/spark-store-console-in-container_latest_all.deb"; then + echo "下载 .deb 安装包失败" >&2 + return 1 + fi + + # Install package + if ! apt install -y "$deb_file"; then + echo "安装 .deb 包失败" >&2 + rm -f "$deb_file" + return 1 + fi + rm -f "$deb_file" + + # Verify installation + if ! command -v aptss &>/dev/null; then + echo "成功安装但未找到 aptss 命令" >&2 + return 1 + fi + fi +} +export -f ensure_aptss_exist #################################### if [ $# -eq 0 ]; then @@ -153,7 +183,7 @@ if [ ! -z "$IS_SHA512SUM_CHECKED" ]; then echo "Package name is $package_name" try_run_output=$(/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh test-install-app "$DEBPATH") try_run_ret="$?" - +# 安装失败后进行 aptss update 刷新,随后尝试安装 if [ "$try_run_ret" -ne 0 ]; then aptss update try_run_output=$(/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh test-install-app "$DEBPATH") @@ -161,14 +191,42 @@ if [ ! -z "$IS_SHA512SUM_CHECKED" ]; then fi if [ "$try_run_ret" -ne 0 ]; then - echo "OMG-IT-GOES-WRONG" - echo -e "${try_run_output}" - exit "$try_run_ret" - fi + + if [[ "$IS_ACE_ENV" == "" ]];then ## 如果已经在ACE里面则不进入分支 + if command -v bookworm-run ;then + echo "----------------------------------------" + echo "Attention: USING ACE BOOKWORM TO INSTALL" + echo "----------------------------------------" + bookworm-run ensure_aptss_exist + try_run_output=$(bookworm-run aptss install --dry-run "$DEBPATH") + try_run_ret="$?" + if [ "$try_run_ret" -ne 0 ]; then + bookworm-run aptss update + try_run_output=$(bookworm-run aptss install --dry-run "$DEBPATH") + try_run_ret="$?" + fi + if [ "$try_run_ret" -ne 0 ]; then + echo "OMG-IT-GOES-WRONG" + echo -e "${try_run_output}" + echo "----------------------------------------" + echo "Attention: USING ACE BOOKWORM TO INSTALL" + echo "----------------------------------------" + exit "$try_run_ret" + fi + bookworm-run dpkg -i "$DEBPATH" || aptss install "$DEBPATH" -yf + fi + + else + + echo "OMG-IT-GOES-WRONG" + echo -e "${try_run_output}" + exit "$try_run_ret" + fi + else dpkg -i "$DEBPATH" || aptss install "$DEBPATH" -yf - -unlock_file "$DEBPATH" + fi +### 退出阶段 if [ "$?" = "0" ] && [ "$2" = "--delete-after-install" ]; then if dpkg -s "$package_name" >/dev/null 2>&1; then