Parcourir la source

tahoelafs storage node

Bob Mottram il y a 8 ans
Parent
révision
4cf81861a1
2 fichiers modifiés avec 151 ajouts et 113 suppressions
  1. 150
    112
      src/freedombone-app-tahoelafs
  2. 1
    1
      src/freedombone-controlpanel

+ 150
- 112
src/freedombone-app-tahoelafs Voir le fichier

@@ -38,7 +38,6 @@ TAHOELAFS_REPO="https://github.com/tahoe-lafs/tahoe-lafs"
38 38
 TAHOELAFS_COMMIT='bb782b0331a60de438136a593bba18338d8d866b'
39 39
 
40 40
 TAHOELAFS_PORT=50213
41
-#TAHOELAFS_WEB_PORT=50214
42 41
 TAHOELAFS_ONION_PORT=8096
43 42
 
44 43
 TAHOELAFS_SHARED_DIR='Shared'
@@ -50,6 +49,7 @@ tahoelafs_variables=(ONION_ONLY
50 49
 
51 50
 function tahoelafs_setup_config {
52 51
     config_file=$1
52
+    nick="$2"
53 53
 
54 54
     if ! grep -q "[node]" $config_file; then
55 55
         echo '' >> $config_file
@@ -82,13 +82,9 @@ function tahoelafs_setup_config {
82 82
     sed -i "s|tub.port.*|tub.port = tcp:${TAHOELAFS_ONION_PORT}:interface=127.0.0.1|g" $config_file
83 83
     sed -i "s|tub.location.*|tub.location = tor:${TAHOELAFS_ONION_HOSTNAME}:${TAHOELAFS_PORT}|g" $config_file
84 84
 
85
-    sed -i "s|nickname =.*|nickname = $HOSTNAME|g" $config_file
85
+    sed -i "s|nickname =.*|nickname = ${NICK}|g" $config_file
86 86
 
87
-    if ! grep -q "[storage]" $config_file; then
88
-        echo '' >> $config_file
89
-        echo '[storage]' >> $config_file
90
-        echo 'enabled = false' >> $config_file
91
-    fi
87
+    chown -R tahoelafs:debian-tor /home/tahoelafs
92 88
 }
93 89
 
94 90
 function install_interactive_tahoelafs {
@@ -109,7 +105,7 @@ function upgrade_tahoelafs {
109 105
 }
110 106
 
111 107
 function backup_local_tahoelafs {
112
-    source_directory=/home/tahoelafs/data
108
+    source_directory=/home/tahoelafs
113 109
     if [ ! -d $source_directory ]; then
114 110
         return
115 111
     fi
@@ -122,47 +118,53 @@ function backup_local_tahoelafs {
122 118
 
123 119
 function restore_local_tahoelafs {
124 120
     echo $"Restoring Tahoe-LAFS introducer"
125
-    systemctl stop tahoelafs
121
+    systemctl stop tahoelafs-storage
122
+    systemctl stop tahoelafs-introducer
126 123
     temp_restore_dir=/root/temptahoelafs
127 124
     restore_directory_from_usb $temp_restore_dir tahoelafs
128
-    mv /home/tahoelafs/data /home/tahoelafs/data-old
129
-    cp -r $temp_restore_dir/home/tahoelafs/data /home/tahoelafs/data
125
+    mv /home/tahoelafs /home/tahoelafs-old
126
+    cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs
130 127
     if [ ! "$?" = "0" ]; then
131
-        mv /home/tahoelafs/data-old /home/tahoelafs/data
128
+        mv /home/tahoelafs-old /home/tahoelafs
132 129
         exit 246833
133 130
     fi
134
-    rm -rf /home/tahoelafs/data
131
+    rm -rf /home/tahoelafs-old
135 132
     chown -R tahoelafs:debian-tor /home/tahoelafs
136
-    systemctl start tahoelafs
133
+    systemctl start tahoelafs-introducer
134
+    systemctl start tahoelafs-storage
137 135
     echo $"Restore complete"
138 136
 }
139 137
 
140 138
 function backup_remote_tahoelafs {
141
-    source_directory=/home/tahoelafs/data
139
+    source_directory=/home/tahoelafs
142 140
     if [ ! -d $source_directory ]; then
143 141
         return
144 142
     fi
145
-    systemctl stop tahoelafs
143
+    systemctl stop tahoelafs-storage
144
+    systemctl stop tahoelafs-introducer
146 145
     dest_directory=tahoelafs
147 146
     function_check backup_directory_to_usb
148 147
     backup_directory_to_friend $source_directory $dest_directory
149
-    systemctl start tahoelafs
148
+    systemctl start tahoelafs-introducer
149
+    systemctl start tahoelafs-storage
150 150
 }
151 151
 
152 152
 function restore_remote_tahoelafs {
153 153
     echo $"Restoring Tahoe-LAFS introducer"
154
-    systemctl stop tahoelafs
154
+    systemctl stop tahoelafs-storage
155
+    systemctl stop tahoelafs-introducer
155 156
     temp_restore_dir=/root/temptahoelafs
156 157
     restore_directory_from_friend $temp_restore_dir tahoelafs
157
-    mv /home/tahoelafs/data /home/tahoelafs/data-old
158
-    cp -r $temp_restore_dir/home/tahoelafs/data /home/tahoelafs/data
158
+    mv /home/tahoelafs /home/tahoelafs-old
159
+    cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs
159 160
     if [ ! "$?" = "0" ]; then
160
-        mv /home/tahoelafs/data-old /home/tahoelafs/data
161
+        mv /home/tahoelafs-old /home/tahoelafs
161 162
         exit 623925
162 163
     fi
163
-    rm -rf /home/tahoelafs/data-old
164
+    rm -rf /home/tahoelafs-old
164 165
     chown -R tahoelafs:debian-tor /home/tahoelafs
165
-    systemctl start tahoelafs
166
+    systemctl start tahoelafs-introducer
167
+    systemctl start tahoelafs-storage
166 168
     echo $"Restore complete"
167 169
 }
168 170
 
@@ -180,14 +182,18 @@ function remove_tahoelafs {
180 182
         systemctl reload nginx
181 183
     fi
182 184
 
183
-    systemctl stop tahoelafs
184
-    systemctl disable tahoelafs
185
-    rm /etc/systemd/system/tahoelafs.service
185
+    systemctl stop tahoelafs-storage
186
+    systemctl disable tahoelafs-storage
187
+    rm /etc/systemd/system/tahoelafs-storage.service
186 188
 
187
-    firewall_remove ${TAHOELAFS_PORT}
189
+    systemctl stop tahoelafs-introducer
190
+    systemctl disable tahoelafs-introducer
191
+    rm /etc/systemd/system/tahoelafs-introducer.service
192
+
193
+    #firewall_remove ${TAHOELAFS_PORT}
188 194
     rm -rf /var/lib/tahoelafs
189 195
     remove_completion_param install_tahoelafs
190
-    remove_completion_param configure_firewall_for_tahoelafs
196
+    #remove_completion_param configure_firewall_for_tahoelafs
191 197
     function_check remove_onion_service
192 198
     remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
193 199
     deluser tahoelafs
@@ -205,44 +211,100 @@ function configure_firewall_for_tahoelafs {
205 211
     mark_completed $FUNCNAME
206 212
 }
207 213
 
208
-function install_tahoelafs_web {
209
-    config_file=$1
214
+function install_tahoelafs_to_directory {
215
+    tahoe_dir=$1
216
+
217
+    git_clone $TAHOELAFS_REPO $tahoe_dir
218
+    cd $tahoe_dir
219
+    git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT
220
+    git submodule update --init --recursive
221
+    virtualenv venv --distribute
222
+    venv/bin/pip uninstall --yes setuptools
223
+    venv/bin/pip install setuptools==11.3
224
+    venv/bin/pip install six==1.10.0 packaging==16.8 attrs==16.3.0 appdirs==1.4.2 pycrypto==2.1.0 cffi==1.9.1
225
+    venv/bin/pip install cryptography==1.7.2 markerlib==0.6.0 distribute==0.7.3
226
+    venv/bin/pip install txtorcon==0.18.0
227
+    venv/bin/pip install --editable .
228
+}
229
+
230
+function create_tahoelafs_introducer {
231
+    introducer_dir="$1"
232
+
233
+    if [ -d ${introducer_dir} ]; then
234
+        return
235
+    fi
236
+
237
+    mkdir ${introducer_dir}
238
+    su -c "$TAHOE_COMMAND create-introducer -C ${introducer_dir} --hide-ip --hostname=127.0.0.1" - tahoelafs
239
+}
210 240
 
211
-    if [ ! -d /var/www/tahoelafs ]; then
212
-        mkdir -p /var/www/tahoelafs/htdocs
241
+function create_tahoelafs_storage_node {
242
+    # Nodes can store introducer
243
+    node_dir="$1"
244
+    furl="$2"
245
+
246
+    if [ ${#furl} -eq 0 ]; then
247
+        return
213 248
     fi
214
-    tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
215
-    echo 'server {' > $tahoelafs_nginx_site
216
-    echo "    listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;" >> $tahoelafs_nginx_site
217
-    echo "    server_name $TAHOELAFS_ONION_HOSTNAME;" >> $tahoelafs_nginx_site
218
-    echo '' >> $tahoelafs_nginx_site
219
-    function_check nginx_disable_sniffing
220
-    nginx_disable_sniffing tahoelafs
221
-    echo '' >> $tahoelafs_nginx_site
222
-    echo '  # Logs' >> $tahoelafs_nginx_site
223
-    echo '  access_log /dev/null;' >> $tahoelafs_nginx_site
224
-    echo '  error_log /dev/null;' >> $tahoelafs_nginx_site
225
-    echo '' >> $tahoelafs_nginx_site
226
-    echo '  # Root' >> $tahoelafs_nginx_site
227
-    echo "  root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
228
-    echo '' >> $tahoelafs_nginx_site
229
-    echo '  location / {' >> $tahoelafs_nginx_site
230
-    function_check nginx_limits
231
-    nginx_limits tahoelafs '15m'
232
-    echo '    rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
233
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $tahoelafs_nginx_site
234
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $tahoelafs_nginx_site
235
-    echo '    proxy_set_header Host $http_host;' >> $tahoelafs_nginx_site
236
-    echo '    proxy_set_header X-NginX-Proxy true;' >> $tahoelafs_nginx_site
237
-    echo "    proxy_pass http://localhost:${TAHOELAFS_WEB_PORT};" >> $tahoelafs_nginx_site
238
-    echo '    proxy_redirect off;' >> $tahoelafs_nginx_site
239
-    echo '  }' >> $tahoelafs_nginx_site
240
-    echo '}' >> $tahoelafs_nginx_site
241
-
242
-    function_check nginx_ensite
243
-    nginx_ensite tahoelafs
244
-
245
-    sed -i "s|web.port =.*|web.port = tcp:$TAHOELAFS_WEB_PORT:interface=127.0.0.1|g" $config_file
249
+
250
+    if [ -d ${node_dir} ]; then
251
+        return
252
+    fi
253
+
254
+    mkdir ${node_dir}
255
+    su -c "$TAHOE_COMMAND create-node -C ${node_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
256
+}
257
+
258
+function create_tahoelafs_client {
259
+    # Clients have no storage
260
+    client_dir="$1"
261
+    furl="$2"
262
+
263
+    if [ ${#furl} -eq 0 ]; then
264
+        return
265
+    fi
266
+
267
+    if [ -d ${client_dir} ]; then
268
+        return
269
+    fi
270
+
271
+    mkdir ${client_dir}
272
+    su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
273
+    sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' $client_dir/tahoe.cfg
274
+    sed -i 's|tub.port =.*|tub.port = disabled|g' $client_dir/tahoe.cfg
275
+    sed -i 's|tub.location =.*|tub.location = disabled|g' $client_dir/tahoe.cfg
276
+}
277
+
278
+function get_tahoelafs_introducer {
279
+    echo "$(cat /home/tahoelafs/.tahoe-introducer/private/introducer.furl)"
280
+}
281
+
282
+function create_tahoelafs_daemon {
283
+    daemon_name=$1
284
+
285
+
286
+    TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
287
+    echo '[Unit]' > $TAHOELAFS_DAEMON_FILE
288
+    echo "Description=Tahoe-LAFS ${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
289
+    echo 'After=syslog.target' >> $TAHOELAFS_DAEMON_FILE
290
+    echo 'After=network.target' >> $TAHOELAFS_DAEMON_FILE
291
+    echo '' >> $TAHOELAFS_DAEMON_FILE
292
+    echo '[Service]' >> $TAHOELAFS_DAEMON_FILE
293
+    echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
294
+    echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
295
+    echo "Group=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
296
+    echo "WorkingDirectory=/home/tahoelafs/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
297
+    echo "ExecStart=/home/tahoelafs/tahoelafs/venv/bin/tahoe run /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
298
+    echo "ExecStop=/home/tahoelafs/tahoelafs/venv/bin/tahoe stop /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
299
+    echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
300
+    echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
301
+    echo "Environment=\"USER=tahoelafs\" \"HOME=/home/tahoelafs\"" >> $TAHOELAFS_DAEMON_FILE
302
+    echo '' >> $TAHOELAFS_DAEMON_FILE
303
+    echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
304
+    echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
305
+    systemctl enable tahoelafs-${daemon_name}
306
+    systemctl daemon-reload
307
+    systemctl start tahoelafs-${daemon_name}
246 308
 }
247 309
 
248 310
 function install_tahoelafs {
@@ -264,23 +326,8 @@ function install_tahoelafs {
264 326
         rm -rf /home/tahoelafs/Maildir
265 327
     fi
266 328
 
267
-    git_clone $TAHOELAFS_REPO /home/tahoelafs/tahoelafs
268
-    cd /home/tahoelafs/tahoelafs
269
-    git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT
270
-    git submodule update --init --recursive
271
-    virtualenv venv --distribute
272
-    venv/bin/pip uninstall --yes setuptools
273
-    venv/bin/pip install setuptools==11.3
274
-    venv/bin/pip install six==1.10.0 packaging==16.8 attrs==16.3.0 appdirs==1.4.2 pycrypto==2.1.0 cffi==1.9.1
275
-    venv/bin/pip install cryptography==1.7.2 markerlib==0.6.0 distribute==0.7.3
276
-    venv/bin/pip install txtorcon==0.18.0
277
-    venv/bin/pip install --editable .
278
-    configure_firewall_for_tahoelafs
279
-
280
-    if [ -d /home/tahoelafs/data ]; then
281
-        rm -rf /home/tahoelafs/data
282
-    fi
283
-    mkdir /home/tahoelafs/data
329
+    install_tahoelafs_to_directory /home/tahoelafs/tahoelafs
330
+    #configure_firewall_for_tahoelafs
284 331
 
285 332
     # remove files we don't need
286 333
     rm -rf /home/tahoelafs/.mutt
@@ -293,50 +340,41 @@ function install_tahoelafs {
293 340
     chown -R tahoelafs:debian-tor /home/tahoelafs
294 341
 
295 342
     # create the introducer config
296
-    su -c "$TAHOE_COMMAND create-introducer -C /home/tahoelafs/data --hide-ip --hostname=127.0.0.1" - tahoelafs
297
-    TAHOELAFS_CONFIG=/home/tahoelafs/data/tahoe.cfg
298
-    if [ ! -f $TAHOELAFS_CONFIG ]; then
343
+    create_tahoelafs_introducer /home/tahoelafs/introducer
344
+    TAHOELAFS_INTRODUCER_CONFIG=/home/tahoelafs/introducer/tahoe.cfg
345
+    if [ ! -f $TAHOELAFS_INTRODUCER_CONFIG ]; then
299 346
         exit 62831
300 347
     fi
301 348
 
349
+    if [ ! -d /home/tahoelafs/storage ]; then
350
+        mkdir /home/tahoelafs/storage
351
+    fi
352
+    create_tahoelafs_storage_node /home/tahoelafs/storage "$(get_tahoelafs_introducer)"
353
+    TAHOELAFS_STORAGE_CONFIG=/home/tahoelafs/storage/tahoe.cfg
354
+    if [ ! -f $TAHOELAFS_STORAGE_CONFIG ]; then
355
+        exit 782523
356
+    fi
357
+
302 358
     # create an onion address
303 359
     TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs ${TAHOELAFS_PORT} ${TAHOELAFS_ONION_PORT})
304
-    tahoelafs_setup_config $TAHOELAFS_CONFIG
305 360
 
306
-    su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/data' - tahoelafs
307
-    TAHOELAFS_INTRODUCER=/home/tahoelafs/data/tahoe-introducer.tac
361
+    # start the introducer
362
+    tahoelafs_setup_config $TAHOELAFS_INTRODUCER_CONFIG ${PROJECT_NAME}-introducer
363
+    su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/introducer' - tahoelafs
364
+    TAHOELAFS_INTRODUCER=/home/tahoelafs/introducer/tahoe-introducer.tac
308 365
     if [ ! -f $TAHOELAFS_INTRODUCER ]; then
309 366
         echo $'Introducer file not found'
310 367
         exit 782253
311 368
     fi
312 369
 
313
-    # create a daemon
314
-    TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs.service
315
-    echo '[Unit]' > $TAHOELAFS_DAEMON_FILE
316
-    echo 'Description=Tahoe-LAFS introducer' >> $TAHOELAFS_DAEMON_FILE
317
-    echo 'After=syslog.target' >> $TAHOELAFS_DAEMON_FILE
318
-    echo 'After=network.target' >> $TAHOELAFS_DAEMON_FILE
319
-    echo '' >> $TAHOELAFS_DAEMON_FILE
320
-    echo '[Service]' >> $TAHOELAFS_DAEMON_FILE
321
-    echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
322
-    echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
323
-    echo "Group=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
324
-    echo "WorkingDirectory=/home/tahoelafs/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
325
-    echo "ExecStart=/home/tahoelafs/tahoelafs/venv/bin/tahoe run /home/tahoelafs/data" >> $TAHOELAFS_DAEMON_FILE
326
-    echo "ExecStop=/home/tahoelafs/tahoelafs/venv/bin/tahoe stop /home/tahoelafs/data" >> $TAHOELAFS_DAEMON_FILE
327
-    echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
328
-    echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
329
-    echo "Environment=\"USER=tahoelafs\" \"HOME=/home/tahoelafs\"" >> $TAHOELAFS_DAEMON_FILE
330
-    echo '' >> $TAHOELAFS_DAEMON_FILE
331
-    echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
332
-    echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
333
-    systemctl enable tahoelafs
334
-    systemctl daemon-reload
335
-    systemctl start tahoelafs
370
+    # start the storage node
371
+    su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/storage' - tahoelafs
336 372
 
337
-    set_completion_param "tahoelafs commit" "$TAHOELAFS_COMMIT"
373
+    # create daemons
374
+    create_tahoelafs_daemon introducer
375
+    create_tahoelafs_daemon storage
338 376
 
339
-    #install_tahoelafs_web $TAHOELAFS_CONFIG
377
+    set_completion_param "tahoelafs commit" "$TAHOELAFS_COMMIT"
340 378
 
341 379
     APP_INSTALLED=1
342 380
 }

+ 1
- 1
src/freedombone-controlpanel Voir le fichier

@@ -483,7 +483,7 @@ function show_tahoe_introducer {
483 483
     echo 'Tahoe-LAFS'
484 484
     echo '=========='
485 485
     echo ''
486
-    cat /home/tahoelafs/.tahoe-introducer/private/introducer.furl
486
+    get_tahoelafs_introducer
487 487
     echo ''
488 488
 }
489 489