瀏覽代碼

Set tahoelafs shares

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

+ 67
- 11
src/freedombone-app-tahoelafs 查看文件

46
 TAHOE_COMMAND="cd /home/tahoelafs/tahoelafs && venv/bin/tahoe"
46
 TAHOE_COMMAND="cd /home/tahoelafs/tahoelafs && venv/bin/tahoe"
47
 tahoelafs_storage_file=/home/tahoelafs/client/private/servers.yaml
47
 tahoelafs_storage_file=/home/tahoelafs/client/private/servers.yaml
48
 
48
 
49
+TAHOELAFS_SHARES_NEEDED=3
50
+TAHOELAFS_SHARES_HAPPY=7
51
+TAHOELAFS_SHARES_TOTAL=10
52
+
49
 tahoelafs_variables=(ONION_ONLY
53
 tahoelafs_variables=(ONION_ONLY
50
                      MY_USERNAME
54
                      MY_USERNAME
51
                      TAHOELAFS_REPO
55
                      TAHOELAFS_REPO
52
-                     TAHOELAFS_PORT)
56
+                     TAHOELAFS_PORT
57
+                     TAHOELAFS_SHARES_NEEDED
58
+                     TAHOELAFS_SHARES_HAPPY
59
+                     TAHOELAFS_SHARES_TOTAL)
53
 
60
 
54
 function add_tahoelafs_storage_node_interactive {
61
 function add_tahoelafs_storage_node_interactive {
55
     data=$(tempfile 2>/dev/null)
62
     data=$(tempfile 2>/dev/null)
78
 
85
 
79
     add_tahoelafs_server "${storage_hostname}" "${public_key}" "${nick}" "${furl}"
86
     add_tahoelafs_server "${storage_hostname}" "${public_key}" "${nick}" "${furl}"
80
 
87
 
81
-    if grep -q "$public_key" $tahoelafs_storage_file; then
88
+    if grep -q "$public_key" ${tahoelafs_storage_file}; then
82
         dialog --title $"Add Tahoe-LAFS storage node" \
89
         dialog --title $"Add Tahoe-LAFS storage node" \
83
                --msgbox $"Storage node added" 6 40
90
                --msgbox $"Storage node added" 6 40
84
     fi
91
     fi
90
     systemctl restart tahoelafs-client
97
     systemctl restart tahoelafs-client
91
 }
98
 }
92
 
99
 
100
+function edit_tahoelafs_shares {
101
+    read_config_param TAHOELAFS_SHARES_NEEDED
102
+    read_config_param TAHOELAFS_SHARES_HAPPY
103
+    read_config_param TAHOELAFS_SHARES_TOTAL
104
+
105
+    data=$(tempfile 2>/dev/null)
106
+    trap "rm -f $data" 0 1 2 5 15
107
+    dialog --backtitle $"Freedombone Configuration" \
108
+           --title $"Tahoe-LAFS shares" \
109
+           --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
110
+           $"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
111
+           $"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
112
+           $"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
113
+           2> $data
114
+    sel=$?
115
+    case $sel in
116
+        1) return;;
117
+        255) return;;
118
+    esac
119
+    tl_needed="$(cat $data | sed -n 1p)"
120
+    tl_happy="$(cat $data | sed -n 2p)"
121
+    tl_total="$(cat $data | sed -n 3p)"
122
+    if [ ${#tl_needed} -gt 0 ]; then
123
+        TAHOELAFS_SHARES_NEEDED=${tl_needed}
124
+    fi
125
+    if [ ${#tl_happy} -gt 0 ]; then
126
+        TAHOELAFS_SHARES_HAPPY=${tl_happy}
127
+    fi
128
+    if [ ${#tl_total} -gt 0 ]; then
129
+        TAHOELAFS_SHARES_TOTAL=${tl_total}
130
+    fi
131
+
132
+    sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
133
+    sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
134
+    sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
135
+
136
+    sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
137
+    sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
138
+    sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
139
+
140
+    systemctl restart tahoelafs-storage
141
+    systemctl restart tahoelafs-client
142
+
143
+    dialog --title $"Tahoe-LAFS shares" \
144
+           --msgbox $"Shares settings changed" 6 40
145
+}
146
+
93
 function configure_interactive_tahoelafs {
147
 function configure_interactive_tahoelafs {
94
     data=$(tempfile 2>/dev/null)
148
     data=$(tempfile 2>/dev/null)
95
     trap "rm -f $data" 0 1 2 5 15
149
     trap "rm -f $data" 0 1 2 5 15
96
     dialog --backtitle $"Freedombone Configuration" \
150
     dialog --backtitle $"Freedombone Configuration" \
97
            --title $"Tahoe-LAFS" \
151
            --title $"Tahoe-LAFS" \
98
-           --radiolist $"The least authority is always the best" 10 50 3 \
152
+           --radiolist $"The least authority is always the best" 10 50 4 \
99
            1 "Add a storage node" off \
153
            1 "Add a storage node" off \
100
            2 "Manually edit storage nodes" off \
154
            2 "Manually edit storage nodes" off \
101
-           3 "Back to main menu" on 2> $data
155
+           3 "Shares settings" off \
156
+           4 "Back to main menu" on 2> $data
102
     sel=$?
157
     sel=$?
103
     case $sel in
158
     case $sel in
104
         1) exit 1;;
159
         1) exit 1;;
107
     case $(cat $data) in
162
     case $(cat $data) in
108
         1) add_tahoelafs_storage_node_interactive;;
163
         1) add_tahoelafs_storage_node_interactive;;
109
         2) edit_tahoelafs_nodes;;
164
         2) edit_tahoelafs_nodes;;
165
+        3) edit_tahoelafs_shares;;
110
     esac
166
     esac
111
 }
167
 }
112
 
168
 
117
     echo '[node]' > $config_file
173
     echo '[node]' > $config_file
118
     echo "nickname = $nick" >> $config_file
174
     echo "nickname = $nick" >> $config_file
119
     echo 'reveal-IP-address = false' >> $config_file
175
     echo 'reveal-IP-address = false' >> $config_file
120
-    echo "web.port = tcp:$TAHOELAFS_ONION_PORT:interface=127.0.0.1" >> $config_file
176
+    echo "web.port = tcp:${TAHOELAFS_ONION_PORT}:interface=127.0.0.1" >> $config_file
121
     echo 'web.static = public_html' >> $config_file
177
     echo 'web.static = public_html' >> $config_file
122
     echo 'tub.port = disabled' >> $config_file
178
     echo 'tub.port = disabled' >> $config_file
123
     echo 'tub.location = disabled' >> $config_file
179
     echo 'tub.location = disabled' >> $config_file
124
     echo '' >> $config_file
180
     echo '' >> $config_file
125
     echo '[client]' >> $config_file
181
     echo '[client]' >> $config_file
126
     echo 'introducer.furl =' >> $config_file
182
     echo 'introducer.furl =' >> $config_file
127
-    echo 'shares.needed = 3' >> $config_file
128
-    echo 'shares.happy = 7' >> $config_file
129
-    echo 'shares.total = 10' >> $config_file
183
+    echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
184
+    echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
185
+    echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
130
     echo '' >> $config_file
186
     echo '' >> $config_file
131
     echo '[storage]' >> $config_file
187
     echo '[storage]' >> $config_file
132
     echo 'enabled = false' >> $config_file
188
     echo 'enabled = false' >> $config_file
155
     echo 'introducer.furl =' >> $config_file
211
     echo 'introducer.furl =' >> $config_file
156
     echo 'helper.furl =' >> $config_file
212
     echo 'helper.furl =' >> $config_file
157
     echo '' >> $config_file
213
     echo '' >> $config_file
158
-    echo 'shares.needed = 3' >> $config_file
159
-    echo 'shares.happy = 7' >> $config_file
160
-    echo 'shares.total = 10' >> $config_file
214
+    echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
215
+    echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
216
+    echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
161
     echo '' >> $config_file
217
     echo '' >> $config_file
162
     echo '[storage]' >> $config_file
218
     echo '[storage]' >> $config_file
163
     echo 'enabled = true' >> $config_file
219
     echo 'enabled = true' >> $config_file