From a3d803477af8a9fac24e39d9faa05f871f4c093d Mon Sep 17 00:00:00 2001 From: zty199 <46324746+zty199@users.noreply.github.com> Date: Wed, 21 Dec 2022 12:09:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=BA=94=E7=94=A8=E5=88=97=E8=A1=A8=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=E4=BB=8D=E7=84=B6=E5=BC=B9=E5=87=BA=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=9B=B4=E6=96=B0=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 获取可更新应用列表后直接赋值给 zenity 处理,未对列表为空进行处理 Log: 获取可更新应用列表后,若列表为空则退出;不为空再交给 zenity 处理 --- tool/update-upgrade/ss-do-upgrade.sh | 39 +++++---- tool/update-upgrade/ss-update-notifier.sh | 102 ++++++++++------------ 2 files changed, 66 insertions(+), 75 deletions(-) diff --git a/tool/update-upgrade/ss-do-upgrade.sh b/tool/update-upgrade/ss-do-upgrade.sh index e022e47..cb34bb6 100755 --- a/tool/update-upgrade/ss-do-upgrade.sh +++ b/tool/update-upgrade/ss-do-upgrade.sh @@ -21,13 +21,12 @@ PKG_LIST="$(pkexec /opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-wor if [ -z "$PKG_LIST" ] ; then zenity --info --text "没有软件需要更新\n但是你并没有站在世界之巅" --title "星火商店更新检测模块" --height 150 --width 300 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg else - ## 指定分隔符为 \n + ## 获取用户选择的要更新的应用 + ### 指定分隔符为 \n IFS_OLD="$IFS" IFS=$'\n' - ## 获取用户选择的要更新的应用 PKG_UPGRADE_LIST=`for line in $PKG_LIST ; do - PKG_NAME=$(echo $line | awk -F ' ' '{print $1}') PKG_NEW_VER=$(echo $line | awk -F ' ' '{print $2}') PKG_CUR_VER=$(echo $line | awk -F ' ' '{print $3}') @@ -36,7 +35,7 @@ else if [ $? -eq 0 ] ; then continue fi - ### 检测是否是 hold 状态 + #### 检测是否是 hold 状态 PKG_STA=$(dpkg-query -W -f='${db:Status-Want}' $PKG_NAME) if [ "$PKG_STA" != "hold" ] ; then echo "true" @@ -49,25 +48,31 @@ else echo "$PKG_NEW_VER" echo "$PKG_NAME" fi -done | zenity --list --text="选择你想更新的应用" --column="是否更新" --column="包名" --column="新版本" --column="值" --separator=" " --checklist --multiple --print-column=4 --hide-column=4 --height 350 --width 550 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg` +done` - ## 还原分隔符 + ### 还原分隔符 IFS="$IFS_OLD" - ### 如果没有选择,则直接退出 - if [ "$PKG_UPGRADE_LIST" = "" ] ; then + ## 如果没有应用需要更新,则直接退出 + if [ -z "$PKG_UPGRADE_LIST" ] ; then zenity --info --text "没有选中任何软件\n但是你并没有站在世界之巅" --title "星火商店更新检测服务" --height 150 --width 300 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg else - ### 更新用户选择的应用 - pkexec /opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh upgrade-app $PKG_UPGRADE_LIST -y | zenity --progress --auto-close --no-cancel --pulsate --text="正在更新已选中的应用,请稍候..." --height 70 --width 400 --title="星火商店更新模块" --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg - - #### 更新成功 - if [ -z "`cat /tmp/spark-store-app-upgrade-status.txt`" ] ; then - zenity --info --text "选中的软件已经更新完毕" --title "星火商店更新检测模块" --height 150 --width 300 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg + PKG_UPGRADE_LIST=$(echo "$PKG_UPGRADE_LIST" | zenity --list --text="选择你想更新的应用" --column="是否更新" --column="包名" --column="新版本" --column="值" --separator=" " --checklist --multiple --print-column=4 --hide-column=4 --height 350 --width 550 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg) + ## 如果没有选择,则直接退出 + if [ -z "$PKG_UPGRADE_LIST" ] ; then + zenity --info --text "没有选中任何软件\n但是你并没有站在世界之巅" --title "星火商店更新检测服务" --height 150 --width 300 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg else - #### 更新异常 - zenity --error --text "更新出现错误!按确定查看报错,可用于反馈" --title "星火商店更新检测模块" --height 200 --width 350 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg - zenity --text-info --filename=/tmp/spark-store-app-upgrade-log.txt --checkbox="我已复制了此文本框中的日志,且将会在反馈时附上 。反馈渠道可以在右上角菜单的设置中找到" --title="反馈渠道在商店右上角的设置里往下拉" --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg + ### 更新用户选择的应用 + pkexec /opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh upgrade-app $PKG_UPGRADE_LIST -y | zenity --progress --auto-close --no-cancel --pulsate --text="正在更新已选中的应用,请稍候..." --height 70 --width 400 --title="星火商店更新模块" --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg + + #### 更新成功 + if [ -z "`cat /tmp/spark-store-app-upgrade-status.txt`" ] ; then + zenity --info --text "选中的软件已经更新完毕" --title "星火商店更新检测模块" --height 150 --width 300 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg + else + #### 更新异常 + zenity --error --text "更新出现错误!按确定查看报错,可用于反馈" --title "星火商店更新检测模块" --height 200 --width 350 --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg + zenity --text-info --filename=/tmp/spark-store-app-upgrade-log.txt --checkbox="我已复制了此文本框中的日志,且将会在反馈时附上 。反馈渠道可以在右上角菜单的设置中找到" --title="反馈渠道在商店右上角的设置里往下拉" --window-icon=/usr/share/icons/hicolor/scalable/apps/spark-store.svg + fi fi fi fi diff --git a/tool/update-upgrade/ss-update-notifier.sh b/tool/update-upgrade/ss-update-notifier.sh index a7ea6c6..a220741 100755 --- a/tool/update-upgrade/ss-update-notifier.sh +++ b/tool/update-upgrade/ss-update-notifier.sh @@ -1,107 +1,93 @@ #!/bin/bash -LANG=en.US +LANGUAGE=en_US +# 发送通知 function notify-send() { - #Detect the name of the display in use + # Detect name of the display in use local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)" - #Detect the user using such display + # Detect user using the display local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1) - #Detect the id of the user + # Detect uid of the user local uid=$(id -u $user) - sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send "$@" + su -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${uid}/bus notify-send "$@" } -#检测网络链接畅通 +# 检测网络链接畅通 function network() { - #超时时间 + # 超时时间 local timeout=15 - #目标网站 + # 目标网站 local target=www.baidu.com - #获取响应状态码 + # 获取响应状态码 local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1` - if [ "x$ret_code" = "x200" ]; then - #网络畅通 + if [ "x$ret_code" = "x200" ] ; then + # 网络畅通 return 0 else - #网络不畅通 + # 网络不畅通 return 1 fi - - return 0 } network -if [ $? -eq 1 ];then - echo "Network fail. Stop to avoid bother dpkg" - exit -1 +if [ $? -ne 0 ] ; then + echo "Network fail. Stop to avoid bother dpkg" + exit -1 fi -#The code above is modified from https://blog.csdn.net/yaxuan88521/article/details/120516298 +# The code above is modified from https://blog.csdn.net/yaxuan88521/article/details/120516298 -curl --progress-bar -o /opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list "https://gitee.com/deepin-community-store/repo_auto_update_script/raw/master/mirror-list-for-apt-fast/sources.list.d/sparkstore.list" # 每日更新星火源文件 - +curl --progress-bar -o /opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list "https://gitee.com/deepin-community-store/repo_auto_update_script/raw/master/mirror-list-for-apt-fast/sources.list.d/sparkstore.list" updatetext=`aptss ssupdate` - - - - isupdate=`echo ${updatetext: -5}` -if [ "$isupdate" = "date." ];then -exit 0 +if [ "$isupdate" = "date." ] ; then + exit 0 fi -#### 从这里开始,只有检测到了更新才会进行 +## 从这里开始,只有检测到了更新才会进行 update_app_number=`echo ${updatetext%package*} #从右向左截取第一个 src 后的字符串` update_app_number=`echo ${update_app_number##*information...}` - +# 获取用户选择的要更新的应用 PKG_LIST="$(/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade-worker.sh upgradable-list)" +# 指定分隔符为 \n +IFS_OLD="$IFS" +IFS=$'\n' - - -## 指定分隔符为 \n - IFS_OLD="$IFS" - IFS=$'\n' - - ## 获取用户选择的要更新的应用 for line in $PKG_LIST ; do + PKG_NAME=$(echo $line | awk -F ' ' '{print $1}') + PKG_NEW_VER=$(echo $line | awk -F ' ' '{print $2}') + PKG_CUR_VER=$(echo $line | awk -F ' ' '{print $3}') - PKG_NAME=$(echo $line | awk -F ' ' '{print $1}') - PKG_NEW_VER=$(echo $line | awk -F ' ' '{print $2}') - PKG_CUR_VER=$(echo $line | awk -F ' ' '{print $3}') + dpkg --compare-versions $PKG_NEW_VER le $PKG_CUR_VER + if [ $? -eq 0 ] ; then + let update_app_number=$update_app_number-1 + continue + fi - dpkg --compare-versions $PKG_NEW_VER le $PKG_CUR_VER - - if [ $? -eq 0 ] ; then - let update_app_number=$update_app_number-1 - continue - fi - - ### 检测是否是 hold 状态 - PKG_STA=$(dpkg-query -W -f='${db:Status-Want}' $PKG_NAME) - if [ "$PKG_STA" = "hold" ] ; then - let update_app_number=$update_app_number-1 - fi + ## 检测是否是 hold 状态 + PKG_STA=$(dpkg-query -W -f='${db:Status-Want}' $PKG_NAME) + if [ "$PKG_STA" = "hold" ] ; then + let update_app_number=$update_app_number-1 + fi done +# 还原分隔符 +IFS="$IFS_OLD" - - -if [ $update_app_number -le 0 ];then -exit +if [ $update_app_number -le 0 ] ; then + exit 0 fi -#### 如果都是hold或者版本一致的那就直接退出,否则把剩余的给提醒了 - -notify-send -i spark-store "星火更新提醒" "星火商店仓库中有$update_app_number个软件包可以更新啦!请到星火商店的菜单处理" - +## 如果都是hold或者版本一致的那就直接退出,否则把剩余的给提醒了 +notify-send -a spark-store "星火更新提醒" "星火商店仓库中有$update_app_number个软件包可以更新啦!请到星火商店的菜单处理"