Sfoglia il codice sorgente

Functions for adding and removing snap packages

Bob Mottram 7 anni fa
parent
commit
9f999b6887
2 ha cambiato i file con 62 aggiunte e 3 eliminazioni
  1. 2
    3
      src/freedombone-app-rocketchat
  2. 60
    0
      src/freedombone-utils-snap

+ 2
- 3
src/freedombone-app-rocketchat Vedi File

@@ -238,12 +238,11 @@ function remove_rocketchat {
238 238
 
239 239
     remove_ddns_domain "$ROCKETCHAT_DOMAIN_NAME"
240 240
 
241
-    snap remove rocketchat-server
241
+    remove_snap rocketchat-server
242 242
 }
243 243
 
244 244
 function install_rocketchat {
245
-    apt-get -qy install snapd
246
-    snap install rocketchat-server
245
+    install_snap rocketchat-server
247 246
 
248 247
     install_nodejs rocketchat
249 248
     if [ ! "$ROCKETCHAT_DOMAIN_NAME" ]; then

+ 60
- 0
src/freedombone-utils-snap Vedi File

@@ -0,0 +1,60 @@
1
+#!/bin/bash
2
+#  _____               _           _
3
+# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
4
+# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
5
+# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
6
+#
7
+#                              Freedom in the Cloud
8
+#
9
+# Handling installation of snap packages
10
+#
11
+# License
12
+# =======
13
+#
14
+# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
15
+#
16
+# This program is free software: you can redistribute it and/or modify
17
+# it under the terms of the GNU Affero General Public License as published by
18
+# the Free Software Foundation, either version 3 of the License, or
19
+# (at your option) any later version.
20
+#
21
+# This program is distributed in the hope that it will be useful,
22
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
+# GNU Affero General Public License for more details.
25
+#
26
+# You should have received a copy of the GNU Affero General Public License
27
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
+
29
+function install_snap {
30
+    snap_package="$1"
31
+
32
+    if [ ! "$snap_package" ]; then
33
+        return
34
+    fi
35
+    no_of_snaps=$(df | grep -c "/snap/core/")
36
+    if [ "$no_of_snaps" -eq 0 ]; then
37
+        apt-get -yq install snapd
38
+    fi
39
+    if ! snap install "$snap_package"; then
40
+        echo $"Failed to install snap package $snap_package"
41
+        exit 46382854
42
+    fi
43
+}
44
+
45
+function remove_snap {
46
+    snap_package="$1"
47
+
48
+    if [ ! "$snap_package" ]; then
49
+        return
50
+    fi
51
+
52
+    snap remove "$snap_package"
53
+
54
+    no_of_snaps=$(df | grep -c "/snap/")
55
+    if [ "$no_of_snaps" -eq 1 ]; then
56
+        apt-get -yq remove snapd
57
+    fi
58
+}
59
+
60
+# NOTE: deliberately no exit 0