For some snap applications, we would like to be able to run our script in the snap installation to do something we want to do, such as creating a folder. So how can we get this event? In our previous article, "How to set up for our Ubuntu core app," We've shown how to set up our snap app. The Configure script in that polygon is called when it is set. In fact, it is automatically called when it is installed. Below, we illustrate the following examples:
Https://github.com/liu-xiao-guo/helloworld-install
In the example above, our configure script is as follows: Configure
#!/bin/sh
echo "This is called during the installation!"
Exit 1
This is a very simple scripting program. During our installation, it returned a value of "1", indicating that it was a failure. Then this app will not be installed successfully:
liu-xiao-guo@localhost:~/apps/helloworld-install$ sudo snap install *.snap--dangerous
Error:cannot perform the Following tasks:
-Run Configure Hook of "hello-install" snap if present (this is called during the installation!)
liu-xiao-guo@localhost:~/apps/helloworld-install$ Snap List
Name Version Rev Developer Notes
Classic 16.04 canonical DevMode
Core 16.04.1 716 canonical -
grovepi-server 1.0 x1 DEVMODE
Packageproxy 0.1 3 ogra -
pi2 16.04-0.17 canonical -
Pi2-kernel 4.4.0-1030-3 canonical -
snapweb 0.21.2 Canonical -
Obviously through the above show, Helloworld-install is not installed in our system. If we change the Configure script to:
Configure
#!/bin/sh
echo "This is called during the installation!"
Exit 0
The return value of this script is "0", indicating that its installation was successful.
liu-xiao-guo@localhost:~/apps/helloworld-install$ sudo snap install *.snap--dangerous
Hello-install 1.0 Installed
liu-xiao-guo@localhost:~/apps/helloworld-install$ snap list
Name Version Rev Developer Notes
Classic 16.04 canonical devmode
core 16.04.1 716 canonical -
grovepi-server 1.0 x1 devmode
hello-install 1.0 x1 -
packageproxy 0.1 3 ogra -
pi2 16.04-0.17 Canonical -
pi2-kernel 4.4.0-1030-3 canonical -
snapweb 0.21.2 Canonical -
liu-xiao-guo@localhost:~/apps/helloworld-install$ vi/var/log/syslog
liu-xiao-guo@localhost:~/apps/helloworld-install$ sudo vi/var/log/syslog
We can find the output of this script runtime in the/var/log/syslog of the system:
It is obvious that the script is running properly at the time of installation. We can do some initialization of our application by running such a hook, paving the way for the next application to run well.
Read MORE: Https://kyrofa.com/posts/snap-updates-automatic-rollbacks