Skip to content

Instantly share code, notes, and snippets.

@atomatt
Last active June 1, 2017 11:19
Show Gist options
  • Select an option

  • Save atomatt/38eb03f2bfe178e9e5a6ea06d121a046 to your computer and use it in GitHub Desktop.

Select an option

Save atomatt/38eb03f2bfe178e9e5a6ea06d121a046 to your computer and use it in GitHub Desktop.
Make a simple, tiny snap
#!/bin/bash
set -euo pipefail
snap_name=""
version="1"
env="stg"
register=""
push=""
release=""
while [ "${1:-}" != "" ]; do
case $1 in
-e | --env)
shift
env=$1
;;
-v | --version)
shift
version=$1
;;
--no-register)
register="n"
;;
--push)
register=${register:-y}
push="y"
;;
--release)
register=${register:-y}
push="y"
release="y"
;;
*)
snap_name=$1
;;
esac
shift
done
if [ "${snap_name}" == "" ]; then
echo "Invalid snap name '${snap_name}'"
exit 1
fi
case ${env} in
prod)
;;
stg)
export UBUNTU_STORE_API_ROOT_URL="https://myapps.developer.staging.ubuntu.com/dev/api/"
export UBUNTU_STORE_SEARCH_ROOT_URL="https://search.apps.staging.ubuntu.com/"
export UBUNTU_STORE_UPLOAD_ROOT_URL="https://upload.apps.staging.ubuntu.com/"
export UBUNTU_SSO_API_ROOT_URL="https://login.staging.ubuntu.com/api/v2/"
;;
*)
echo "Invalid environment name '${env}', must be one 'prod' or 'stg' (default)"
exit 1
;;
esac
# Save the current directory but switch to a temp dir to work in. Otherwise
# snapcraft scans everything in the current directory and may overwrite
# existing files.
origdir=$(pwd)
workdir=$(mktemp -d)
cd ${workdir}
# Cleanup and change back to original directory.
function finish() {
rm -rf ${workdir}
cd ${origdir}
}
trap finish EXIT
# Build snap and copy it to the original directory.
cat > snapcraft.yaml <<EOF
name: $snap_name
version: $version
summary: hello test snap
description: hello test snap
confinement: strict
grade: stable
architectures:
- all
apps:
hello:
command: echo "hello from $snap_name v$version"
parts:
empty:
plugin: nil
EOF
snapcraft
cp ${snap_name}_${version}_all.snap ${origdir}
# Optionally interact with store.
if [ "${register}" == "y" ] && [ "${version}" == "1" ]; then
snapcraft register $snap_name
fi
if [ "${push}" == "y" ]; then
snapcraft push ${snap_name}_${version}_all.snap
fi
if [ "${release}" == "y" ]; then
snapcraft release ${snap_name} ${version} stable
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment