瀏覽代碼

tahoelafs directory

Bob Mottram 7 年之前
父節點
當前提交
e543d160fa
共有 1 個檔案被更改,包括 60 行新增49 行删除
  1. 60
    49
      src/freedombone-app-tahoelafs

+ 60
- 49
src/freedombone-app-tahoelafs 查看文件

@@ -44,8 +44,9 @@ TAHOELAFS_STORAGE_PORT=50214
44 44
 TAHOELAFS_ONION_PORT=8096
45 45
 TAHOELAFS_STORAGE_ONION_PORT=8097
46 46
 
47
-TAHOE_COMMAND="cd /home/tahoelafs/tahoelafs && venv/bin/tahoe"
48
-tahoelafs_storage_file=/home/tahoelafs/client/private/servers.yaml
47
+TAHOE_DIR=/home/tahoelafs
48
+TAHOE_COMMAND="cd $TAHOE_DIR/tahoelafs && venv/bin/tahoe"
49
+tahoelafs_storage_file=$TAHOE_DIR/client/private/servers.yaml
49 50
 
50 51
 TAHOELAFS_SHARES_NEEDED=3
51 52
 TAHOELAFS_SHARES_HAPPY=7
@@ -164,13 +165,13 @@ function edit_tahoelafs_shares {
164 165
         TAHOELAFS_SHARES_TOTAL=${tl_total}
165 166
     fi
166 167
 
167
-    sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
168
-    sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
169
-    sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
168
+    sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
169
+    sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
170
+    sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/client/tahoe.cfg
170 171
 
171
-    sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
172
-    sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
173
-    sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
172
+    sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
173
+    sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
174
+    sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" $TAHOE_DIR/tahoelafs/storage/tahoe.cfg
174 175
 
175 176
     systemctl restart tahoelafs-storage
176 177
     systemctl restart tahoelafs-client
@@ -263,7 +264,7 @@ function tahoelafs_setup_storage_config {
263 264
     echo '[connections]' >> $config_file
264 265
     echo 'tcp = tor' >> $config_file
265 266
 
266
-    chown -R tahoelafs:debian-tor /home/tahoelafs
267
+    chown -R tahoelafs:debian-tor $TAHOE_DIR
267 268
 }
268 269
 
269 270
 function install_interactive_tahoelafs {
@@ -272,22 +273,22 @@ function install_interactive_tahoelafs {
272 273
 }
273 274
 
274 275
 function upgrade_tahoelafs {
275
-    if [ ! -d /home/tahoelafs/tahoelafs ]; then
276
+    if [ ! -d $TAHOE_DIR/tahoelafs ]; then
276 277
         return
277 278
     fi
278 279
     systemctl stop tahoelafs
279 280
     function_check set_repo_commit
280
-    set_repo_commit /home/tahoelafs/tahoelafs "tahoelafs commit" "$TAHOELAFS_COMMIT" $TAHOELAFS_REPO
281
-    cd /home/tahoelafs/tahoelafs
281
+    set_repo_commit $TAHOE_DIR/tahoelafs "tahoelafs commit" "$TAHOELAFS_COMMIT" $TAHOELAFS_REPO
282
+    cd $TAHOE_DIR/tahoelafs
282 283
     git submodule update --init --recursive
283 284
     virtualenv venv
284 285
     venv/bin/pip install --editable .
285
-    chown -R tahoelafs:debian-tor /home/tahoelafs
286
+    chown -R tahoelafs:debian-tor $TAHOE_DIR
286 287
     systemctl start tahoelafs
287 288
 }
288 289
 
289 290
 function backup_local_tahoelafs {
290
-    source_directory=/home/tahoelafs
291
+    source_directory=$TAHOE_DIR
291 292
     if [ ! -d $source_directory ]; then
292 293
         return
293 294
     fi
@@ -304,21 +305,21 @@ function restore_local_tahoelafs {
304 305
     systemctl stop tahoelafs-client
305 306
     temp_restore_dir=/root/temptahoelafs
306 307
     restore_directory_from_usb $temp_restore_dir tahoelafs
307
-    mv /home/tahoelafs /home/tahoelafs-old
308
-    cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs
308
+    mv $TAHOE_DIR ${TAHOE_DIR}-old
309
+    cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
309 310
     if [ ! "$?" = "0" ]; then
310
-        mv /home/tahoelafs-old /home/tahoelafs
311
+        mv ${TAHOE_DIR}-old $TAHOE_DIR
311 312
         exit 246833
312 313
     fi
313
-    rm -rf /home/tahoelafs-old
314
-    chown -R tahoelafs:debian-tor /home/tahoelafs
314
+    rm -rf ${TAHOE_DIR}-old
315
+    chown -R tahoelafs:debian-tor $TAHOE_DIR
315 316
     systemctl start tahoelafs-client
316 317
     systemctl start tahoelafs-storage
317 318
     echo $"Restore complete"
318 319
 }
319 320
 
320 321
 function backup_remote_tahoelafs {
321
-    source_directory=/home/tahoelafs
322
+    source_directory=$TAHOE_DIR
322 323
     if [ ! -d $source_directory ]; then
323 324
         return
324 325
     fi
@@ -337,14 +338,14 @@ function restore_remote_tahoelafs {
337 338
     systemctl stop tahoelafs-client
338 339
     temp_restore_dir=/root/temptahoelafs
339 340
     restore_directory_from_friend $temp_restore_dir tahoelafs
340
-    mv /home/tahoelafs /home/tahoelafs-old
341
-    cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs
341
+    mv $TAHOE_DIR ${TAHOE_DIR}-old
342
+    cp -r $temp_restore_dir$TAHOE_DIR $TAHOE_DIR
342 343
     if [ ! "$?" = "0" ]; then
343
-        mv /home/tahoelafs-old /home/tahoelafs
344
+        mv ${TAHOE_DIR}old $TAHOE_DIR
344 345
         exit 623925
345 346
     fi
346
-    rm -rf /home/tahoelafs-old
347
-    chown -R tahoelafs:debian-tor /home/tahoelafs
347
+    rm -rf ${$TAHOE_DIR}-old
348
+    chown -R tahoelafs:debian-tor $TAHOE_DIR
348 349
     systemctl start tahoelafs-client
349 350
     systemctl start tahoelafs-storage
350 351
     echo $"Restore complete"
@@ -384,8 +385,8 @@ function remove_tahoelafs {
384 385
     remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick)
385 386
     sed -i '/HidServAuth /d' /etc/tor/torrc
386 387
     deluser tahoelafs
387
-    if [ -d /home/tahoelafs ]; then
388
-        rm -rf /home/tahoelafs
388
+    if [ -d $TAHOE_DIR ]; then
389
+        rm -rf $TAHOE_DIR
389 390
     fi
390 391
     remove_app tahoelafs
391 392
     if [ -f /etc/nginx/.htpasswd-tahoelafs ]; then
@@ -398,15 +399,25 @@ function remove_tahoelafs {
398 399
 function install_tahoelafs_to_directory {
399 400
     tahoe_dir=$1
400 401
 
402
+    apt-get -yq install build-essential autoconf python-dev
401 403
     git_clone $TAHOELAFS_REPO $tahoe_dir
402 404
     cd $tahoe_dir
403 405
     git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT
404 406
     git submodule update --init --recursive
405 407
     virtualenv venv --distribute
406 408
     venv/bin/pip uninstall --yes setuptools
407
-    venv/bin/pip install setuptools==11.3
408
-    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
409
-    venv/bin/pip install cryptography==1.7.2 markerlib==0.6.0 distribute==0.7.3
409
+    venv/bin/pip install setuptools==36.0.1
410
+    venv/bin/pip install six==1.10.0
411
+    venv/bin/pip install packaging==16.8
412
+    venv/bin/pip install attrs==17.2.0
413
+    venv/bin/pip install appdirs==1.4.3
414
+    venv/bin/pip install pycrypto==2.6.1
415
+
416
+
417
+    venv/bin/pip install cffi==1.9.1
418
+    venv/bin/pip install cryptography==1.7.2
419
+    venv/bin/pip install markerlib==0.6.0
420
+    venv/bin/pip install distribute==0.7.3
410 421
     venv/bin/pip install txtorcon==0.18.0
411 422
     venv/bin/pip install --editable .
412 423
 }
@@ -496,7 +507,7 @@ function create_tahoelafs_client {
496 507
 }
497 508
 
498 509
 function get_tahoelafs_furl {
499
-    furl=$(cat /home/tahoelafs/storage/private/storage.furl)
510
+    furl=$(cat $TAHOE_DIR/storage/private/storage.furl)
500 511
     furl_1=$(echo "${furl}" | awk -F ' ' '{print $1}')
501 512
     furl_2=$(echo "${furl}" | awk -F ':' '{print $5}')
502 513
     echo "${furl_1}:${furl_2}"
@@ -511,7 +522,7 @@ function get_tahoelafs_storage_hostname {
511 522
 }
512 523
 
513 524
 function get_tahoelafs_public_key {
514
-    echo "$(cat /home/tahoelafs/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
525
+    echo "$(cat $TAHOE_DIR/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
515 526
 }
516 527
 
517 528
 function add_tahoelafs_server {
@@ -572,12 +583,12 @@ function create_tahoelafs_daemon {
572 583
     echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
573 584
     echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
574 585
     echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE
575
-    echo "WorkingDirectory=/home/tahoelafs/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
576
-    echo "ExecStart=/home/tahoelafs/tahoelafs/venv/bin/tahoe run /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
577
-    echo "ExecStop=/home/tahoelafs/tahoelafs/venv/bin/tahoe stop /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
586
+    echo "WorkingDirectory=${TAHOE_DIR}/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
587
+    echo "ExecStart=${TAHOE_DIR}/tahoelafs/venv/bin/tahoe run ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
588
+    echo "ExecStop=${TAHOE_DIR}/tahoelafs/venv/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
578 589
     echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
579 590
     echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
580
-    echo "Environment=\"USER=tahoelafs\" \"HOME=/home/tahoelafs\"" >> $TAHOELAFS_DAEMON_FILE
591
+    echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"" >> $TAHOELAFS_DAEMON_FILE
581 592
     echo '' >> $TAHOELAFS_DAEMON_FILE
582 593
     echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
583 594
     echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
@@ -646,27 +657,27 @@ function install_tahoelafs {
646 657
     apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi python-virtualenv
647 658
 
648 659
     # create a user
649
-    if [ ! -d /home/tahoelafs ]; then
660
+    if [ ! -d $TAHOE_DIR ]; then
650 661
         # add a gogs user account
651 662
         adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs
652 663
         adduser tahoelafs debian-tor
653 664
     fi
654 665
 
655
-    if [ -d /home/tahoelafs/Maildir ]; then
656
-        rm -rf /home/tahoelafs/Maildir
666
+    if [ -d $TAHOE_DIR/Maildir ]; then
667
+        rm -rf $TAHOE_DIR/Maildir
657 668
     fi
658 669
 
659
-    install_tahoelafs_to_directory /home/tahoelafs/tahoelafs
670
+    install_tahoelafs_to_directory $TAHOE_DIR/tahoelafs
660 671
 
661 672
     # remove files we don't need
662
-    rm -rf /home/tahoelafs/.mutt
663
-    rm /home/tahoelafs/.emacs-mutt
664
-    rm /home/tahoelafs/.muttrc
665
-    rm /home/tahoelafs/.mutt-alias
666
-    rm /home/tahoelafs/.procmailrc
673
+    rm -rf $TAHOE_DIR/.mutt
674
+    rm $TAHOE_DIR/.emacs-mutt
675
+    rm $TAHOE_DIR/.muttrc
676
+    rm $TAHOE_DIR/.mutt-alias
677
+    rm $TAHOE_DIR/.procmailrc
667 678
 
668 679
     # set permissions
669
-    chown -R tahoelafs:debian-tor /home/tahoelafs
680
+    chown -R tahoelafs:debian-tor $TAHOE_DIR
670 681
 
671 682
     node_nick=$(get_tahoelafs_nick)
672 683
     client_nick=${MY_USERNAME}-client
@@ -677,14 +688,14 @@ function install_tahoelafs {
677 688
     # create an onion address for client node
678 689
     TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
679 690
 
680
-    create_tahoelafs_stealth_node /home/tahoelafs/storage /home/tahoelafs/client ${node_nick} ${client_nick}
691
+    create_tahoelafs_stealth_node $TAHOE_DIR/storage $TAHOE_DIR/client ${node_nick} ${client_nick}
681 692
 
682 693
     # start the storage node
683
-    su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/storage' - tahoelafs
694
+    su -c "$TAHOE_DIR/tahoelafs/venv/bin/python2 $TAHOE_DIR/tahoelafs/venv/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs
684 695
     create_tahoelafs_daemon "storage"
685 696
 
686 697
     # start the client
687
-    su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/client' - tahoelafs
698
+    su -c "$TAHOE_DIR/tahoelafs/venv/bin/python2 $TAHOE_DIR/tahoelafs/venv/bin/tahoe start $TAHOE_DIR/client" - tahoelafs
688 699
     add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)"
689 700
     if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then
690 701
         echo $'Unable to create tahoelafs server'