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