1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/bin/bash -e
get_package_data() {
name="${INPUT_File?File must be given to get-package-data}"
echo PackageType=repo
echo Name=$name
}
list_installed() {
# Example pkg output:
# Name Version Rev Developer Notes
# core 16-2.30 3748 canonical core
# hello-world 6.3 27 canonical -
#
# After rewrite:
# Name=core
# Version=16-2.30
# Architecture=none
snap list | sed 1d | awk '
{
printf("Name=%s\n",$1)
printf("Version=%s\n",$2)
printf("Architecture=none\n")
}'
}
repo_install() {
name="${INPUT_Name?Name must be given to repo-install}"
# TODO: investigate channel, revision flags
snap install "$name" >&2
}
list_updates() {
# By default snaps are updated daily, at the time of this writing, there is no
# way to disable the auto-update, but it can be delayed.
# TODO: Get example output showing updates from `snap refresh --list`
true
}
remove() {
name="${INPUT_Name?Name must be given to remove}"
snap remove "$name" >&2
}
main() {
command=$1
# Output maybe contain backslashes, and we don't want those to end up escaping
# something so we use use -r with read.
while read -r line; do
# Note that line is a variable assignment, e.g.
# INPUT_File=syncthing
declare INPUT_$line
done
case $command in
supports-api-version)
echo 1
;;
get-package-data)
get_package_data
;;
list-installed)
list_installed
;;
repo-install)
repo_install
;;
list-updates)
list_updates
;;
list-updates-local)
list_updates
;;
remove)
remove
;;
*)
echo "ErrorMessage=Invalid operation"
esac
}
main $1
|