diff --git a/ACE-rpm/rpmbuild/BUILD/.keep b/ACE-rpm/rpmbuild/BUILD/.keep new file mode 100644 index 0000000..e69de29 diff --git a/ACE-rpm/rpmbuild/RPMS/.keep b/ACE-rpm/rpmbuild/RPMS/.keep new file mode 100644 index 0000000..e69de29 diff --git a/ACE-rpm/rpmbuild/SRPMS/.keep b/ACE-rpm/rpmbuild/SRPMS/.keep new file mode 100644 index 0000000..e69de29 diff --git a/src/DEBIAN/control b/src/DEBIAN/control index 62a1eee..f7d7b4e 100755 --- a/src/DEBIAN/control +++ b/src/DEBIAN/control @@ -1,8 +1,8 @@ Package: cn.flamescion.bookworm-compatibility-mode -Version: 12.4.7 +Version: 12.4.8 Section: misc Priority: optional -Depends: bubblewrap,flatpak,zenity,policykit-1,gcc +Depends: bubblewrap,flatpak,zenity,policykit-1,gcc,systemd Maintainer: shenmo Architecture: amd64 Description: bwrap wrapper for install and running debs inside a bookworm container diff --git a/src/DEBIAN/postinst b/src/DEBIAN/postinst index e12aebb..b92f22d 100755 --- a/src/DEBIAN/postinst +++ b/src/DEBIAN/postinst @@ -2,3 +2,8 @@ export PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE" /opt/apps/$PACKAGE_NAME/files/bin/bookworm-init +if [ "${PACKAGE_NAME}" = "cn.flamescion.bookworm-compatibility-mode" ];then +systemctl daemon-reload +systemctl enable ace-auto-upgrade +systemctl start ace-auto-upgrade +fi diff --git a/src/DEBIAN/postrm b/src/DEBIAN/postrm index 69f6013..e649349 100755 --- a/src/DEBIAN/postrm +++ b/src/DEBIAN/postrm @@ -1,5 +1,13 @@ #!/bin/bash PACKAGE_NAME="$DPKG_MAINTSCRIPT_PACKAGE" + +if [ "${PACKAGE_NAME}" = "cn.flamescion.bookworm-compatibility-mode" ];then +systemctl stop ace-auto-upgrade +systemctl disable ace-auto-upgrade +fi + + + if [ "$1" = "remove" ] || [ "$1" = "purge" ];then echo "清理卸载残留" @@ -9,3 +17,5 @@ else echo "非卸载,跳过清理" fi + + diff --git a/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/build-container.sh b/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/build-container.sh index 4f223da..93a8c52 100755 --- a/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/build-container.sh +++ b/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/build-container.sh @@ -23,7 +23,7 @@ exit 1 fi cd "`dirname $0`" -sudo debootstrap --include=apt-utils,bash-completion,bc,curl,dialog,diffutils,findutils,gnupg2,less,libnss-myhostname,libvte-common,lsof,ncurses-base,passwd,pinentry-curses,procps,sudo,time,util-linux,wget,libegl1-mesa,libgl1-mesa-glx,libvulkan1,mesa-vulkan-drivers,locales,libglib2.0-bin --arch=${ARCH} bookworm ./bookworm-env https://mirrors.ustc.edu.cn/debian/ +sudo debootstrap --include=libnotify-bin,apt-utils,bash-completion,bc,curl,dialog,diffutils,findutils,gnupg2,less,libnss-myhostname,libvte-common,lsof,ncurses-base,passwd,pinentry-curses,procps,sudo,time,util-linux,wget,libegl1-mesa,libgl1-mesa-glx,libvulkan1,mesa-vulkan-drivers,locales,libglib2.0-bin --arch=${ARCH} bookworm ./bookworm-env https://mirrors.ustc.edu.cn/debian/ sudo rm -rf bookworm-env/var/cache/apt/archives/*.deb diff --git a/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/flamescion-container-tools/ace-upgrader/ace-upgrader b/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/flamescion-container-tools/ace-upgrader/ace-upgrader new file mode 100755 index 0000000..06fc201 --- /dev/null +++ b/src/opt/apps/cn.flamescion.bookworm-compatibility-mode/files/flamescion-container-tools/ace-upgrader/ace-upgrader @@ -0,0 +1,170 @@ +#!/bin/bash +LANGUAGE=en_US + + + +############################################################# +# ===== Log ===== +# log.info xxx +# log.warn xxx +# log.info xxx +# log.debug xxx +# 带颜色的echo +function log.color_output() { + local color=$1 + shift 1 + + echo >&2 -e "\033[${color}m$@\033[0m" + return 0 +} + +# Log is named without prefix "utils." for convenience +# Usage: log.log ...content +function log.log() { + if [[ $# < 2 ]]; then + return -1 + fi + + local level=$1 + shift 1 + + case $level in + error) log.color_output "0;31" "[ERROR] $@" ;; + warn) log.color_output "1;33" "[WARN] $@" ;; + info) log.color_output "1;37" "[INFO] $@" ;; + debug) log.color_output "1;30" "[DEBUG] $@" ;; + esac + + return 0 +} + +function log.error() { log.log "error" "$@"; } +function log.warn() { log.log "warn" $@; } +function log.info() { log.log "info" $@; } +function log.debug() { log.log "debug" $@; } + + +# 发送通知 +function notify-send() { + + + # Detect user using the display + local user=$(who | awk '{print $1}' | head -n 1) + + # Detect uid of the user + local uid=$(id -u $user) + + sudo -u $user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${uid}/bus notify-send "$@" +} + + + +# 检测网络链接畅通 +function network-check() +{ + # 超时时间 + 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 + # 网络畅通 + return 0 + else + # 网络不畅通 + return 1 + fi +} +############################################################### + +if [ "$(id -u)" != "0" ]; then +log.error "Nope we need root to run" +exit -1 +fi + +network-check +if [ $? -ne 0 ] ; then + log.error "NETWORK_FAIL" + exit -1 +fi + +# The code above is modified from https://blog.csdn.net/yaxuan88521/article/details/120516298 + +if [ $(which aptss) ];then +APT_COMMAND=aptss +log.info "Using aptss to operate the upgrade process since we detect it." +elif [ -e /usr/bin/apt ];then +APT_COMMAND=/usr/bin/apt +log.info "Using apt to operate the upgrade process." +else +log.error "Nope we support debian only now" +exit -1 +fi +${APT_COMMAND} update + +updatetext=`${APT_COMMAND} update 2>&1` + +until [ "`echo $updatetext | grep E: `" = "" ];do +log.info "UPDATE_ERROR_AND_WAIT_15_SEC" +sleep 15 +updatetext=`${APT_COMMAND} update 2>&1` + + + +done + +isupdate=`echo ${updatetext: -5}` +if [ "$isupdate" = "date." ] ; then + log.info "No need to upgrade. exit" + exit 0 +fi + +## 从这里开始,只有检测到了更新才会进行 +update_app_number=`echo ${updatetext%package*} #从右向左截取第一个 src 后的字符串` +update_app_number=`echo ${update_app_number##*information...}` + +# 获取用户选择的要更新的应用 +PKG_LIST="$(env LANGUAGE=en_US /usr/bin/apt list --upgradable | awk NR\>1)" +# 指定分隔符为 \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}') + + 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 +done + +# 还原分隔符 +IFS="$IFS_OLD" +if [ $update_app_number -le 0 ] ; then + log.info "No package need to upgrade after ignoring those holded ones. exit" + exit 0 +fi + + +## 如果都是hold或者版本一致的那就直接退出,否则把剩余的给提醒了 + + +user=$(who | awk '{print $1}' | head -n 1) + + log.info "ACE环境中有 $update_app_number 个软件包可升级,正在自动升级" +notify-send -a cn.flamescion.bookworm-compatibility-mode "ACE 兼容环境" "ACE环境中有 $update_app_number 个软件包可升级,正在自动升级" + diff --git a/src/usr/lib/systemd/system/ace-auto-upgrade.service b/src/usr/lib/systemd/system/ace-auto-upgrade.service new file mode 100644 index 0000000..f609163 --- /dev/null +++ b/src/usr/lib/systemd/system/ace-auto-upgrade.service @@ -0,0 +1,14 @@ +[Unit] +Description=Amber CE Auto upgrade +After=apt-daily.service network.target network-online.target systemd-networkd.service NetworkManager.service connman.service + + +[Service] +Type=simple +RemainAfterExit=yes +ExecStart=bookworm-run /flamescion-container-tools/ace-upgrader/ace-upgrader +Restart=on-failure +RestartSec=10 + +[Install] +WantedBy=multi-user.target