Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
29 changes: 20 additions & 9 deletions .update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
gvatsal60 marked this conversation as resolved.
fi

# Check if no snaps are installed (only header line present)
if [ "$(echo "${snap_output}" | wc -l)" -le 1 ]; then
Comment thread
gvatsal60 marked this conversation as resolved.
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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Comment thread
gvatsal60 marked this conversation as resolved.
println "Updating ${PKG_MGR_CMD} based packages..."
if ! ("${PKG_MGR_CMD}" update -y &&
"${PKG_MGR_CMD}" upgrade -y &&
Expand Down Expand Up @@ -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}"
;;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down