4

Is there a way to obtain the url of an snap to download, instead of using the snap download command ?, so it could be downloaded with wget/aria2c or other programs?

  • I strongly suspect snap uses one of those itself, so why not snap download? – mikewhatever Sep 16 '18 at 8:49
  • I have a bad internet connection, it is very unstable, so i want to download the snaps with a download manager, so i can resume the download in case fails..., and snap download doesn't allow me to continue the download once it fails – Daniel Pérez Sep 16 '18 at 17:59
  • I once tried arch linux, and pacman had a config file where you can specify what tool to use to download packages, maybe there is a config file for snaps ? – Daniel Pérez Sep 16 '18 at 18:00
9

Retrieve the information with,

curl -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/anbox # | jq
# "anbox" is the name of the snap package. change it to what you want.

which could contain multiple entries for channels and architectures. One among them would be,

"download": {
        "deltas": [],
        "sha3-384": "b105626b35dbba5eb990125adf557c5a38bf1a793256f35ca89f3d33d81caa608084606f2d39569475f8d880088f79d2",
        "size": 391696384,
        "url": "https://api.snapcraft.io/api/v1/snaps/download/Nr9K6UJaIOD8wHpDEQl16nabFFt9LLEQ_185.snap"
      },

and you got it.

See also snap store api documentation (https://api.snapcraft.io/docs/info.html).

| improve this answer | |
  • I removed the cross hatch character to pretty print it: curl -H 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/anbox | jq – noobninja Dec 16 '19 at 4:37
  • 1
    Right! I commented it out in case other people don't have jq. – 把友情留在无盐 Dec 16 '19 at 4:46
  • 1
    What is the purpose of the 'Snap-Device-Series: 16' header? – pierce.jason Feb 12 at 18:01
3

Expanding on a prior answer...

If this is a machine that you have not installed snaps on before, you will first need the core snap.

For any snap PACKAGE that you want to install, you will need the PACKAGE.assert file to do updates and to avoid using the --dangerous install option.

After you have the PACKAGE.snap and PACKAGE.assert you'll need to use the snap command to ack the PACKAGE.assert and then install the PACKAGE.snap.

snap ack PACKAGE.assert
snap install PACKAGE.snap

You can use Pedronis's snap, assert-fetcher to fetch the PACKAGE.assert file. If you download this using snippet example as below, you will need to change the RELEASE from stable to beta. You can then extract the .snap to get the executable assert-fetcher. The executable is compiled for Ubuntu 16, but I have found that it works in Debian 10 (buster) as well. If this executable doesn't work in your distro, the source is available on launchpad. It will be in the ~/assert-fetcher/bin directory. unsquashfs -d ~/assert-fetcher/ assert-fetcher.snap Usage syntax is such as ~/assert-fetcher/bin/assert-fetcher PACKAGE.snap. Modify the 3rd line of the snippet below to point to the assert-fetcher executable.

The script I wrote below, snap-download.sh, downloads PACKAGE.json, PACKAGE.snap, and PACKAGE.assert. I wrote this handy script in-order to resume failed downloads due to flaky network connection. It will fetch and parse the metadata for PACKAGE to get the url. Then it downloads or resumes a partial download for PACKAGE.snap. Once PACKAGE.snap is downloaded successfully, it will fetch the PACKAGE.assert file. This will get packages and data for 64bit stable releases. If you want something different, change the values in the first 2 lines.

An example of installing sublime-text on a machine that has snapd installed, but has never had any snaps installed

snap-download.sh assert-fetcher # Download assert-fetcher.snap and assert-fetcher.json. Getting the assert file will fail.
unsquashfs -d ~/assert-fetcher/ assert-fetcher.snap # Extract the assert-snapper snap to use the executable
~/assert-fetcher assert-fetcher # Download the assert file for assert-fetcher
snap ack assert-fetcher.assert # Register the assert file
snap install assert-fetcher.snap # Install the snap
rm -rf ~/assert-fetcher/ assert-fetcher.assert assert-fetcher.snap assert-fetcher.json # Don't need these files anymore, it is installed as a snap now

snap-download core # Downloads core.snap, core.json, and core.assert
snap ack core.assert
snap install core.snap
rm core.assert core.snap core.json

snap-download sublime-text
snap ack sublime-text.assert
snap install sublime-text.snap
rm sublime-text.assert sublime-text.snap sublime-text.json

snap-download.sh

#!/bin/bash
ARCH=amd64
RELEASE=stable
#export PATH="$PATH:/snap/bin/"
eval assert_fetcher_path="~/assert-fetcher/bin/assert-fetcher"

PACKAGE=$1

echo "Checking for jq..."
which jq
nojq=$?

if [ $nojq -gt 0 ]; then
    echo "This snippet requires jq to function. Please install jq and try again"
    exit 1
fi

if [ -z $PACKAGE ]; then
    echo "Enter name of snap package to manually download:"
    read PACKAGE
fi

meta_url="http://api.snapcraft.io/v2/snaps/info/${PACKAGE}"
echo "Fetching metadata from ${meta_url}..."

curl -H 'Snap-Device-Series: 16' -o ${PACKAGE}.json ${meta_url}
grep -v "error-list" ${PACKAGE}.json > /dev/null
curl_stat=$?

if [ $curl_stat -gt 0 ]; then
    echo "Problem fetching ${PACKAGE} metadata."
    echo "See file ${PACKAGE}.json for details."
    exit
fi

url=$( cat ${PACKAGE}.json | jq '."channel-map"' | jq '.[]' | jq '[."channel"."architecture", ."channel"."name", ."download"."url"]' | grep -A2 ${ARCH} | grep -A1 ${RELEASE} | grep http | tr -d ' ' | tr -d '"' )

echo "Downloading '$url'..."
curl -L -o "${PACKAGE}.snap" -C - "$url"
curl2_stat=$?

ls -lh ${PACKAGE}.snap

if [ $curl2_stat -gt 0 ]; then
    echo "Download failed. Re-run this snippet to attempt to resume download"
    exit 1
fi

echo "Downloaded ${PACKAGE}.snap successfully. Attempting to fetch ${PACKAGE}.assert now."

echo "Checking for assert-fetcher..."
which ${assert_fetcher_path}
noassert_fetcher=$?
if [ $noassert_fetcher -gt 0 ]; then
    echo "assert-fetcher executable not found at ${assert_fetcher_path}. Checking system path."

    SNAP_PATH=$( which assert-fetcher )
    noassert_fetcher2=$?

    if [ $noassert_fetcher2 -gt 0 ]; then
        echo "assert-fetcher not found in system path. You will need to run asset-fetcher manually or install your snap with --dangerous (not recomended)."
        exit 1
    fi
    assert_fetcher_path="$SNAP_PATH"
fi

${assert_fetcher_path} ${PACKAGE}.snap
assert_fetcher_stat=$?
if [ $assert_fetcher_stat -gt 0 ]; then
    echo "Failed to fetch ${PACKAGE}.assert."
    exit 1
fi

ls -lh ${PACKAGE}.*
echo "Snap and Assert file for ${PACKAGE} downloaded successfully."
exit 0
| improve this answer | |
1

I found this site https://uappexplorer.com/ readding this question Download only with snap, as it says

uApp Explorer is the unofficial viewer for snaps and Ubuntu Touch apps.

You'll probably have to install it with the --dangerous flag, snap install --dangerous <snap>

Here are some related links:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.