Skip to content

Commit 3df1580

Browse files
authored
Fixed: No snap installed print (#83)
2 parents 8fc0fcd + eed0fd4 commit 3df1580

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
}
5353
}
5454
},
55-
"image": "mcr.microsoft.com/devcontainers/javascript-node",
55+
"image": "mcr.microsoft.com/devcontainers/base:debian",
5656
"mounts": [
5757
"source=${localWorkspaceFolder}/snippets,target=${containerWorkspaceFolder}/.vscode,type=bind,consistency=cached"
5858
],

.update.sh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,28 @@ cleanup_snapd() {
8181

8282
rm -rf /var/lib/snapd/cache/*
8383

84-
# List all snaps and filter for disabled ones
85-
snap list --all | awk '/disabled/{print $1, $3}' | while read -r snapname revision; do
84+
# Get snap list output once and store it
85+
if ! snap_output=$(snap list --all); then
86+
print_err "Error: Failed to retrieve snap list."
87+
return
88+
fi
89+
90+
# Check if no snaps are installed (only header line present)
91+
if [ "$(echo "${snap_output}" | wc -l)" -le 1 ]; then
92+
return
93+
fi
94+
95+
# Process the stored output to find disabled snaps
96+
echo "${snap_output}" | awk '/disabled/{print $1, $3}' | while read -r snap_name revision; do
8697
# Check if variables are set and not empty
87-
if [ -z "$snapname" ] || [ -z "$revision" ]; then
98+
if [ -z "${snap_name}" ] || [ -z "${revision}" ]; then
8899
print_err "Error: Snap name or revision is empty. Skipping..."
89100
continue
90101
fi
91102

92103
# Attempt to remove the snap revision
93-
if ! snap remove "$snapname" --revision="$revision"; then
94-
print_err "Error: Failed to remove $snapname (revision $revision)."
104+
if ! snap remove "${snap_name}" --revision="${revision}"; then
105+
print_err "Error: Failed to remove ${snap_name} (revision ${revision})."
95106
fi
96107
done
97108
}
@@ -102,7 +113,7 @@ cleanup_snapd() {
102113
# Provides output to indicate the cleanup process and handles errors gracefully.
103114
# Usage: Call this function to automate system cleanup tasks after updating the system.
104115
clean_up() {
105-
case ${ADJUSTED_ID} in
116+
case "${ADJUSTED_ID}" in
106117
debian)
107118
# rm -rf /var/lib/apt/lists/*
108119
cleanup_snapd
@@ -140,9 +151,9 @@ update_snapd() {
140151
# Supports Debian-based (apt-get), RPM-based (dnf/yum/microdnf), and Alpine (apk) package managers.
141152
# Prints messages indicating the update process and handles errors gracefully.
142153
update_os_pkg() {
143-
case ${ADJUSTED_ID} in
154+
case "${ADJUSTED_ID}" in
144155
debian)
145-
if [ "$(find /var/lib/apt/lists/* -maxdepth 1 -check_cmd f 2>/dev/null | wc -l)" -eq 0 ]; then
156+
if [ "$(find /var/lib/apt/lists/ -mindepth 1 -maxdepth 1 -type f 2>/dev/null | wc -l)" -eq 0 ]; then
146157
println "Updating ${PKG_MGR_CMD} based packages..."
147158
if ! ("${PKG_MGR_CMD}" update -y &&
148159
"${PKG_MGR_CMD}" upgrade -y &&
@@ -304,7 +315,7 @@ install_pkg() {
304315
pkg_name="$1"
305316

306317
if ! check_command "${pkg_name}"; then
307-
case ${ADJUSTED_ID} in
318+
case "${ADJUSTED_ID}" in
308319
debian)
309320
"${PKG_MGR_CMD}" update && "${INSTALL_CMD}" "${pkg_name}"
310321
;;

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![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)
44
[![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)
5+
[![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)
56
[![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)
67
[![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/)
78
[![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/)

0 commit comments

Comments
 (0)