### Initial hello-world example: snapcraft.yaml and hello.sh Source: https://snapcraft.io/docs/reference/interfaces/ros-opt-data-interface The initial hello-world example snap, before adding ros-opt-data. The snapcraft.yaml defines a simple dump-based snap, and hello.sh just prints "hello world". These two files are shown as the starting point for the tutorial. ```yaml name: hello-world version: '0.1' summary: A simple hello world application description: | A simple hello world application. base: core22 grade: devel confinement: strict apps: hello-world: command: ./hello.sh parts: hello-world: plugin: dump source: files ``` ```bash #!/bin/bash echo "hello world" ``` -------------------------------- ### Download a snap and its assertions with snap download Source: https://snapcraft.io/docs/explanation/security/assertions Example of using the `snap download` command to fetch a snap and its assertions. The output shows the download progress and instructions to install the snap using `snap ack` and `snap install`. ```bash $ snap download gnome-calculator Fetching snap "gnome-calculator" Fetching assertions for "gnome-calculator" Install the snap with: snap ack gnome-calculator_945.assert snap install gnome-calculator_945.snap ``` -------------------------------- ### Install the core snap Source: https://snapcraft.io/docs/tutorials/install-the-daemon/raspberrypios Install the core snap to get the latest snapd. The expected output is shown. ```bash $ sudo snap install core core 16-2.45.2 from Canonical✓ installed ``` -------------------------------- ### Autostart desktop file example with snap.yaml and startup command Source: https://snapcraft.io/docs/reference/development/yaml-schemas/the-snap-format The snap.yaml sets the 'autostart' property to 'my-chat.desktop'. The desktop file in $SNAP_USER_DATA/.config/autostart provides the Exec line. The application is started as 'my-chat.chat --autostart a b c'. ```yaml name: my-chat version: 1.0 apps: chat: command: bin/my-chat autostart: my-chat.desktop ``` ```ini [Desktop Entry] Name=My Chat Exec=/usr/bin/my-chat --autostart a b c ``` ```text my-chat.chat --autostart a b c ``` -------------------------------- ### snapctl system-mode command and example output Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-snapctl Returns YAML-formatted details about specific system states, including the current system mode, whether seeded snaps have finished installing, and whether the factory image hint is set. The output shown is an example of a UC20+ system in install mode with the factory hint enabled. ```bash $ snapctl system-mode system-mode: install seed-loaded: true factory: true ``` -------------------------------- ### snap list output showing install modes Source: https://snapcraft.io/docs/explanation/snap-development/install-modes Example output of the snap list command showing the install mode in the Notes column. The Notes column displays devmode for snaps installed in developer mode and classic for classic snaps. ```text Name Version Rev Tracking Publisher Notes liquidctl 1.7.1-11-g6295354 1 latest/stable morrisong devmode snapcraft 5.0 6751 latest/stable canonical✓ classic ``` -------------------------------- ### snap debug timings --last=install output (cache and fresh install) Source: https://snapcraft.io/docs/explanation/how-snaps-work/snap-performance Example output from `snap debug timings --last=install` after installing the Chromium snap, first from cache and then fresh install. The `Doing` column shows task execution times. ```text ID Status Doing Undoing Label Summary 160241 Done 461ms - prerequisites Ensure prerequisites for "chromium" are available ^ 353ms - install-prereq install "cups" ^ 12ms - install-prereq install base "core22" 160242 Done 62ms - download-snap Download snap "chromium" (2556) from channel "stable" 160243 Done 607ms - validate-snap Fetch and check assertions for snap "chromium" (2556) 160244 Done 2253ms - mount-snap Mount snap "chromium" (2556) ^ 75ms - check-snap check snap "chromium" ^ 2059ms - setup-snap setup snap "chromium" 160245 Done 61ms - copy-snap-data Copy snap "chromium" data 160246 Done 241ms - setup-profiles Setup snap "chromium" (2556) security profiles ^ 32ms - setup-security-backend setup security backend "seccomp" for snap "chromium" ^ 133ms - setup-security-backend[many] setup security backend "apparmor" for 1 snaps ^ 101ms - load-profiles[changed-many] load changed security profiles of 1 snaps 160247 Done 396ms - link-snap Make snap "chromium" (2556) available to the system ^ 8ms - generate-wrappers generate wrappers for snap chromium ^ 290ms - update-fc-cache update font config caches 160248 Done 388ms - auto-connect Automatically connect eligible plugs and slots of snap "chromium" 160267 Done 92ms - connect Connect chromium:u2f-devices to snapd:u2f-devices ``` -------------------------------- ### Install snap from explicit channel Source: https://snapcraft.io/docs/explanation/how-snaps-work/channels-and-tracks Installs a snap from an explicitly specified channel. Here, 'latest/edge' is used as an example, but any valid channel can be specified. ```bash snap install vlc --channel=latest/edge ``` -------------------------------- ### Install snap components with snap install Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/using-components Installs the snap my-snap along with components comp1 and comp2. If the snap is already installed, only the missing components are installed. The syntax ++...+ is used to refer to components from the command line. ```bash snap install my-snap+comp1+comp2 ``` -------------------------------- ### Test snap installation with hello-world Source: https://snapcraft.io/docs/tutorials/install-the-daemon/arch-linux Installs the hello-world snap and runs it to verify the system is set up correctly. ```bash $ sudo snap install hello-world hello-world 6.3 from Canonical✓ installed $ hello-world Hello World! ``` -------------------------------- ### Install snaps as a single transaction with --transaction=all-snaps Source: https://snapcraft.io/docs/explanation/how-snaps-work/transactional-updates Installs the hello and hello-world snaps as a single transaction using the --transaction=all-snaps argument. The output shows both snaps installed successfully, but no change, log, or message indicates that the set was installed as a single transaction. ```bash $ snap install hello hello-world --transaction=all-snaps hello-world 6.4 from Canonical✓ installed hello 2.10 from Canonical✓ installed ``` -------------------------------- ### Install snap file with --name instance key Source: https://snapcraft.io/docs/explanation/how-snaps-work/parallel-installs Install a snap from a local .snap file with an explicit instance key. The --name flag sets the instance name (snap_instance) when installing from a file. ```bash sudo snap install --name hello-world_foo hello-world_27.snap ``` -------------------------------- ### Install an unpacked snap with snap try Source: https://snapcraft.io/docs/how-to-guides/snap-development/snap-try Installs an unpacked snap using a bind mount. The output shows the snap being mounted and the location of the installed command. ```bash $ snap try squashfs-root hello-world 6.4 mounted from /home/user/squashfs-root $ which hello-world /snap/bin/hello-world ``` -------------------------------- ### GET request to /v2/apps with jq formatting Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-the-rest-api This example sends a GET request to the /v2/apps endpoint and pipes the response through jq for formatting. The output shows a JSON object with type sync, status-code 200, and a result array containing snap details. Use this to retrieve and inspect the list of installed snaps. ```bash $ sudo curl -sS --unix-socket /run/snapd.socket http://localhost/v2/apps \ | jq { "type": "sync", "status-code": 200, "status": "OK", "result": [ { "snap": "anbox-installer", "name": "anbox-installer" } ] } ``` -------------------------------- ### snapcraft edit-validation-sets example Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/manage-validation-sets Example command using a sample account ID, set name 'myset1', and sequence 1. The sequence number starts at 1. ```bash snapcraft edit-validation-sets xSfWKGdLoQBoQx88vIM1MpbFNMq53t1f myset1 1 ``` -------------------------------- ### snap install hello-world --revision 27 Source: https://snapcraft.io/docs/explanation/how-snaps-work/revisions Installs revision 27 of the hello-world snap. The output confirms the installed revision. ```bash $ snap install hello-world --revision 27 hello-world 6.3 from Canonical✓ installed ``` -------------------------------- ### Install Snapcraft Source: https://snapcraft.io/docs/snapcraft-overview Installs Snapcraft as a snap with classic confinement. ```bash snap install snapcraft --classic ``` -------------------------------- ### Install snap from beta channel Source: https://snapcraft.io/docs/explanation/how-snaps-work/channels-and-tracks Installs VLC from the beta risk-level. If the beta snap is not available, the snap is installed from the closest channel with a more stable risk-level. ```bash sudo snap install --channel=beta vlc ``` -------------------------------- ### Install multiple snap instances with instance key Source: https://snapcraft.io/docs/explanation/how-snaps-work/parallel-installs Install two instances of the hello-world snap in one command. The second instance uses the instance key 'foo' appended with an underscore. Each instance is isolated from the others. ```bash sudo snap install hello-world hello-world_foo ``` -------------------------------- ### Install snapd on openSUSE Source: https://snapcraft.io/docs/tutorials/install-the-daemon/opensuse Installs the snapd package using zypper. ```bash sudo zypper install snapd ``` -------------------------------- ### Start and enable a service Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/control-services Starts a service and re-enables its automatic start on system boot. ```bash snap start --enable lxd.daemon ``` -------------------------------- ### Install Snapd from beta channel Source: https://snapcraft.io/docs/reference/release-notes Use this command to install Snapd from the beta channel. This is useful for testing beta releases. ```bash sudo snap refresh snapd --beta ``` -------------------------------- ### Install snapd with pacman Source: https://snapcraft.io/docs/tutorials/install-the-daemon/manjaro-linux Installs the snapd package from the command line. Run this if snap is not already installed or has been removed. ```bash sudo pacman -S snapd ``` -------------------------------- ### Install components from local files with --dangerous flag Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/using-components Installs components from a local file. Unasserted components can only be installed if the host snap is unasserted too, and the --dangerous flag is required. ```bash snap install --dangerous ./my-snap+comp1+comp2_1.0.comp ``` -------------------------------- ### snap info output with revision numbers Source: https://snapcraft.io/docs/explanation/how-snaps-work/revisions Example output of `snap info ` showing revision numbers in brackets after the publishing date for each channel. The installed revision appears on the final line. ```text channels: latest/stable: 2.59.4 2023-05-31 (19361) 55MB - latest/candidate: 2.59.5 2023-06-09 (19457) 55MB - latest/beta: 2.59.5 2023-05-27 (19457) 55MB - latest/edge: 2.59.5+git955.gc9310cc 2023-06-13 (19535) 42MB - installed: 2.59.1+git798.g5f761c7 (19131) 42MB snapd ``` -------------------------------- ### Install LXD Source: https://snapcraft.io/docs/snapcraft-overview Installs LXD, the build provider that containerizes the build environment. ```bash snap install lxd ``` -------------------------------- ### Install snapd from command line Source: https://snapcraft.io/docs/tutorials/install-the-daemon/linux-mint Installs snapd via the command line as an alternative to using the Software Manager. ```bash sudo apt install snapd ``` -------------------------------- ### Enable snapd.apparmor.service for confinement Source: https://snapcraft.io/docs/tutorials/install-the-daemon/arch-linux Enables and starts the AppArmor service for snap confinement. Requires AppArmor to be installed and enabled first. ```bash sudo systemctl enable --now snapd.apparmor.service ``` -------------------------------- ### Test changes to an unpacked snap Source: https://snapcraft.io/docs/how-to-guides/snap-development/snap-try Shows how changes to files in the squashfs-root directory are immediately reflected in the installed snap. The example edits the bin/echo script and runs the snap again to see the updated output. ```bash $ hello-world Hello world! $ sed -i 's/World/Everyone/g' /home/user/squashfs-root/bin/echo $ hello-world Hello Everyone! ``` -------------------------------- ### Connect personal-files plug with snap connect Source: https://snapcraft.io/docs/reference/interfaces/personal-files-interface Connects the dot-config-foo plug to enable access to the personal files declared in the snapcraft.yaml example. Use this command after the snap is installed to grant the snap access to the specified home directory files. ```shell snap connect foo:dot-config-foo ``` -------------------------------- ### Example snapcraft.yaml for hello-docker snap Source: https://snapcraft.io/docs/reference/interfaces/docker-interface Defines a strictly confined snap with the hello-docker app, using the docker and docker-executables plugs. The docker-executables plug is a content interface that requires an empty directory named docker-snap in the snap's image. The default-provider field ensures the docker snap is installed and connected automatically if not present. ```yaml base: core22 confinement: strict apps: hello-docker: command: usr/bin/hello-docker environment: PATH: $SNAP/docker-snap/bin:$PATH plugs: - docker - docker-executables plugs: docker: label: Access to the docker communication socket docker-executables: label: Access to the docker command-line utilities interface: content content: docker-executables target: $SNAP/docker-snap default-provider: docker ``` -------------------------------- ### snap list output with Rev column Source: https://snapcraft.io/docs/explanation/how-snaps-work/revisions Example output of `snap list` showing the `Rev` column with each installed snap's revision number. ```text Name Version Rev Tracking Publisher Notes alacritty 0.8.0 46 latest/stable snapcrafters✪ classic blender 3.5.0 3486 latest/stable blenderfoundation✓ classic chromium 112.0 2424 latest/stable canonical✓ - ffmpeg 4.3.1 1286 latest/stable snapcrafters✪ - ``` -------------------------------- ### Install build dependencies Source: https://snapcraft.io/docs/explanation/snap-development/building-snap-rpms-on-rhel Refresh the package list and install the Go toolset and rpmdevtools, which are needed for building snap RPMs. ```bash $ sudo dnf upgrade $ sudo dnf module install go-toolset $ sudo dnf install rpmdevtools ``` -------------------------------- ### Declare network and network-bind plugs in snapcraft.yaml Source: https://snapcraft.io/docs/reference/interfaces/network-interface Example snapcraft.yaml configuration declaring the network plug for a client application and both network and network-bind plugs for a frontend server application. Both interfaces auto-connect on installation and require no additional store review. ```yaml apps: client: command: bin/client-application plugs: - network frontend: command: bin/server-application plugs: - network - network-bind ``` -------------------------------- ### fde-setup features operation example Source: https://snapcraft.io/docs/reference/development/uc20-fde-hooks Example of the fde-setup hook handling the "features" operation. The hook calls snapctl fde-setup-request, reads the JSON from stdout, and reports an empty features list via snapctl fde-setup-result. ```shell $ snapctl fde-setup-request {"op":"features"} $ echo '{"features": []}' | snapctl fde-setup-result ``` -------------------------------- ### Install snapd from AUR using git clone and makepkg Source: https://snapcraft.io/docs/tutorials/install-the-daemon/arch-linux Manual build process for installing snap from the Arch User Repository. Requires the prerequisites for building AUR packages to be installed first. ```bash git clone https://aur.archlinux.org/snapd.git cd snapd makepkg -si ``` -------------------------------- ### Install snapd package Source: https://snapcraft.io/docs/tutorials/install-the-daemon/almalinux-os Installs the snapd package from the EPEL repository. Requires root or sudo privileges. ```bash sudo dnf install snapd ``` -------------------------------- ### Example configure hook shell script Source: https://snapcraft.io/docs/reference/development/supported-snap-hooks Shell script for the configure hook that retrieves username and password via snapctl get, validates them, and writes credentials to $SNAP_DATA/options. Exits with non-zero status if required values are missing. ```sh #!/bin/sh -e username="$(snapctl get username)" password="$(snapctl get password)" if [ -z "$username" -o -z "$password" ]; then echo "Username and password are required." exit 1 fi mkdir -m 0600 $SNAP_DATA/options echo "username: $username" > $SNAP_DATA/options/credentials echo "password: $password" >> $SNAP_DATA/options/credentials ``` -------------------------------- ### Install snap from stable channel Source: https://snapcraft.io/docs/explanation/how-snaps-work/channels-and-tracks Installs VLC from the default stable risk-level. Use this command when you want the default stable release. ```bash sudo snap install vlc ``` -------------------------------- ### List all components with snap components Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/using-components Lists the components installed and available on the system. The output shows the component name, status, and type. ```bash $ snap components Component Status Type snap-with-comps+one installed standard snap-with-comps+two installed standard snap-with-comps+three available standard other-snap-with-comps+one installed standard other-snap-with-comps+two installed standard other-snap-with-comps+three available standard ``` -------------------------------- ### snapctl get syntax Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-snapctl Shows the basic syntax for querying a configuration option with snapctl get. ```bash snapctl get ``` -------------------------------- ### snap debug timings --verbose output Source: https://snapcraft.io/docs/explanation/how-snaps-work/snap-performance Example output from `snap debug timings --verbose` showing a label column for the change. The `--last` argument can be used with names like `auto-refresh`, `install`, `refresh`, `remove`, or `try`. ```text ID Status Doing Undoing Label Summary 160162 Done 750ms - prerequisites Ensure prerequisites for "chromium" are available ^ 681ms - install-prereq install "cups" ``` -------------------------------- ### Refresh snap and install component simultaneously Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/using-components Refreshes the snap my-snap and installs the component comp1 at the same time. ```bash snap refresh my-snap+comp1 ``` -------------------------------- ### Test snapd with hello-world Source: https://snapcraft.io/docs/explanation/snap-development/building-snap-rpms-on-rhel Test the snapd environment by installing the hello-world snap. A reboot/logout should put hello-world in the path. ```bash $ snap install hello-world ``` -------------------------------- ### Enable and start snapd service Source: https://snapcraft.io/docs/tutorials/install-the-daemon/opensuse Enables and starts the snapd service. After this, reboot, logout/login, or source /etc/profile to add /snap/bin to PATH. ```bash sudo systemctl enable --now snapd ``` -------------------------------- ### Fetch sources and install build dependencies Source: https://snapcraft.io/docs/explanation/snap-development/building-snap-rpms-on-rhel Fetch remaining release packages and install build dependencies using the snapd spec file. ```bash $ spectool -g ~/rpmbuild/SOURCES/snapd.spec $ sudo dnf builddep ~/rpmbuild/SPECS/snapd.spec -y ``` -------------------------------- ### Install snapd on Elementary OS Source: https://snapcraft.io/docs/tutorials/install-the-daemon/elementary-os Run these commands in Terminal to update the package list and install snapd. After installation, log out and back in or restart to update snap's paths. ```bash sudo apt update sudo apt install snapd ``` -------------------------------- ### Install and revert a test snapd build Source: https://snapcraft.io/docs/how-to-guides/snap-development/test-snapd-fixes Install a test snapd from a downloaded artifact: unzip the snap-files archive, install the resulting snap with --dangerous, and later revert to the stable channel with snap refresh --stable --amend. ```bash $ unzip snap-files.zip Archive: snap-files.zip inflating: snapd_2.53.2+git6345be5.6345be5-dirty_amd64.snap ``` ```bash $ snap install --dangerous snapd_2.53.2+git6345be5.6345be5-dirty_amd64.snap 2021-11-24T13:06:46Z INFO Waiting for automatic snapd restart... snapd 2.53.2+git6345be5.6345be5-dirty installed ``` ```bash $ snap refresh snapd --stable --amend ``` -------------------------------- ### Example default-configure hook script Source: https://snapcraft.io/docs/reference/development/supported-snap-hooks A shell script for the default-configure hook. It retrieves a gadget option using snapctl get, applies a default value if unset, creates a directory with mode 0600, and writes the option to a file. The hook must be located in meta/hooks and requires a configure hook to be present. ```shell #!/bin/sh -e DEFAULT_GADGET_OPTION="123" gadget_option="$(snapctl get gadget-option)" if [ -z "$gadget_option" ]; then gadget_option="$DEFAULT_GADGET_OPTION" fi mkdir -m 0600 $SNAP_DATA/options echo "option: $gadget_option" > $SNAP_DATA/options/gadget ``` -------------------------------- ### View component details with snap component Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/using-components Displays information about an installed or available component. The installed: line is only printed if the component is installed. ```bash $ snap component qwen-vl+llamacpp component: qwen-vl+llamacpp type: standard summary: llama.cpp Engine using default CPU instruction sets description: | LLM inference in C/C++ installed: b5794 (240) 30MB ``` -------------------------------- ### Install snapd package Source: https://snapcraft.io/docs/tutorials/install-the-daemon/centos Install the snapd package using yum after adding the EPEL repository. ```bash sudo yum install snapd ``` -------------------------------- ### Show component summary with snap info Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/using-components Displays a summary of the ratio of installed components to available components. The summary is omitted if both installed and available components are zero. ```bash $ snap info qwen-vl name: qwen-vl summary: Qwen VL inference snap ... installed: 2.5 (248) 332MB - components: 4/14 ``` -------------------------------- ### Install strace-static snap Source: https://snapcraft.io/docs/how-to-guides/snap-development/debug-snaps Install the strace-static snap to enable running snaps under strace. Requires snapd 2.62. ```bash sudo snap install strace-static ``` -------------------------------- ### Install snap with --dangerous Source: https://snapcraft.io/docs/snapcraft-overview Installs the locally built snap with --dangerous because it is not from the Snap Store and thus not checked for safety. ```bash snap install ukuzama-pyfiglet_0.1_amd64.snap --dangerous ``` -------------------------------- ### Install snap-http Python package Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-the-rest-api Install the snap-http Python package, which provides a Python interface to the snapd REST API. After installation, refer to the snap-http repository for documentation and usage examples. ```bash pip install snap-http ``` -------------------------------- ### Install Juju 2.9 and 3.0 in parallel with --channel Source: https://snapcraft.io/docs/explanation/how-snaps-work/parallel-installs Install two instances of Juju on different channels/tracks. Each instance is installed separately with its own channel and instance key (juju_29, juju_30). The --classic flag is used for both. ```bash sudo snap install --channel 2.9/stable juju_29 --classic sudo snap install --channel 3.0/stable juju_30 --classic ``` -------------------------------- ### Build and serve live preview with make run Source: https://snapcraft.io/docs/contributing/local-development Builds and serves the documentation at http://127.0.0.1:8000/ with live reload on file changes. Use this command to start a local preview while editing. ```make make run ``` -------------------------------- ### Install snapd on Debian without sudo (as root) Source: https://snapcraft.io/docs/tutorials/install-the-daemon/debian Use these commands when sudo is not installed, typically because a root password was provided at install time. Switch to the root account first. ```bash $ su root # apt update # apt install snapd ``` -------------------------------- ### Gadget YAML connections example Source: https://snapcraft.io/docs/reference/development/yaml-schemas/the-gadget-snap Example connections section in a gadget.yaml, listing plug and slot pairs for account-control, network-manager, and shell-config-files. Use to declare interface connections for the gadget snap. ```yaml connections: - plug: LVkazk0JLrL0ivuHRlv3wp3bK1nAgwtN:account-control - plug: LVkazk0JLrL0ivuHRlv3wp3bK1nAgwtN:network-manager slot: RmBXKl6HO6YOC2DE4G2q1JzWImC04EUy:service - plug: LVkazk0JLrL0ivuHRlv3wp3bK1nAgwtN:shell-config-files slot: system:system-files ``` -------------------------------- ### Install snap into quota group Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/use-resource-quotas Installs a snap and adds it to an existing quota group. ```bash snap install snap1 --quota-group=mygroup ``` -------------------------------- ### Install snapd RPM packages Source: https://snapcraft.io/docs/explanation/snap-development/building-snap-rpms-on-rhel Install the three built RPM packages: snap-confine, snapd, and snapd-selinux. ```bash $ sudo dnf localinstall \ ~/rpmbuild/RPMS/x86_64/snap-confine-2.42-0.el8.x86_64.rpm \ ~/rpmbuild/RPMS/x86_64/snapd-2.42-0.el8.x86_64.rpm \ ~/rpmbuild/RPMS/noarch/snapd-selinux-2.42-0.el8.noarch.rpm ``` -------------------------------- ### Enable and start snapd.apparmor service Source: https://snapcraft.io/docs/tutorials/install-the-daemon/opensuse Enables and starts the snapd.apparmor service. Recommended to restart the machine after this step. ```bash sudo systemctl enable --now snapd.apparmor ``` -------------------------------- ### Initialize snap project with snapcraft init Source: https://snapcraft.io/docs/snapcraft-overview Runs the `snapcraft init` command to generate a template `snapcraft.yaml` file in the `snap/` directory. ```bash snapcraft init ``` -------------------------------- ### Simple snap.yaml with an app Source: https://snapcraft.io/docs/reference/development/yaml-schemas/the-snap-format An example snap.yaml that declares an application with a command. ```yaml name: simple version: 1.0 apps: hello: command: bin/hello --world ``` -------------------------------- ### Static Netplan configuration example Source: https://snapcraft.io/docs/reference/administration/system-options Example of a static network configuration for the system.network.netplan key. Shows the structure with addresses, gateway4, and nameservers for the enp0s2 device. This is the configuration that the subsequent snap set command modifies. ```json { "system.network.netplan": { "network": { "ethernets": { "enp0s2": { "addresses": [ "10.0.2.15/24" ], "gateway4": "10.0.2.2", "nameservers": { "addresses": [ "8.8.8.8", "8.8.4.4" ], "search": [] } } }, "version": 2 } } } ``` -------------------------------- ### Install font with -L Source: https://snapcraft.io/docs/snapcraft-overview Installs a font (Small Braille) from the figlet-fonts project. ```bash ukuzama-pyfiglet -L smbraille.tlf ``` -------------------------------- ### Install the snapd snap for latest features Source: https://snapcraft.io/docs/tutorials/install-the-daemon/debian After installing snapd and restarting the system, install the snapd snap to get the latest snapd. Some snaps may require new snapd features and show an error like 'snap "lxd" assumes unsupported features' if not updated. ```bash sudo snap install snapd ``` -------------------------------- ### Configure polkit interface with action-prefix and install-rules Source: https://snapcraft.io/docs/reference/interfaces/polkit-interface Snapcraft YAML configuration for the polkit interface. Sets the action-prefix to org.example.foo and installs a polkit rule file named polkit.bar.rules with its sha3-384 hash. The app named 'app' runs command 'foo' and plugs into the polkit interface. ```yaml plugs: polkit: action-prefix: org.example.foo install-rules: - name: polkit.bar.rules sha3-384: 2YM8oyXyE7xuXR07EXqUpixvr8duiJwgPQqhnxZgrBCU8ZSDowV0Gyujvs1j0-KR apps: app: command: foo plugs: [polkit] ``` -------------------------------- ### Install a snap in developer mode Source: https://snapcraft.io/docs/how-to-guides/snap-development/debug-snaps Install a snap with `--devmode` to permit security policy violations and log them via journald. ```bash sudo snap install --devmode mysnap ``` -------------------------------- ### Install secret-tool snap for testing Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-the-secret-portal Install the secret-tool snap from the store using the appropriate track depending on the base you want to test. Replace XX with the base version (e.g., 22 for core22). ```bash snap install secret-tool \--channel XX/stable to use coreXX base ``` -------------------------------- ### Install snappy-debug tool Source: https://snapcraft.io/docs/how-to-guides/snap-development/debug-snaps Install the snappy-debug tool, which watches syslog for policy violations and shows them in a human-readable format with recommendations. ```bash sudo snap install snappy-debug ``` -------------------------------- ### Enable experimental.parallel-instances feature flag Source: https://snapcraft.io/docs/explanation/how-snaps-work/parallel-installs Enable the experimental parallel-instances feature flag before attempting parallel installs. Without this, snap install fails if the same snap is already installed. Rebooting after toggling the flag is recommended to avoid namespace problems with already-run snap applications. ```bash sudo snap set system experimental.parallel-instances=true ``` -------------------------------- ### udev-tagging syntax example Source: https://snapcraft.io/docs/reference/interfaces/custom-device-interface Shows the udev-tagging syntax for the custom-device interface, mapping kernel, subsystem, and attributes to udev rules. The example uses two entries with different idVendor values. ```yaml udev-tagging: - kernel: hiddev0 subsystem: usb attributes: idVendor: "0x03f0" # HP - kernel: hiddev1 subsystem: usb attributes: idVendor: "0x03fc" # ECS ``` -------------------------------- ### snapctl mount --persistent example Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-snapctl Mount a persistent mount point with the `--persistent` option, using bind mount with read-write options. The example mounts /usr/share to /media/mount. ```bash $ snapctl mount --persistent -o bind,rw /usr/share /media/mount ``` -------------------------------- ### Basic timer examples Source: https://snapcraft.io/docs/reference/administration/timer-string-format Basic timer examples showing time ranges with frequency and a single time. Each line is a separate timer string with its own schedule. ```text 00:00-24:00/24 ``` ```text 00:00-24:00/48 ``` ```text 00:00-24:00/96 ``` ```text 12:00-13:00/12 ``` ```text 23:00 ``` -------------------------------- ### snap debug timings --startup=ifacemgr Source: https://snapcraft.io/docs/explanation/how-snaps-work/snap-performance Use the `--startup` argument with `snap debug timings` to output startup timing data for the `ifacemgr` subsystem. The output shows execution times for setting up security profiles for installed snaps before snapd becomes operational. ```bash $ snap debug timings --startup=ifacemgr ID Status Doing Undoing Summary ifacemgr - - ^ 8ms - setup security backend "apparmor" for snap "core" ^ 7ms - setup security backend "mount" for snap "lxd" ^ 16ms - setup security backend "apparmor" for snap "lxd" ^ 12ms - load unchanged security profiles of snap "lxd" ^ 7ms - setup security backend "apparmor" for snap "vlc" ^ 5ms - load unchanged security profiles of snap "vlc" ``` -------------------------------- ### Raspberry Pi gadget.yaml example Source: https://snapcraft.io/docs/reference/development/yaml-schemas/the-gadget-snap Example gadget.yaml for a Raspberry Pi, defining device-tree, volumes, and structures for ubuntu-seed, ubuntu-boot, ubuntu-save, and ubuntu-data. Includes comments about optional ubuntu-save and MBR partition limits. ```yaml device-tree: bcm2709-rpi-3-b-plus volumes: pi: schema: mbr bootloader: u-boot structure: - name: ubuntu-seed role: system-seed filesystem: vfat type: 0C size: 1200M content: - source: boot-assets/ target: / - name: ubuntu-boot role: system-boot filesystem: vfat type: 0C # what's the appropriate size? size: 750M content: # TODO:install the boot.sel via snapd instead of via the gadget - source: boot.sel target: uboot/ubuntu/boot.sel # NOTE: ubuntu-save is optional for unencrypted devices like the pi, so # this structure can be dropped in favor of a different partition for # users who wish to instead use a different partition, since with MBR we # are limited to only 4 primary partitions. # TODO: look into switching over to GPT, the pi bootloader firmware now # has support for this - name: ubuntu-save role: system-save filesystem: ext4 type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4 size: 16M - name: ubuntu-data role: system-data filesystem: ext4 type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4 # XXX: make auto-grow to partition size: 1500M ``` -------------------------------- ### snap get nextcloud Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/configure-snaps Displays the configuration options of an installed snap. The output shows the top-level keys and values, with {...} indicating nested options beneath the current key name level. ```shell $ sudo snap get nextcloud Key Value mode production nextcloud {...} php {...} ports {...} private {...} ``` -------------------------------- ### Register install hook with network plug in snapcraft.yaml Source: https://snapcraft.io/docs/reference/development/supported-snap-hooks Excerpt from snapcraft.yaml that registers an install hook using the network plug. Place this under the hooks key in the snapcraft.yaml file. ```yaml apps: ... hooks: install: plugs: [network] ``` -------------------------------- ### Install and connect snaps for confdb access Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb Install the custodian-snap and reader-snap snaps, then connect their confdb plugs to the network-wifi-admin and network-wifi-state views. When a snap is published by the same account ID as the assertion, the interface plug is auto-connected. ```bash snap install custodian-snap reader-snap snap connect custodian-snap:network-wifi-admin snap connect custodian-snap:network-wifi-state snap connect reader-snap:network-wifi-state ``` -------------------------------- ### Enable and disable services with snapctl start/stop Source: https://snapcraft.io/docs/how-to-guides/snap-development/use-snapctl Enable a service with --enable when starting, and disable a service with --disable when stopping. Note the typo in the first command (myql instead of mysql). ```bash $ snapctl start nextcloud.myql --enable $ snapctl stop nextcloud.mysql --disable ``` -------------------------------- ### Get system settings with snap get -d Source: https://snapcraft.io/docs/reference/administration/system-options Displays the current system settings, including the timezone. Available only on Ubuntu Core. ```bash $ snap get -d system { "experimental": { "hotplug": true, "layouts": true }, "refresh": { "last": "2017-05-25T09:03:58.664837614+01:00", "retain": 2 }, "seed": { "loaded": true }, "system": { "timezone": "America/Chicago" } } ``` -------------------------------- ### Install snapd on Rocky Linux Source: https://snapcraft.io/docs/tutorials/install-the-daemon/rocky-linux Installs the snapd package from the EPEL repository on Rocky Linux. Requires EPEL to be added first. ```bash $ sudo yum install snapd ``` -------------------------------- ### Prepare RPM build environment Source: https://snapcraft.io/docs/explanation/snap-development/building-snap-rpms-on-rhel Set up the RPM build tree, download the snapd source tarball, and extract the RPM spec file into the SPECS directory. ```bash $ rpmdev-setuptree $ cd ~/rpmbuild/SOURCES $ curl -L \ https://github.com/canonical/snapd/releases/download/2.42/snapd_2.42.no-vendor.tar.xz \ -o snapd_2.42.no-vendor.tar.xz $ tar -xvJ -C ~/rpmbuild/SPECS --strip-components=3 \ -f snapd_2.42.no-vendor.tar.xz \ snapd-2.42/packaging/fedora/ ``` -------------------------------- ### squashfs mount error output Source: https://snapcraft.io/docs/tutorials/install-the-daemon/fedora Example error message that may appear when installing the first snap on a Fedora cloud image. Indicates the system does not fully support snapd due to missing squashfs support. ```text error: system does not fully support snapd: cannot mount squashfs image using "squashfs": mount: /tmp/sanity-mountpoint-156693269: unknown filesystem type 'squashfs'. ``` -------------------------------- ### View top-level system option categories and experimental options Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/set-system-options Shows the output of 'snap get system' which lists top-level categories, and 'snap get system experimental' which displays the experimental options and their values. ```bash $ snap get system Key Value experimental {...} refresh {...} seed {...} system {...} $ snap get system experimental Key Value experimental.hotplug true experimental.layouts true ``` -------------------------------- ### Defining gpio plugs in snapcraft.yaml Source: https://snapcraft.io/docs/reference/interfaces/gpio-interface Example of defining distinct plugs for each GPIO pin in a snap's snapcraft.yaml, using the gpio interface. ```yaml plugs: activity-led: interface: gpio warning-led: interface: gpio ``` -------------------------------- ### Install a specific revision when a channel is closed Source: https://snapcraft.io/docs/explanation/how-snaps-work/channels-and-tracks Shows the output of installing a specific revision when the tracked channel is closed, and the revision list that explains why the snap appears to come from a riskier channel. The install command forwards to the edge channel because the requested revision is not available on the closed stable channel. ```shell $ snap install hello-world --revision=28 hello-world (edge) 6.3 from Canonical✓ installed Channel latest/stable for hello-world is closed; temporarily forwarding to edge. ``` ```shell $ snapcraft list-revisions hello-world Rev. Uploaded Arches Version Channels 29 2019-04-17T16:43:58Z all 6.4 latest/beta*,latest/candidate*,latest/edge*,latest/stable* 28 2017-11-20T07:59:46Z all 6.3 latest/edge 27 2016-07-12T16:37:23Z all 6.3 latest/beta,latest/candidate,latest/edge,latest/stable 26 2016-05-31T07:02:32Z all 6.1 latest/edge,latest/stable 24 2016-04-19T15:37:06Z all 6 latest/beta,latest/candidate,latest/edge,latest/stable ``` -------------------------------- ### Install a classic snap with --classic Source: https://snapcraft.io/docs/explanation/snap-development/install-modes Required for classic snaps that need unfettered access to system resources. The --classic argument is silently accepted when installing a strict snap, but it won't change its confinement. ```bash sudo snap install snapcraft --classic ``` -------------------------------- ### prepare-serial hook: set registration.body with attestation data Source: https://snapcraft.io/docs/reference/development/yaml-schemas/the-gadget-snap Use in the optional prepare-serial hook to provide device attestation information during secure registration. It retrieves the registration request-id via snapctl get and sets registration.body with hardware identity fields. The hook runs after the gadget snap is installed when secure registration is required. ```shell #!/bin/sh # Get the request-id for registration REQUEST_ID="$(snapctl get registration.request-id)" # Sign request_id with HW ID private key # set hardware identity attestation information snapctl set registration.body="{\"hardware-id-key-sha3-384\": \"${HASH}\", \"signature-hash-algorithm\": \"${SIG_HASH}\", \"request-id-signature\": \"${SIGNATURE}\" }" ``` -------------------------------- ### List all snap services globally Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/control-services Use `sudo snap services --global` to list all snap services for the entire system. Requires root-level access. Output shows service name, startup state, current state, and notes. ```bash $ sudo snap services --global Service Startup Current Notes lxd.activate enabled inactive - lxd.daemon enabled active socket-activated lxd.user-daemon enabled inactive socket-activated multipass.multipassd enabled active - nextcloud.apache enabled active - nextcloud.logrotate enabled inactive timer-activated nextcloud.mysql enabled active - nextcloud.nextcloud-cron enabled active - nextcloud.nextcloud-fixer enabled active - nextcloud.php-fpm enabled active - nextcloud.redis-server enabled active - nextcloud.renew-certs enabled active - ``` -------------------------------- ### snap connections and disconnect/connect for instance Source: https://snapcraft.io/docs/explanation/how-snaps-work/parallel-installs Shows how to inspect and modify interface connections for a snap instance. The example lists connections, disconnects the network plug, verifies the slot becomes empty, reconnects, and shows the connection is now marked 'manual'. ```bash $ snap connections xkcd-webserver_foo Interface Plug Slot Notes network xkcd-webserver_foo:network :network - network-bind xkcd-webserver_foo:network-bind :network-bind - $ sudo snap disconnect xkcd-webserver_foo:network $ snap connections xkcd-webserver_foo Interface Plug Slot Notes network xkcd-webserver_foo:network - - network-bind xkcd-webserver_foo:network-bind :network-bind - $ sudo snap connect xkcd-webserver_foo:network $ snap connections xkcd-webserver_foo Interface Plug Slot Notes network xkcd-webserver_foo:network :network manual network-bind xkcd-webserver_foo:network-bind :network-bind - ``` -------------------------------- ### Start an interactive shell during packaging with `snapcdd` --shell interactive shell. description: Run `sn_large.png Source: https://snapcraft.io/docs/snapcraft-overview Run `snapcraft pack --shell interactive shell inside the interactive shell. description: ```bash_code sn? Actually, exact code exactly as in source preserving whitespace preserving line breaks.actual code block content exactly as in source verbatim preserving whitespace and line breaks exactly as they appear.page_titleInspect the result: inspecting the build container and file structure. page_description: ``` -------------------------------- ### snap connections --all (with unconnected slots) Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/connect-interfaces Lists all interfaces, including those without a connection. This is the same command as the first example but with a different output showing unconnected slots. ```bash $ snap connections --all Interface Plug Slot Notes adb-support scrcpy:adb-support :adb-support - alsa entropypianotuner:alsa - - alsa ffmpeg:alsa :alsa manual alsa guvcview:alsa - - (...) ``` -------------------------------- ### Install Firefox from esr track Source: https://snapcraft.io/docs/explanation/how-snaps-work/channels-and-tracks Installs Firefox from the 'esr/stable' channel, which is a custom track. This command is used when you want to install a specific track of a snap. ```bash snap install firefox --channel=esr/stable ``` -------------------------------- ### Pack the snap with snapcraft pack Source: https://snapcraft.io/docs/snapcraft-overview Run the snapcraft pack command to build the snap. Downloading the container image can take a few minutes, but the build itself takes only a few seconds. ```bash snapcraft pack ``` -------------------------------- ### Set and get confdb data with snapctl and snap get Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb Set data through the confdb view using snapctl set, then read it back with snapctl get and snap get. The change-view-network-wifi-admin hook is invoked when custodian-snap modifies the SSID, and the value is prefixed with 'acme'. ```bash $ sudo snap run --shell custodian-snap.sh # snapctl set --view :network-wifi-admin acme.ssid=some-ssid acme.password=super-secret # exit $ sudo snap run --shell reader-snap.sh # snapctl get --view :network-wifi-state acme.ssid acme-some-ssid # exit $ snap get /network/wifi-state acme.ssid acme-some-ssid ``` -------------------------------- ### Build an unpacked snap with snapcraft try Source: https://snapcraft.io/docs/how-to-guides/snap-development/snap-try Builds a snap with snapcraft and exposes the prime directory for testing. The output shows the build process and the command to run snap try with the prime directory. ```bash $ snapcraft try --use-lxd Pulling hello-world + snapcraftctl pull Building hello-world + snapcraftctl build + cp --archive --link --no-dereference . /root/parts/hello-world/install Staging hello-world + snapcraftctl stage Priming hello-world + snapcraftctl prime You can now run `snap try /home/user/hello-world/prime`. ``` -------------------------------- ### Command: ukuzama-pyfiglet -f thin hello, world! Source: https://snapcraft.io/docs/snapcraft-overview Run this command after repacking and reinstalling the snap to test the new fonts. The output shows the ASCII art generated with the thin font. ```bash ukuzama-pyfiglet -f thin hello, world! ``` ```text | | | | || |---.,---.| | ,---. . . .,---.,---.| ,---|| | ||---'| | | | | | || || | | | ` '`---'`---'`---'`---' | `-'-'`---'` `---'`---'o ``` -------------------------------- ### Initialize LXD Source: https://snapcraft.io/docs/snapcraft-overview Initializes LXD with a lightweight, default configuration. ```bash sudo lxd init --auto ``` -------------------------------- ### Test a snapcraft prime directory with snap try Source: https://snapcraft.io/docs/how-to-guides/snap-development/snap-try Installs the prime directory produced by snapcraft try. The output shows the snap being mounted from the prime directory. ```bash $ snap try /home/user/hello-world/prime hello-world 0.1 mounted from /home/user/hello-world/prime ``` -------------------------------- ### Run snap with font and show output Source: https://snapcraft.io/docs/snapcraft-overview Runs the snap with the installed font, omitting the .tlf extension, and shows the expected braille output. ```bash ukuzama-pyfiglet -f smbraille hello, world! ⣇⡀ ⢀⡀ ⡇ ⡇ ⢀⡀ ⡀ ⢀ ⢀⡀ ⡀⣀ ⡇ ⢀⣸ ⡇ ⠇⠸ ⠣⠭ ⠣ ⠣ ⠣⠜, ⠱⠱⠃ ⠣⠜ ⠏ ⠣ ⠣⠼ ⠅ ``` -------------------------------- ### Enable pre-install disk space check with snap set Source: https://snapcraft.io/docs/how-to-guides/manage-snaps/disk-space-awareness Command to enable the experimental pre-install disk space check by setting system option `experimental.check-disk-space-install` to `true`. ```bash snap set system experimental.check-disk-space-install=true ```