Created
May 8, 2022 20:32
-
-
Save zlocate/81d2aa6338613eef2073c802e3df0dd3 to your computer and use it in GitHub Desktop.
Download .snap package file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment