Skip to content

Instantly share code, notes, and snippets.

@anonymouse64
Last active November 4, 2021 19:41
Show Gist options
  • Save anonymouse64/3a4c6a20500e51d217fbd7994838df02 to your computer and use it in GitHub Desktop.
Save anonymouse64/3a4c6a20500e51d217fbd7994838df02 to your computer and use it in GitHub Desktop.
snap debug base-declaration jq slot allow-installation examples
#!/bin/bash
# NOTE: the following commands are rather simplistic and ignore the logic around deny-installation, which should also hypothetically affect these lists, but really taking that into account requires more logic than I'm willing to put into a jq command
echo ">>> GADGET SNAP SLOT INTERFACES <<<"
echo
# Get all slots that can be used on a gadget snap specifically
snap debug base-declaration | \
head -n -1 | \
yaml2json | \
jq -r '.slots | map_values(select( ( ."allow-installation" | type == "object" ) and ( ."allow-installation"."slot-snap-type" | index("gadget") != null ) ) ) | keys | .[]'
echo
echo ">>> APP SNAP SLOT INTERFACES <<<"
echo
# Get all slots that can be used on an app snap specifically
snap debug base-declaration | \
head -n -1 | \
yaml2json | \
jq -r '.slots | map_values(select( ( ."allow-installation" | type == "object" ) and ( ."allow-installation"."slot-snap-type" | index("app") != null ) ) ) | keys | .[]'
echo
echo ">>> SYSTEM SNAP SLOT INTERFACES <<<"
echo
# Get all slots that can be used on core/system specifically
snap debug base-declaration | \
head -n -1 | \
yaml2json | \
jq -r '.slots | map_values(select( ( ."allow-installation" | type == "object" ) and ( ."allow-installation"."slot-snap-type" | index("core") != null ) ) ) | keys | .[]'
echo
echo ">>> ANY SNAP SLOT INTERFACES <<<"
echo
# Get all slots that can be used on any kind of snap (i.e. are totally unconstrained) - this is currently not used at all, every interface currently has a slot allow-installation rule on it
snap debug base-declaration | \
head -n -1 | \
yaml2json | \
jq -r '.slots | map_values(select( (has("allow-installation") | not) or ( ."allow-installation" == null ) or ( ."allow-installation" == true) ) ) | keys | .[]'
echo
echo ">>> SUPER-PRIVILEGED SNAP SLOT INTERFACES <<<"
echo
# These interfaces are not allowed to be slotted at all, and as such are considered super-privileged, since they need a snap-declaration in order to be installed as a slot at all on any snap.
snap debug base-declaration | \
head -n -1 | \
yaml2json | \
jq -r '.slots | map_values(select( ."allow-installation" == false ) ) | keys | .[]'
# Now the full set for each type (any, gadget, app, and core) is given by the union between the any group and each of the specific groups above
# TODO: actually do the unions, for now it is unnecessary since ANY is empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment