Skip to content

Instantly share code, notes, and snippets.

@OndraZizka
Created September 30, 2025 13:15
Show Gist options
  • Select an option

  • Save OndraZizka/002e97f56ff4e645103ccc279d17b194 to your computer and use it in GitHub Desktop.

Select an option

Save OndraZizka/002e97f56ff4e645103ccc279d17b194 to your computer and use it in GitHub Desktop.
Regenerate Snap profiles (Ubuntu)
#!/bin/bash
## Get a list of all installed snaps, filtering out the system core components.
## The 'snap list' command outputs a table; awk is used to extract the snap name (first column)
## and 'tail -n +2' skips the header line.
## 'grep -v' filters out the core system snaps like core, core18, snapd, etc.
SNAP_LIST=$(snap list | tail -n +2 | awk '{print $1}' | grep -v 'core\|snapd\|gtk-common-themes\|gnome-3-38-2004\|kde-frameworks-5-99-qt-5-15-8-core20\|content')
echo "Starting AppArmor profile regeneration for all user-installed snaps..."
echo "---------------------------------------------------------------------"
for SNAP_NAME in $SNAP_LIST; do
echo "Processing $SNAP_NAME..."
# 1. Disable the snap
if sudo snap disable "$SNAP_NAME"; then
echo " - Disabled successfully."
else
echo " - FAILED to disable. Skipping to next."
continue # Skip to the next snap if disable fails
fi
# 2. Enable the snap
if sudo snap enable "$SNAP_NAME"; then
echo " - Enabled successfully. Profile should be regenerated."
else
echo " - FAILED to enable. This snap may still be broken."
fi
echo
done
echo "---------------------------------------------------------------------"
echo "Batch profile regeneration complete."
echo "You may now try to run your other Snap applications."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment