spark-store/tool/ssinstall
shenmo 2803d4b8da
update tool/ssinstall.
Signed-off-by: shenmo <jifengshenmo@outlook.com>
2023-08-31 09:26:59 +00:00

166 lines
4.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
source /opt/durapps/spark-store/bin/bashimport/transhell.amber
load_transhell_debug
case `arch` in
x86_64)
STORE_URL="store"
;;
aarch64)
STORE_URL="aarch64-store"
;;
esac
echo "Spark Store Install script.星火商店安装脚本"
function pkexec_as_current_user() {
#Detect the user using such display
local user=$(who | awk '{print $1}' | head -n 1)
#Detect the id of the user
local uid=$(id -u $user)
sudo -u $user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus pkexec "$@"
}
function zenity()
{
#Detect the user using such display
local user=$(who | awk '{print $1}' | head -n 1)
#Detect the id of the user
local uid=$(id -u $user)
sudo -u $user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus zenity "$@"
}
function hash_check()
{
if [ ! -e "/var/lib/aptss/lists/cdn.d.store.deepinos.org.cn_${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
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,是星火域名单目录仓库配置"
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,是星火域名单目录仓库配置"
else
PACKAGES_DATA_PATH="/var/lib/aptss/lists/mirrors.sdu.edu.cn_spark-store-repository_${STORE_URL}_Packages"
echo "星火仓库的Packages位置为 $PACKAGES_DATA_PATH是SDU镜像仓库配置"
fi
echo "正在计算hash并与星火仓库匹配..."
DEB_MD5SUM=`md5sum "$1" | cut -c -32`
IS_MD5SUM_CHECKD=`cat $PACKAGES_DATA_PATH | grep $DEB_MD5SUM`
}
##########################################################################
#################检测文件是否存在
if [ $# -eq 0 ];then
echo "没有接收到参数,退出"
echo "用法:$0 deb路径"
echo "OMG-IT-GOES-WRONG"
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
#############################无root权限时
echo "${TRANSHELL_CONTENT_PLEASE_RUN_AS_ROOT}"
echo "OMG-IT-GOES-WRONG"
exit 1
fi
###
DEBPATH=`realpath $1`
hash_check "$DEBPATH"
if [ -z "$IS_MD5SUM_CHECKD" ];then
echo "尝试更新仓库信息重新校验"
aptss ssupdate
hash_check "$DEBPATH"
fi
if [ ! -z "$IS_MD5SUM_CHECKD" ];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="$?"
if [ "$try_run_ret" -ne 0 ]
then
echo "OMG-IT-GOES-WRONG"
echo -e "${try_run_output}"
exit "$try_run_ret"
fi
dpkg -i "$DEBPATH" || aptss install -yf
#### --delete
if [ "$?" = "0" ] && [ "$2" = "--delete-after-install" ];then
##check if is installed yet
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "软件包已安装:$package_name"
rm "$DEBPATH"
echo "${TRANSHELL_CONTENT_DEB_IS_DELETED}"
else
echo "软件包未安装:$package_name"
echo "安装异常!抛出错误"
echo "OMG-IT-GOES-WRONG"
fi
else
echo "${TRANSHELL_CONTENT_WILL_NOT_DELETE_DEB}"
if dpkg -s "$package_name" >/dev/null 2>&1; then
echo "软件包已安装:$package_name"
else
echo "软件包未安装:$package_name"
echo "安装异常!抛出错误"
echo "OMG-IT-GOES-WRONG"
fi
fi
else
zenity --info --icon-name=spark-store --height 270 --width 500 --text "${TRANSHELL_CONTENT_HASH_CHECK_FAILED}"
echo -e ${TRANSHELL_CONTENT_HASH_CHECK_FAILED}
echo "OMG-IT-GOES-WRONG"
fi