瀏覽代碼

More librevault

Bob Mottram 8 年之前
父節點
當前提交
ccb07ff320
沒有帳戶連結到提交者的電子郵件
共有 5 個檔案被更改,包括 384 行新增29 行删除
  1. 172
    29
      src/freedombone-app-librevault
  2. 2
    0
      src/freedombone-image-customise
  3. 5
    0
      src/freedombone-mesh-batman
  4. 101
    0
      src/freedombone-utils-cmake
  5. 104
    0
      src/freedombone-utils-cryptopp

+ 172
- 29
src/freedombone-app-librevault 查看文件

@@ -28,14 +28,14 @@
28 28
 # You should have received a copy of the GNU Affero General Public License
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31
-VARIANTS='none'
31
+VARIANTS='mesh'
32 32
 
33 33
 PROTOBUF_REPO="https://github.com/google/protobuf"
34 34
 PROTOBUF_COMMIT='b97a4a53cdd55be74c30badefeb132a091764f53'
35 35
 
36 36
 LIBREVAULT_REPO="https://github.com/Librevault/librevault"
37 37
 LIBREVAULT_COMMIT='86a6aefcb5cc458f4d42195368fbcff2871f98e3'
38
-LIBREVAULT_PORT=
38
+LIBREVAULT_PORT=42345
39 39
 
40 40
 function reconfigure_librevault {
41 41
     echo -n ''
@@ -43,23 +43,55 @@ function reconfigure_librevault {
43 43
 }
44 44
 
45 45
 function upgrade_librevault {
46
-    echo -n ''
47
-    # TODO
46
+    if ! grep -Fxq "install_librevault" $COMPLETION_FILE; then
47
+        return
48
+    fi
49
+
50
+    function_check set_repo_commit
51
+
52
+    if [ -d $INSTALL_DIR/protobuf ]; then
53
+        if ! grep -q "Protobuf commit:$PROTOBUF_COMMIT" $COMPLETION_FILE; then
54
+            set_repo_commit $INSTALL_DIR/protobuf "Protobuf commit" "$PROTOBUF_COMMIT" $PROTOBUF_REPO
55
+            cd $INSTALL_DIR/protobuf
56
+            ./autogen.sh
57
+            ./configure
58
+            make
59
+            make check
60
+            make install
61
+            ldconfig
62
+        fi
63
+    fi
64
+
65
+    if [ -d $INSTALL_DIR/librevault/build ]; then
66
+        if ! grep -q "Librevault commit:$LIBREVAULT_COMMIT" $COMPLETION_FILE; then
67
+            set_repo_commit $INSTALL_DIR/librevault "Librevault commit" "$LIBREVAULT_COMMIT" $LIBREVAULT_REPO
68
+            cd $INSTALL_DIR/librevault
69
+            git submodule update --init --recursive
70
+            cd $INSTALL_DIR/librevault/build
71
+            cmake ..
72
+            cmake --build .
73
+            make install
74
+        fi
75
+    fi
48 76
 }
49 77
 
50 78
 function backup_local_librevault {
79
+    echo -n ''
51 80
     # TODO
52 81
 }
53 82
 
54 83
 function restore_local_librevault {
84
+    echo -n ''
55 85
     # TODO
56 86
 }
57 87
 
58 88
 function backup_remote_librevault {
89
+    echo -n ''
59 90
     # TODO
60 91
 }
61 92
 
62 93
 function restore_remote_librevault {
94
+    echo -n ''
63 95
     # TODO
64 96
 }
65 97
 
@@ -67,12 +99,10 @@ function remove_librevault {
67 99
     if ! grep -Fxq "install_librevault" $COMPLETION_FILE; then
68 100
         return
69 101
     fi
70
-    if [ $LIBREVAULT_PORT ]; then
71
-        iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
72
-        iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
73
-        function_check save_firewall_settings
74
-        save_firewall_settings
75
-    fi
102
+    iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
103
+    iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
104
+    function_check save_firewall_settings
105
+    save_firewall_settings
76 106
 
77 107
     systemctl stop librevault
78 108
     systemctl disable librevault
@@ -85,29 +115,39 @@ function configure_firewall_for_librevault {
85 115
     if grep -Fxq "configure_firewall_for_librevault" $COMPLETION_FILE; then
86 116
         return
87 117
     fi
88
-    if [ $LIBREVAULT_PORT ]; then
89
-        iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
90
-        iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
91
-        function_check save_firewall_settings
92
-        save_firewall_settings
93
-        OPEN_PORTS+=("Librevault $LIBREVAULT_PORT")
94
-    fi
118
+    iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
119
+    iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
120
+    function_check save_firewall_settings
121
+    save_firewall_settings
122
+    OPEN_PORTS+=("Librevault $LIBREVAULT_PORT")
95 123
     echo 'configure_firewall_for_librevault' >> $COMPLETION_FILE
96 124
 }
97 125
 
98 126
 function mesh_install_librevault {
99 127
     install_tracker
128
+    install_cmake
129
+    install_cryptopp
100 130
 
101
-    chroot "$rootdir" apt-get -y -t jessie-backports install cmake
102 131
     chroot "$rootdir" apt-get -y install bittornado nginx
103
-    chroot "$rootdir" apt-get -y install build-essential libboost-all-dev libssl-dev
132
+    chroot "$rootdir" apt-get -y install build-essential
133
+    chroot "$rootdir" apt-get -y install autoconf automake libtool curl make unzip
134
+
135
+    # A workaround which allows c++14 to be installed
136
+    sed -i 's|jessie|stretch|g' $rootdir/etc/apt/sources.list
137
+    sed -i 's|stretch-backports|jessie-backports|g' $rootdir/etc/apt/sources.list
138
+    chroot "$rootdir" apt-get update
139
+    chroot "$rootdir" apt-get -y install g++ gcc-6 g++-6 libboost-all-dev libssl-dev
140
+    chroot "$rootdir" apt-get -y install protobuf-compiler libprotobuf-dev
104 141
     chroot "$rootdir" apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
105
-    chroot "$rootdir" apt-get -y install autoconf automake libtool curl make g++ unzip
142
+    chroot "$rootdir" apt-get -y install libsqlite3-dev qttools5-dev qttools5-dev-tools libnatpmp-dev
143
+    sed -i 's|stretch|jessie|g' $rootdir/etc/apt/sources.list
144
+    chroot "$rootdir" apt-get update
106 145
 
107 146
     if [ ! -d $rootdir$INSTALL_DIR ]; then
108
-        chroot "$rootdir" mkdir -p $INSTALL_DIR
147
+        mkdir -p $rootdir$INSTALL_DIR
109 148
     fi
110
-    chroot "$rootdir" git clone $PROTOBUF_REPO $rootdir$INSTALL_DIR/protobuf
149
+
150
+    git clone $PROTOBUF_REPO $rootdir$INSTALL_DIR/protobuf
111 151
     cd $rootdir$INSTALL_DIR/protobuf
112 152
     git checkout $PROTOBUF_COMMIT -b $PROTOBUF_COMMIT
113 153
 
@@ -122,19 +162,59 @@ EOF
122 162
     chroot "$rootdir" chmod +x /root/install_protobuf
123 163
     chroot "$rootdir" /root/install_protobuf
124 164
 
125
-    git_clone $LIBREVAULT_REPO $rootdir$INSTALL_DIR/librevault
165
+    git clone $LIBREVAULT_REPO $rootdir$INSTALL_DIR/librevault
126 166
     cd $rootdir$INSTALL_DIR/librevault
127 167
     git checkout $LIBREVAULT_COMMIT -b $LIBREVAULT_COMMIT
168
+    git submodule update --init --recursive
169
+
170
+    # rabin seems particularly broken
171
+    rm -rf $rootdir$INSTALL_DIR/librevault/contrib/rabin
172
+    git clone https://github.com/bashrc/rabin $rootdir$INSTALL_DIR/librevault/contrib/rabin
173
+    cd $rootdir$INSTALL_DIR/librevault/contrib/rabin
174
+    git checkout bashrc/fixup2
175
+
128 176
     mkdir $rootdir$INSTALL_DIR/librevault/build
129 177
 
130 178
     cat <<EOF > $rootdir/root/install_librevault
131 179
 cd $INSTALL_DIR/librevault/build
132
-cmake ..
133
-cmake --build .
180
+cmake -BUILD_UPDATER=OFF ..
181
+which Meta_s.pb.cc
182
+cmake --build $INSTALL_DIR/librevault/build
134 183
 make install
135 184
 EOF
136 185
     chroot "$rootdir" chmod +x /root/install_librevault
137 186
     chroot "$rootdir" /root/install_librevault
187
+    chroot "$rootdir" rm /root/install_librevault
188
+
189
+    LIBREVAULT_DAEMON=$rootdir/etc/systemd/system/librevault-daemon.service
190
+    echo '[Unit]' > $LIBREVAULT_DAEMON
191
+    echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (multi-instance-master)' >> $LIBREVAULT_DAEMON
192
+    echo '' >> $LIBREVAULT_DAEMON
193
+    echo '[Service]' >> $LIBREVAULT_DAEMON
194
+    echo 'Type=oneshot' >> $LIBREVAULT_DAEMON
195
+    echo 'RemainAfterExit=yes' >> $LIBREVAULT_DAEMON
196
+    echo 'ExecStart=/bin/true' >> $LIBREVAULT_DAEMON
197
+    echo 'ExecReload=/bin/true' >> $LIBREVAULT_DAEMON
198
+    echo '' >> $LIBREVAULT_DAEMON
199
+    echo '[Install]' >> $LIBREVAULT_DAEMON
200
+    echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
201
+
202
+    LIBREVAULT_DAEMON=$rootdir/etc/systemd/system/librevault-daemon@.service
203
+    echo '[Unit]' > $LIBREVAULT_DAEMON
204
+    echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (instance for %I)' >> $LIBREVAULT_DAEMON
205
+    echo 'After=network.target' >> $LIBREVAULT_DAEMON
206
+    echo 'PartOf=librevault-daemon.service' >> $LIBREVAULT_DAEMON
207
+    echo 'ReloadPropagatedFrom=librevault-daemon.service' >> $LIBREVAULT_DAEMON
208
+    echo '' >> $LIBREVAULT_DAEMON
209
+    echo '[Service]' >> $LIBREVAULT_DAEMON
210
+    echo 'User=%i' >> $LIBREVAULT_DAEMON
211
+    echo 'ExecStart=/usr/bin/librevault-daemon' >> $LIBREVAULT_DAEMON
212
+    echo 'Restart=on-failure' >> $LIBREVAULT_DAEMON
213
+    echo '' >> $LIBREVAULT_DAEMON
214
+    echo '[Install]' >> $LIBREVAULT_DAEMON
215
+    echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
216
+
217
+    chroot "$rootdir" systemctl enable librevault-daemon
138 218
 }
139 219
 
140 220
 function install_librevault {
@@ -148,11 +228,23 @@ function install_librevault {
148 228
     fi
149 229
 
150 230
     install_tracker
231
+    install_cmake
232
+    install_cryptopp
151 233
 
152
-    apt-get -y -t jessie-backports install cmake
153
-    apt-get -y install build-essential libboost-all-dev libssl-dev
234
+    apt-get -y install build-essential
235
+    apt-get -y install autoconf automake libtool curl make unzip
236
+
237
+    # A workaround which allows c++14 to be installed
238
+    sed -i 's|jessie|stretch|g' /etc/apt/sources.list
239
+    sed -i 's|stretch-backports|jessie-backports|g' /etc/apt/sources.list
240
+    apt-get update
241
+    apt-get -y install protobuf-compiler libprotobuf-dev
242
+    apt-get -y install g++ gcc-6 g++-6 libboost-all-dev libssl-dev
154 243
     apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
155
-    apt-get -y install autoconf automake libtool curl make g++ unzip
244
+    apt-get -y install libsqlite3-dev qttools5-dev qttools5-dev-tools libnatpmp-dev
245
+    apt-get -y install gcc-6 g++-6 libboost-all-dev
246
+    sed -i 's|stretch|jessie|g' /etc/apt/sources.list
247
+    apt-get update
156 248
 
157 249
     if [ ! -d $INSTALL_DIR ]; then
158 250
         mkdir -p $INSTALL_DIR
@@ -167,15 +259,66 @@ function install_librevault {
167 259
     make install
168 260
     ldconfig
169 261
 
262
+    if ! grep -q "Protobuf commit" $COMPLETION_FILE; then
263
+        echo "Protobuf commit:$PROTOBUF_COMMIT" >> $COMPLETION_FILE
264
+    else
265
+        sed -i "s/Protobuf commit.*/Protobuf commit:$PROTOBUF_COMMIT/g" $COMPLETION_FILE
266
+    fi
267
+
170 268
     git_clone $LIBREVAULT_REPO $INSTALL_DIR/librevault
171 269
     cd $INSTALL_DIR/librevault
172 270
     git checkout $LIBREVAULT_COMMIT -b $LIBREVAULT_COMMIT
271
+    git submodule update --init --recursive
272
+
273
+    # rabin seems particularly broken
274
+    rm -rf $INSTALL_DIR/librevault/contrib/rabin
275
+    git clone https://github.com/bashrc/rabin $INSTALL_DIR/librevault/contrib/rabin
276
+    cd $INSTALL_DIR/librevault/contrib/rabin
277
+    git checkout bashrc/fixup2
278
+
173 279
     mkdir $INSTALL_DIR/librevault/build
174 280
     cd $INSTALL_DIR/librevault/build
175
-    cmake ..
281
+    cmake -BUILD_UPDATER=OFF ..
176 282
     cmake --build .
177 283
     make install
178 284
 
285
+    if ! grep -q "Librevault commit" $COMPLETION_FILE; then
286
+        echo "Librevault commit:$LIBREVAULT_COMMIT" >> $COMPLETION_FILE
287
+    else
288
+        sed -i "s/Librevault commit.*/Librevault commit:$LIBREVAULT_COMMIT/g" $COMPLETION_FILE
289
+    fi
290
+
291
+    LIBREVAULT_DAEMON=/etc/systemd/system/librevault-daemon.service
292
+    echo '[Unit]' > $LIBREVAULT_DAEMON
293
+    echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (multi-instance-master)' >> $LIBREVAULT_DAEMON
294
+    echo '' >> $LIBREVAULT_DAEMON
295
+    echo '[Service]' >> $LIBREVAULT_DAEMON
296
+    echo 'Type=oneshot' >> $LIBREVAULT_DAEMON
297
+    echo 'RemainAfterExit=yes' >> $LIBREVAULT_DAEMON
298
+    echo 'ExecStart=/bin/true' >> $LIBREVAULT_DAEMON
299
+    echo 'ExecReload=/bin/true' >> $LIBREVAULT_DAEMON
300
+    echo '' >> $LIBREVAULT_DAEMON
301
+    echo '[Install]' >> $LIBREVAULT_DAEMON
302
+    echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
303
+
304
+    LIBREVAULT_DAEMON=/etc/systemd/system/librevault-daemon@.service
305
+    echo '[Unit]' > $LIBREVAULT_DAEMON
306
+    echo 'Description=Librevault - Peer-to-peer, decentralized and open source file sync (instance for %I)' >> $LIBREVAULT_DAEMON
307
+    echo 'After=network.target' >> $LIBREVAULT_DAEMON
308
+    echo 'PartOf=librevault-daemon.service' >> $LIBREVAULT_DAEMON
309
+    echo 'ReloadPropagatedFrom=librevault-daemon.service' >> $LIBREVAULT_DAEMON
310
+    echo '' >> $LIBREVAULT_DAEMON
311
+    echo '[Service]' >> $LIBREVAULT_DAEMON
312
+    echo 'User=%i' >> $LIBREVAULT_DAEMON
313
+    echo 'ExecStart=/usr/bin/librevault-daemon' >> $LIBREVAULT_DAEMON
314
+    echo 'Restart=on-failure' >> $LIBREVAULT_DAEMON
315
+    echo '' >> $LIBREVAULT_DAEMON
316
+    echo '[Install]' >> $LIBREVAULT_DAEMON
317
+    echo 'WantedBy=multi-user.target' >> $LIBREVAULT_DAEMON
318
+
319
+    systemctl enable librevault-daemon
320
+    systemctl start librevault-daemon
321
+
179 322
     echo 'install_librevault' >> $COMPLETION_FILE
180 323
 }
181 324
 

+ 2
- 0
src/freedombone-image-customise 查看文件

@@ -555,6 +555,7 @@ initialise_mesh() {
555 555
     install_avahi
556 556
     install_batman
557 557
     install_tomb
558
+    #install_librevault
558 559
     #install_ipfs
559 560
     install_tox
560 561
     install_web_server
@@ -618,6 +619,7 @@ function mesh_client_startup_applications {
618 619
     echo 'dconf write /org/mate/power-manager/lock-blank-screen false' >> $START_DESKTOP
619 620
     echo 'dconf write /org/mate/power-manager/lock-hibernate false' >> $START_DESKTOP
620 621
     echo 'dconf write /org/mate/power-manager/lock-keyring-hibernate false' >> $START_DESKTOP
622
+    echo 'dconf write /org/mate/desktop/peripherals/touchpad/scroll-method 2' >> $START_DESKTOP
621 623
     echo "touch /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
622 624
     echo "chmod 600 /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP
623 625
     echo "env | grep DBUS_SESSION_BUS_ADDRESS > /home/$MY_USERNAME/.dbus/Xdbus" >> $START_DESKTOP

+ 5
- 0
src/freedombone-mesh-batman 查看文件

@@ -63,6 +63,7 @@ ZERONET_PORT=15441
63 63
 IPFS_PORT=4001
64 64
 TOX_PORT=33445
65 65
 TRACKER_PORT=6969
66
+LIBREVAULT_PORT=42345
66 67
 
67 68
 # Ethernet bridge definition (bridged to bat0)
68 69
 BRIDGE=br-mesh
@@ -141,6 +142,8 @@ function stop {
141 142
     iptables -D INPUT -p udp --dport $IPFS_PORT -j ACCEPT
142 143
     iptables -D INPUT -p tcp --dport $TOX_PORT -j ACCEPT
143 144
     iptables -D INPUT -p udp --dport $TOX_PORT -j ACCEPT
145
+    iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
146
+    iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
144 147
 
145 148
     systemctl restart network-manager
146 149
 }
@@ -246,6 +249,8 @@ function start {
246 249
     iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
247 250
     iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT
248 251
     iptables -A INPUT -p udp --dport $TOX_PORT -j ACCEPT
252
+    iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
253
+    iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
249 254
 
250 255
     systemctl restart avahi-daemon
251 256
 

+ 101
- 0
src/freedombone-utils-cmake 查看文件

@@ -0,0 +1,101 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Some things need a recent build of CMake to compile
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+CMAKE_REPO="https://github.com/Kitware/CMake"
32
+CMAKE_COMMIT='d6734eeb875ceca5d810e829ca90541918dca2b4'
33
+
34
+function mesh_install_cmake {
35
+    if [ ! -d $rootdir$INSTALL_DIR ]; then
36
+        chroot "$rootdir" mkdir -p $INSTALL_DIR
37
+    fi
38
+
39
+    chroot "$rootdir" apt-get -y install build-essential
40
+
41
+    git clone $CMAKE_REPO $rootdir$INSTALL_DIR/cmake
42
+    cd $rootdir$INSTALL_DIR/cmake
43
+    git checkout $CMAKE_COMMIT -b $CMAKE_COMMIT
44
+
45
+    cat <<EOF > $rootdir/root/install_cmake
46
+cd $INSTALL_DIR/cmake
47
+./bootstrap
48
+make
49
+if [ ! "$?" = "0" ]; then
50
+    exit 72581
51
+fi
52
+make install
53
+EOF
54
+    chroot "$rootdir" chmod +x /root/install_cmake
55
+    chroot "$rootdir" /root/install_cmake
56
+    chroot "$rootdir" rm /root/install_cmake
57
+}
58
+
59
+function install_cmake {
60
+    if [ $INSTALLING_MESH ]; then
61
+        mesh_install_cmake
62
+        return
63
+    fi
64
+
65
+    if [ -d $INSTALL_DIR/cmake ]; then
66
+        if ! grep -q "CMake commit:$CMAKE_COMMIT" $COMPLETION_FILE; then
67
+            set_repo_commit $INSTALL_DIR/cmake "CMake commit" "$CMAKE_COMMIT" $CMAKE_REPO
68
+            cd $INSTALL_DIR/cmake
69
+            ./bootstrap
70
+            make
71
+            if [ ! "$?" = "0" ]; then
72
+                exit 72581
73
+            fi
74
+            make install
75
+        fi
76
+    fi
77
+
78
+    if grep -Fxq "install_cmake" $COMPLETION_FILE; then
79
+        return
80
+    fi
81
+
82
+    if [ ! -d $INSTALL_DIR ]; then
83
+        mkdir -p $INSTALL_DIR
84
+    fi
85
+
86
+    apt-get -y install build-essential
87
+
88
+    git_clone $CMAKE_REPO $INSTALL_DIR/cmake
89
+    cd $INSTALL_DIR/cmake
90
+    git checkout $CMAKE_COMMIT -b $CMAKE_COMMIT
91
+    ./bootstrap
92
+    make
93
+    if [ ! "$?" = "0" ]; then
94
+        exit 72581
95
+    fi
96
+    make install
97
+
98
+    echo 'install_cmake' >> $COMPLETION_FILE
99
+}
100
+
101
+# NOTE: deliberately there is no "exit 0"

+ 104
- 0
src/freedombone-utils-cryptopp 查看文件

@@ -0,0 +1,104 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# A recent version of crypto++ is needed by some things
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+CRYPTOPP_REPO="https://github.com/weidai11/cryptopp"
32
+CRYPTOPP_COMMIT='65e91a8caa8c1846cb311bc83d8507e12699d6d3'
33
+
34
+function mesh_install_cryptopp {
35
+    if [ ! -d $rootdir$INSTALL_DIR ]; then
36
+        chroot "$rootdir" mkdir -p $INSTALL_DIR
37
+    fi
38
+
39
+    chroot "$rootdir" apt-get -y install build-essential
40
+
41
+    git clone $CRYPTOPP_REPO $rootdir$INSTALL_DIR/cryptopp
42
+    cd $rootdir$INSTALL_DIR/cryptopp
43
+    git checkout $CRYPTOPP_COMMIT -b $CRYPTOPP_COMMIT
44
+    mkdir $rootdir$INSTALL_DIR/cryptopp/build
45
+
46
+    cat <<EOF > $rootdir/root/install_cryptopp
47
+cd $INSTALL_DIR/cryptopp/build
48
+cmake ..
49
+make
50
+if [ ! "$?" = "0" ]; then
51
+    exit 62825
52
+fi
53
+make install
54
+EOF
55
+    chroot "$rootdir" chmod +x /root/install_cryptopp
56
+    chroot "$rootdir" /root/install_cryptopp
57
+    chroot "$rootdir" rm /root/install_cryptopp
58
+}
59
+
60
+function install_cryptopp {
61
+    if [ $INSTALLING_MESH ]; then
62
+        mesh_install_cryptopp
63
+        return
64
+    fi
65
+
66
+    if [ -d $INSTALL_DIR/cryptopp ]; then
67
+        if ! grep -q "Crypto++ commit:$CRYPTOPP_COMMIT" $COMPLETION_FILE; then
68
+            set_repo_commit $INSTALL_DIR/cryptopp "Crypto++ commit" "$CRYPTOPP_COMMIT" $CRYPTOPP_REPO
69
+            cd $INSTALL_DIR/cryptopp/build
70
+            cmake ..
71
+            make
72
+            if [ ! "$?" = "0" ]; then
73
+                exit 72581
74
+            fi
75
+            make install
76
+        fi
77
+    fi
78
+
79
+    if grep -Fxq "install_cryptopp" $COMPLETION_FILE; then
80
+        return
81
+    fi
82
+
83
+    if [ ! -d $INSTALL_DIR ]; then
84
+        mkdir -p $INSTALL_DIR
85
+    fi
86
+
87
+    apt-get -y install build-essential
88
+
89
+    git_clone $CRYPTOPP_REPO $INSTALL_DIR/cryptopp
90
+    cd $INSTALL_DIR/cryptopp
91
+    git checkout $CRYPTOPP_COMMIT -b $CRYPTOPP_COMMIT
92
+    mkdir -p $INSTALL_DIR/cryptopp/build
93
+    cd $INSTALL_DIR/cryptopp/build
94
+    cmake ..
95
+    make
96
+    if [ ! "$?" = "0" ]; then
97
+        exit 62826
98
+    fi
99
+    make install
100
+
101
+    echo 'install_cryptopp' >> $COMPLETION_FILE
102
+}
103
+
104
+# NOTE: deliberately there is no "exit 0"