Skip to content

Automatically marks Debian/Ubuntu packages as auto-installed, which may help reduce conflicts during dist-upgrade.

Notifications You must be signed in to change notification settings

raohwork/apt-aggressive-mark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

apt-aggressive-mark

Automatically marks Debian/Ubuntu packages as auto-installed, which may help reduce conflicts during dist-upgrade.

Problem

During dist-upgrade, you may encounter package conflicts when the packaging structure changes:

1. Package Split/Merge Conflicts

When packages are split or merged between releases, APT cannot automatically handle the transition if the old package is marked as manually installed. This causes conflicts because APT cannot remove the old package to install the new one.

Example: Package foo, which is depends by an iportant package bar, is split into foo-core and foo-utils. If foo is manually installed, APT cannot automatically remove it and install the split packages.

2. Library Repackaging

Libraries often get renamed with version numbers (e.g., libssl1.1 to libssl3). Manually installed old versions accumulate over time and cannot be auto-removed, even when no longer needed.

3. Transitional Package Cleanup

Transitional packages are temporary packages used during upgrades to help migration. If marked as manually installed, they remain on the system indefinitely after serving their purpose.

Solution

This tool marks packages as automatically installed when they are dependencies of other packages, while preserving your explicitly chosen packages (whitelist). This may help APT's dependency resolver better handle package reorganization during upgrades.

Key behavior:

  • Packages with reverse dependencies (depended upon by other packages) -> marked auto
  • Packages in whitelist -> remain manual
  • Orphaned packages (not depended upon by anything) -> remain manual

In most cases, this means apt-get autoremove will not remove any packages, but package reorganization during upgrades may work more smoothly.

How It Works

  1. Reads your whitelist configuration
  2. Queries all manually installed packages
  3. For each manual package, checks if other packages depend on it
  4. Marks packages with dependencies (but not in whitelist) as auto
  5. Orphaned packages remain manual to prevent accidental removal

Installation

git clone https://github.com/raohwork/apt-aggressive-mark.git
cd apt-aggressive-mark
chmod +x apt-aggressive-mark

# Copy example config
cp config.example ~/.config/apt-aggressive-mark.conf

Or download directly:

wget https://raw.githubusercontent.com/raohwork/apt-aggressive-mark/main/apt-aggressive-mark
chmod +x apt-aggressive-mark

Usage

Dry-run (recommended first):

./apt-aggressive-mark --dry-run

Actually execute:

sudo ./apt-aggressive-mark

Common options:

# Dry-run with package list
./apt-aggressive-mark --dry-run --list-manual

# Verbose output for debugging
./apt-aggressive-mark --dry-run --verbose

# Use custom config file
./apt-aggressive-mark --config /path/to/config

# Execute and show resulting manual packages
sudo ./apt-aggressive-mark --list-manual

All options:

-h, --help              Show help message
-c, --config CONFIG     Specify config file path
-d, --dry-run           Show what would be done without modifying
-v, --verbose           Show detailed execution process
-l, --list-manual       List all manual packages after execution
--skip-safety-check     Skip safety check (not recommended)

Configuration

Create ~/.config/apt-aggressive-mark.conf or /etc/apt-aggressive-mark.conf:

# List packages that must remain manually installed
# These are tools you explicitly need for your work

# Text editors
vim

# Terminal tools
tmux
htop

# Version control
git

# Network tools
curl
wget

# Development tools
build-essential

Important: Only list tools you actively use. Do not list system packages like linux-image-amd64 unless you are extremly sure the package will still be there in the future.

Safety

The tool includes multiple safety checks:

  1. Whitelist verification - Refuses to run if whitelist is empty
  2. Orphaned package protection - Avoids marking packages that nothing depends on
  3. Autoremove simulation - Attempts to verify that apt-get autoremove will not remove packages after marking
  4. Dry-run mode - Test without making changes

If safety checks fail, the tool stops and displays detailed error messages. However, users should still review changes carefully before applying them on critical systems.

Examples

Before dist-upgrade:

sudo apt-aggressive-mark
sudo apt-get dist-upgrade

Regular maintenance:

sudo apt-aggressive-mark
sudo apt-get autoremove

First-time use workflow:

# 1. Check current state
apt-mark showmanual | wc -l

# 2. Configure whitelist
cp config.example ~/.config/apt-aggressive-mark.conf
vim ~/.config/apt-aggressive-mark.conf

# 3. Test
./apt-aggressive-mark --dry-run --list-manual

# 4. Execute
sudo ./apt-aggressive-mark --list-manual

# 5. Verify
apt-mark showmanual | wc -l  # Should typically be less
apt-get autoremove --dry-run  # Should typically show no removals

FAQ

Q: Will this remove any packages?

A: No. The tool only changes package marks (manual/auto). It never removes packages. After running, apt-get autoremove should typically show zero packages to remove (if your whitelist is properly configured).

Q: What if I need to revert?

A: Mark packages back to manual:

apt-mark manual package-name

Q: What should be in my whitelist?

A: Only packages you explicitly installed for your own use:

  • Text editors you use
  • Command-line tools you use
  • Development tools you installed
  • Applications you installed

Do not include unless you know what you are doing:

  • System packages (kernel, bootloader, init system)
  • Libraries
  • Dependencies

Q: Why did the safety check fail?

A: Your whitelist may be incomplete. Run with --verbose to see which packages would be removed, then add necessary packages to your whitelist.

Q: Does this affect auto-installed packages?

A: No. It only processes manually installed packages.

Q: Can I use this on production servers?

A: It's possible, but always test with --dry-run first. The tool is designed with safety in mind and includes multiple checks, but as with any system modification tool, caution is advised.

Requirements

  • Python 3 (standard library only)
  • APT package management system
  • Root privileges for execution (not for dry-run)

License

GPLv3

Contributing

Issues and pull requests are welcome.

References

About

Automatically marks Debian/Ubuntu packages as auto-installed, which may help reduce conflicts during dist-upgrade.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages