diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e0fa3a2..e679a59 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -52,7 +52,7 @@ } } }, - "image": "mcr.microsoft.com/devcontainers/javascript-node", + "image": "mcr.microsoft.com/devcontainers/base:debian", "mounts": [ "source=${localWorkspaceFolder}/snippets,target=${containerWorkspaceFolder}/.vscode,type=bind,consistency=cached" ], diff --git a/.update.sh b/.update.sh index 3ebe9e5..6d325aa 100755 --- a/.update.sh +++ b/.update.sh @@ -81,17 +81,28 @@ cleanup_snapd() { rm -rf /var/lib/snapd/cache/* - # List all snaps and filter for disabled ones - snap list --all | awk '/disabled/{print $1, $3}' | while read -r snapname revision; do + # Get snap list output once and store it + if ! snap_output=$(snap list --all); then + print_err "Error: Failed to retrieve snap list." + return + fi + + # Check if no snaps are installed (only header line present) + if [ "$(echo "${snap_output}" | wc -l)" -le 1 ]; then + return + fi + + # Process the stored output to find disabled snaps + echo "${snap_output}" | awk '/disabled/{print $1, $3}' | while read -r snap_name revision; do # Check if variables are set and not empty - if [ -z "$snapname" ] || [ -z "$revision" ]; then + if [ -z "${snap_name}" ] || [ -z "${revision}" ]; then print_err "Error: Snap name or revision is empty. Skipping..." continue fi # Attempt to remove the snap revision - if ! snap remove "$snapname" --revision="$revision"; then - print_err "Error: Failed to remove $snapname (revision $revision)." + if ! snap remove "${snap_name}" --revision="${revision}"; then + print_err "Error: Failed to remove ${snap_name} (revision ${revision})." fi done } @@ -102,7 +113,7 @@ cleanup_snapd() { # Provides output to indicate the cleanup process and handles errors gracefully. # Usage: Call this function to automate system cleanup tasks after updating the system. clean_up() { - case ${ADJUSTED_ID} in + case "${ADJUSTED_ID}" in debian) # rm -rf /var/lib/apt/lists/* cleanup_snapd @@ -140,9 +151,9 @@ update_snapd() { # Supports Debian-based (apt-get), RPM-based (dnf/yum/microdnf), and Alpine (apk) package managers. # Prints messages indicating the update process and handles errors gracefully. update_os_pkg() { - case ${ADJUSTED_ID} in + case "${ADJUSTED_ID}" in debian) - if [ "$(find /var/lib/apt/lists/* -maxdepth 1 -check_cmd f 2>/dev/null | wc -l)" -eq 0 ]; then + if [ "$(find /var/lib/apt/lists/ -mindepth 1 -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 && @@ -304,7 +315,7 @@ install_pkg() { pkg_name="$1" if ! check_command "${pkg_name}"; then - case ${ADJUSTED_ID} in + case "${ADJUSTED_ID}" in debian) "${PKG_MGR_CMD}" update && "${INSTALL_CMD}" "${pkg_name}" ;; diff --git a/README.md b/README.md index 0097149..b84862d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://img.shields.io/github/license/gvatsal60/Linux-All-In-One-Update-Script) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/gvatsal60/Linux-All-In-One-Update-Script/master.svg)](https://results.pre-commit.ci/latest/github/gvatsal60/Linux-All-In-One-Update-Script/HEAD) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/fea72725a4634b089781f18915e01c21)](https://app.codacy.com/gh/gvatsal60/Linux-All-In-One-Update-Script/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![CodeFactor](https://www.codefactor.io/repository/github/gvatsal60/linux-all-in-one-update-script/badge)](https://www.codefactor.io/repository/github/gvatsal60/linux-all-in-one-update-script) [![GitHub pull-requests](https://img.shields.io/github/issues-pr/gvatsal60/Linux-All-In-One-Update-Script.svg)](https://GitHub.com/gvatsal60/Linux-All-In-One-Update-Script/pull/) [![GitHub issues](https://img.shields.io/github/issues/gvatsal60/Linux-All-In-One-Update-Script.svg)](https://GitHub.com/gvatsal60/Linux-All-In-One-Update-Script/issues/)