From e59ff1d61b81767e8e884e73763073b269fb2e09 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 05:41:09 +0000 Subject: [PATCH 01/12] Fixed: package manager update bugs --- .update.sh | 64 +++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/.update.sh b/.update.sh index 83056ed..a70bbd5 100755 --- a/.update.sh +++ b/.update.sh @@ -79,7 +79,17 @@ cleanup_snapd() { return fi - rm -rf /var/lib/snapd/cache/* + # Robustly clean Snap cache if the directory exists and is not empty + SNAP_CACHE_DIR="/var/lib/snapd/cache" + if [ -d "${SNAP_CACHE_DIR}" ]; then + if rm -rf "${SNAP_CACHE_DIR:?}/"*; then + println "Snap cache cleaned from ${SNAP_CACHE_DIR}" + else + print_err "Error: Failed to clean Snap cache at ${SNAP_CACHE_DIR}" + fi + else + println "Snap cache directory ${SNAP_CACHE_DIR} does not exist." + fi # List all snaps and filter for disabled ones snap list --all | awk '/disabled/{print $1, $3}' | while read -r snap_name revision; do @@ -142,39 +152,29 @@ update_snapd() { update_os_pkg() { case "${ADJUSTED_ID}" in debian) - if [ "$(find /var/lib/apt/lists/* -maxdepth 1 -type f 2>/dev/null | wc -l)" -eq 0 ]; then - println "Updating ${PKG_MGR_CMD} based packages..." - if ! ("${PKG_MGR_CMD}" update -y && - "${PKG_MGR_CMD}" upgrade -y && - "${PKG_MGR_CMD}" dist-upgrade -y && - "${PKG_MGR_CMD}" autoremove -y && - "${PKG_MGR_CMD}" autoclean -y); then - print_err "Error: Update failed." - fi + println "Updating ${PKG_MGR_CMD} based packages..." + if ! ("${PKG_MGR_CMD}" update -y && + "${PKG_MGR_CMD}" upgrade -y && + "${PKG_MGR_CMD}" dist-upgrade -y && + "${PKG_MGR_CMD}" autoremove -y && + "${PKG_MGR_CMD}" autoclean -y); then + print_err "Error: Update failed." fi update_snapd ;; rhel) + println "Updating ${PKG_MGR_CMD} based packages..." if [ "${PKG_MGR_CMD}" = "microdnf" ]; then - if [ "$(find /var/cache/yum/* -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null | wc -l)" -eq 0 ]; then - println "Running ${PKG_MGR_CMD} makecache..." - "${PKG_MGR_CMD}" makecache + if ! ("${PKG_MGR_CMD}" makecache); then + print_err "Error: Update failed." fi else - if [ "$(find "/var/cache/${PKG_MGR_CMD}"/* -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null | wc -l)" -eq 0 ]; then - println "Running ${PKG_MGR_CMD} check-update..." - set +e - "${PKG_MGR_CMD}" check-update - rc=$? - if [ $rc -ne 0 ] && [ $rc -ne 100 ]; then - exit 1 - fi - set -e + if ! ("${PKG_MGR_CMD}" check-update); then + print_err "Error: Update failed." fi fi - println "Updating ${PKG_MGR_CMD} based packages..." if ! ("${PKG_MGR_CMD}" update -y && "${PKG_MGR_CMD}" upgrade -y && "${PKG_MGR_CMD}" autoremove -y); then @@ -182,20 +182,16 @@ update_os_pkg() { fi ;; alpine) - if [ "$(find /var/cache/apk/* 2>/dev/null | wc -l)" -eq 0 ]; then - println "Updating ${PKG_MGR_CMD} based packages..." - if ! ("${PKG_MGR_CMD}" update && "${PKG_MGR_CMD}" upgrade); then - print_err "Error: Update failed." - fi + println "Updating ${PKG_MGR_CMD} based packages..." + if ! ("${PKG_MGR_CMD}" update && "${PKG_MGR_CMD}" upgrade); then + print_err "Error: Update failed." fi ;; arch) - if [ "$(find /var/cache/pacman/pkg/* 2>/dev/null | wc -l)" -eq 0 ]; then - println "Updating ${PKG_MGR_CMD} based packages..." - if ! ("${PKG_MGR_CMD}" -Syu --noconfirm && - "${PKG_MGR_CMD}" -Rns "$("${PKG_MGR_CMD}" -Qdtq)"); then - print_err "Error: Update failed." - fi + println "Updating ${PKG_MGR_CMD} based packages..." + if ! ("${PKG_MGR_CMD}" -Syu --noconfirm && + "${PKG_MGR_CMD}" -Rns "$("${PKG_MGR_CMD}" -Qdtq)"); then + print_err "Error: Update failed." fi ;; *) From 2b1e98ada93dc968be449db9dfb091e40911a5b0 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:18:18 +0530 Subject: [PATCH 02/12] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.update.sh b/.update.sh index a70bbd5..cfdab31 100755 --- a/.update.sh +++ b/.update.sh @@ -170,7 +170,9 @@ update_os_pkg() { print_err "Error: Update failed." fi else - if ! ("${PKG_MGR_CMD}" check-update); then + "${PKG_MGR_CMD}" check-update + rc=$? + if [ $rc -ne 0 ] && [ $rc -ne 100 ]; then print_err "Error: Update failed." fi fi From ed40294d1daf09bf72a6c46872a24fba48e0a059 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:19:50 +0530 Subject: [PATCH 03/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.update.sh b/.update.sh index cfdab31..7eac4a3 100755 --- a/.update.sh +++ b/.update.sh @@ -191,10 +191,16 @@ update_os_pkg() { ;; arch) println "Updating ${PKG_MGR_CMD} based packages..." - if ! ("${PKG_MGR_CMD}" -Syu --noconfirm && - "${PKG_MGR_CMD}" -Rns "$("${PKG_MGR_CMD}" -Qdtq)"); then + if ! ("${PKG_MGR_CMD}" -Syu --noconfirm); then print_err "Error: Update failed." fi + # Remove orphaned packages if any exist + ORPHANS=$("${PKG_MGR_CMD}" -Qdtq) + if [ -n "$ORPHANS" ]; then + if ! ("${PKG_MGR_CMD}" -Rns $ORPHANS); then + print_err "Error: Failed to remove orphaned packages." + fi + fi ;; *) print_err "Error: Unsupported or unrecognized Linux distribution: ${ADJUSTED_ID}" From f8db67543a77277b52e19ab40349270856e262c0 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:20:01 +0530 Subject: [PATCH 04/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.update.sh b/.update.sh index 7eac4a3..7556674 100755 --- a/.update.sh +++ b/.update.sh @@ -82,7 +82,7 @@ cleanup_snapd() { # Robustly clean Snap cache if the directory exists and is not empty SNAP_CACHE_DIR="/var/lib/snapd/cache" if [ -d "${SNAP_CACHE_DIR}" ]; then - if rm -rf "${SNAP_CACHE_DIR:?}/"*; then + if rm -rf "${SNAP_CACHE_DIR}/"*; then println "Snap cache cleaned from ${SNAP_CACHE_DIR}" else print_err "Error: Failed to clean Snap cache at ${SNAP_CACHE_DIR}" From dd742cdb036d84995537d08e52519a5c10554bea Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 05:52:45 +0000 Subject: [PATCH 05/12] Fixed Bugs' --- .update.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.update.sh b/.update.sh index 7556674..8b6602b 100755 --- a/.update.sh +++ b/.update.sh @@ -82,7 +82,7 @@ cleanup_snapd() { # Robustly clean Snap cache if the directory exists and is not empty SNAP_CACHE_DIR="/var/lib/snapd/cache" if [ -d "${SNAP_CACHE_DIR}" ]; then - if rm -rf "${SNAP_CACHE_DIR}/"*; then + if rm -rf "${SNAP_CACHE_DIR:?}/"*; then println "Snap cache cleaned from ${SNAP_CACHE_DIR}" else print_err "Error: Failed to clean Snap cache at ${SNAP_CACHE_DIR}" @@ -196,8 +196,8 @@ update_os_pkg() { fi # Remove orphaned packages if any exist ORPHANS=$("${PKG_MGR_CMD}" -Qdtq) - if [ -n "$ORPHANS" ]; then - if ! ("${PKG_MGR_CMD}" -Rns $ORPHANS); then + if [ -n "${ORPHANS}" ]; then + if ! ("${PKG_MGR_CMD}" -Rns "${ORPHANS}"); then print_err "Error: Failed to remove orphaned packages." fi fi From d93b3f0baf09bc638cc499bf142c465965e69ede Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:27:11 +0530 Subject: [PATCH 06/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.update.sh b/.update.sh index 8b6602b..3c3c7e5 100755 --- a/.update.sh +++ b/.update.sh @@ -195,7 +195,7 @@ update_os_pkg() { print_err "Error: Update failed." fi # Remove orphaned packages if any exist - ORPHANS=$("${PKG_MGR_CMD}" -Qdtq) + ORPHANS=$("${PKG_MGR_CMD}" -Qdtq || true) if [ -n "${ORPHANS}" ]; then if ! ("${PKG_MGR_CMD}" -Rns "${ORPHANS}"); then print_err "Error: Failed to remove orphaned packages." From 78be61ea1faa3833770ce19e4b9697c1524cc83b Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:31:51 +0530 Subject: [PATCH 07/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.update.sh b/.update.sh index 3c3c7e5..e8cddc6 100755 --- a/.update.sh +++ b/.update.sh @@ -167,7 +167,7 @@ update_os_pkg() { println "Updating ${PKG_MGR_CMD} based packages..." if [ "${PKG_MGR_CMD}" = "microdnf" ]; then if ! ("${PKG_MGR_CMD}" makecache); then - print_err "Error: Update failed." + print_err "Error: Failed to update package cache." fi else "${PKG_MGR_CMD}" check-update From 88151b8c6e701caabafa7aecc505ab2c086d20a6 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:32:01 +0530 Subject: [PATCH 08/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.update.sh b/.update.sh index e8cddc6..9ff813f 100755 --- a/.update.sh +++ b/.update.sh @@ -195,9 +195,8 @@ update_os_pkg() { print_err "Error: Update failed." fi # Remove orphaned packages if any exist - ORPHANS=$("${PKG_MGR_CMD}" -Qdtq || true) - if [ -n "${ORPHANS}" ]; then - if ! ("${PKG_MGR_CMD}" -Rns "${ORPHANS}"); then + if [ -n "$("${PKG_MGR_CMD}" -Qdtq)" ]; then + if ! ("${PKG_MGR_CMD}" -Rns $("${PKG_MGR_CMD}" -Qdtq)); then print_err "Error: Failed to remove orphaned packages." fi fi From 90abf0a0c0b9391c507c519ecd1518164b6851f3 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:35:32 +0530 Subject: [PATCH 09/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.update.sh b/.update.sh index 9ff813f..ffde1c5 100755 --- a/.update.sh +++ b/.update.sh @@ -195,11 +195,14 @@ update_os_pkg() { print_err "Error: Update failed." fi # Remove orphaned packages if any exist - if [ -n "$("${PKG_MGR_CMD}" -Qdtq)" ]; then - if ! ("${PKG_MGR_CMD}" -Rns $("${PKG_MGR_CMD}" -Qdtq)); then + ORPHANS=$("${PKG_MGR_CMD}" -Qdtq) + rc=$? + if [ $rc -eq 0 ] && [ -n "${ORPHANS}" ]; then + if ! ("${PKG_MGR_CMD}" -Rns ${ORPHANS}); then print_err "Error: Failed to remove orphaned packages." fi - fi + elif [ $rc -ne 1 ]; then + print_err "Error: Failed to detect orphaned packages (exit code $rc)." ;; *) print_err "Error: Unsupported or unrecognized Linux distribution: ${ADJUSTED_ID}" From a7462f5baed29cc685b3dd9c134ce3b1a3b119be Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:37:58 +0530 Subject: [PATCH 10/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.update.sh b/.update.sh index ffde1c5..e570370 100755 --- a/.update.sh +++ b/.update.sh @@ -198,7 +198,7 @@ update_os_pkg() { ORPHANS=$("${PKG_MGR_CMD}" -Qdtq) rc=$? if [ $rc -eq 0 ] && [ -n "${ORPHANS}" ]; then - if ! ("${PKG_MGR_CMD}" -Rns ${ORPHANS}); then + if ! ("${PKG_MGR_CMD}" -Rns "${ORPHANS}"); then print_err "Error: Failed to remove orphaned packages." fi elif [ $rc -ne 1 ]; then From d7ca558d7601f34fac7869a1ac62351f263bfd29 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 11:38:09 +0530 Subject: [PATCH 11/12] Update .update.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .update.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.update.sh b/.update.sh index e570370..e1b46c4 100755 --- a/.update.sh +++ b/.update.sh @@ -203,6 +203,7 @@ update_os_pkg() { fi elif [ $rc -ne 1 ]; then print_err "Error: Failed to detect orphaned packages (exit code $rc)." + fi ;; *) print_err "Error: Unsupported or unrecognized Linux distribution: ${ADJUSTED_ID}" From 00ed869a4ca775314693ba1d399fb4f240761b94 Mon Sep 17 00:00:00 2001 From: Vatsal Gupta <40350810+gvatsal60@users.noreply.github.com> Date: Sun, 21 Sep 2025 06:20:57 +0000 Subject: [PATCH 12/12] Fix Codacy Bugs --- .update.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.update.sh b/.update.sh index e1b46c4..ede2a80 100755 --- a/.update.sh +++ b/.update.sh @@ -172,7 +172,7 @@ update_os_pkg() { else "${PKG_MGR_CMD}" check-update rc=$? - if [ $rc -ne 0 ] && [ $rc -ne 100 ]; then + if [ "${rc}" -ne 0 ] && [ "${rc}" -ne 100 ]; then print_err "Error: Update failed." fi fi @@ -197,12 +197,12 @@ update_os_pkg() { # Remove orphaned packages if any exist ORPHANS=$("${PKG_MGR_CMD}" -Qdtq) rc=$? - if [ $rc -eq 0 ] && [ -n "${ORPHANS}" ]; then + if [ "${rc}" -eq 0 ] && [ -n "${ORPHANS}" ]; then if ! ("${PKG_MGR_CMD}" -Rns "${ORPHANS}"); then print_err "Error: Failed to remove orphaned packages." fi - elif [ $rc -ne 1 ]; then - print_err "Error: Failed to detect orphaned packages (exit code $rc)." + elif [ "${rc}" -ne 1 ]; then + print_err "Error: Failed to detect orphaned packages (exit code ${rc})." fi ;; *)