Skip to content

This script finds and removes orphaned snap packages on a Linux system, unless they serve as a default provider for another snap package.

Notifications You must be signed in to change notification settings

Mylinde/orphand_snaps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

Orphaned Snap Packages Remover

Description

Removes orphaned snap packages unless they are default providers or bases; also removes disabled snaps. Provides:

  • Bash and Fish scripts
  • Installer that places the script in /usr/local/bin
  • systemd service and weekly timer
  • Supports sudo or doas (auto-detect, overridable)

How it works

  1. The script uses snap connections to find all snap packages that have no connections (i.e. are orphaned).
  2. It filters out themes and slot-based connections.
  3. It extracts the package names from the output and stores them in the orphan variable.
  4. It checks if any of the orphaned packages are default providers for other packages by parsing the snap.yaml files.
  5. If an orphaned package is a default provider, it will not be removed.
  6. Otherwise, the script will remove the orphaned package using sudo snap remove.

Usage

  1. Save this script as a file (e.g. orphand_snaps)
  2. Make the script executable with chmod +x remove_orphaned_snaps
  3. Run the script with ./orphand_snaps

optional Installation

Bash:

# Install (auto-detect doas/sudo; override with set -x OVERRIDE_ELEVATION=doas|sudo)
orphand_snaps install

# Uninstall
orphand_snaps uninstall

Fish:

# Install (auto-detect doas/sudo; override with set -x OVERRIDE_ELEVATION=doas|sudo)
orphand_snaps install

# Uninstall
orphand_snaps uninstall

Undo

The last run records removed snaps to:

  • State file: /var/lib/orphand_snaps/last_removed.txt

Usage:

# List snaps removed in the last run
orphand_snaps undo

# Reinstall a single snap
orphand_snaps undo SNAPNAME

# Reinstall all snaps removed in the last run
orphand_snaps undo all

Notes

  • Be careful when running this script, as it will permanently remove packages without prompting for confirmation.

About

This script finds and removes orphaned snap packages on a Linux system, unless they serve as a default provider for another snap package.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages