Snap (Ubuntu package management)

Snap package search
https://snapcraft.io/store

Install

sudo apt install -y snapd

Configure proxy
https://snapcraft.io/docs/system-options
http://www.panticz.de/proxy (encrypt spedial characters in proxy password)

sudo snap set system proxy.https="${https_proxy}"
sudo snap set system proxy.http="${http_proxy}"

CLI

systemctl status snapd
 
snap find
snap install
snap info <snap name>
 
# update
snap refresh
 
# Update packages
snap refresh --list
 
# purge package
snap remove --purge libreoffice

Configure proxy (DEPRECTED)

# sudo mkdir -p /etc/systemd/system/snapd.service.d/
# echo "[Service]
# Environment=\"http_proxy=${http_proxy}\"
# Environment=\"https_proxy=${https_proxy}\"" | sudo tee /etc/systemd/system/snapd.service.d/http-proxy.conf
 
# sudo systemctl daemon-reload
# sudo systemctl restart snapd
 
# # debug proxy
# systemctl show snapd | grep proxy
 
# ###############################3
# # proxy test (broken?)
# # cat /etc/environment
# http_proxy="http://BENUTZER:PASSWORD@proxy.hostname.de:8080/"
# https_proxy="http://BENUTZER:PASSWORD@proxy.hostname.de:8080/"
 
# sudo systemctl edit snapd.service
# [Service]
# EnvironmentFile=/etc/environment
 
# sudo systemctl daemon-reload
# sudo systemctl restart snapd.service

Configure proxy (Ansible)

---
- hosts: localhost
  tasks:
    - name: Configure snap proxy
      become: yes
      ini_file:
        path: /etc/systemd/system/snapd.service.d/http-proxy.conf
        section: Service
        option: Environment
        value: '"http_proxy=http://proxy.example.com:8080"'
        mode: 0644
        create: yes
      notify: restart snapd
 
  handlers:
    - name: restart snapd
      systemd:
        name: snapd
        state: restarted
        daemon_reload: yes

Service
https://snapcraft.io/docs/service-management

Cleanup old versions

sudo snap set system refresh.retain=2
 
LANG=C snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
    snap remove "$snapname" --revision="$revision"
done

Install applications

# Visual Studio Code
sudo snap install code --classic
 
# Spotify
sudo snap install spotify
 
# (Micro)Kubernetes
snap install microk8s --classic

Uninstall

systemctl disable snapd.service
umount  /snap
apt purge -y snapd

Ports

snap get nextcloud
snap get nextcloud ports
snap set nextcloud ports.http=8080

Ansible module
https://docs.ansible.com/ansible/latest/modules/snap_module.html

Service

snap services
sudo snap stop lxd.daemon
sudo snap stop --disable lxd.daemon
 
systemctl restart snapd
snap services
snap stop lxd.daemon
sudo snap stop lxd.daemon
sudo snap start lxd.daemon
sudo snap start lxd.activate

Allow access to USB pen

snap connect signal-desktop:removable-media

Links
https://snapcraft.io/
https://wiki.ubuntuusers.de/snap/