freedombone-app-tahoelafs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Tahow-LAFS data storage grid implemented via Tor
  12. # https://k0rx.com/blog/2017/01/lafs.html
  13. # http://tahoe-lafs.readthedocs.io/en/latest/anonymity-configuration.html
  14. #
  15. # License
  16. # =======
  17. #
  18. # Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
  19. #
  20. # This program is free software: you can redistribute it and/or modify
  21. # it under the terms of the GNU Affero General Public License as published by
  22. # the Free Software Foundation, either version 3 of the License, or
  23. # (at your option) any later version.
  24. #
  25. # This program is distributed in the hope that it will be useful,
  26. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. # GNU Affero General Public License for more details.
  29. #
  30. # You should have received a copy of the GNU Affero General Public License
  31. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  32. VARIANTS='full full-vim cloud'
  33. IN_DEFAULT_INSTALL=0
  34. SHOW_ON_ABOUT=1
  35. TAHOELAFS_REPO="https://github.com/tahoe-lafs/tahoe-lafs"
  36. TAHOELAFS_COMMIT='bb782b0331a60de438136a593bba18338d8d866b'
  37. TAHOELAFS_PORT=50213
  38. TAHOELAFS_STORAGE_PORT=50214
  39. TAHOELAFS_ONION_PORT=8096
  40. TAHOELAFS_STORAGE_ONION_PORT=8097
  41. TAHOE_COMMAND="cd /home/tahoelafs/tahoelafs && venv/bin/tahoe"
  42. tahoelafs_storage_file=/home/tahoelafs/client/private/servers.yaml
  43. TAHOELAFS_SHARES_NEEDED=3
  44. TAHOELAFS_SHARES_HAPPY=7
  45. TAHOELAFS_SHARES_TOTAL=10
  46. tahoelafs_variables=(ONION_ONLY
  47. MY_USERNAME
  48. TAHOELAFS_REPO
  49. TAHOELAFS_PORT
  50. TAHOELAFS_SHARES_NEEDED
  51. TAHOELAFS_SHARES_HAPPY
  52. TAHOELAFS_SHARES_TOTAL)
  53. function add_tahoelafs_storage_node_interactive {
  54. data=$(tempfile 2>/dev/null)
  55. trap "rm -f $data" 0 1 2 5 15
  56. dialog --backtitle $"Freedombone Configuration" \
  57. --title $"Add Tahoe-LAFS storage node" \
  58. --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 75 5 \
  59. $"Hostname:" 1 1 "" 1 14 53 40 \
  60. $"Public Key:" 2 1 "" 2 14 53 255 \
  61. $"Nickname:" 3 1 "" 3 14 53 255 \
  62. $"FURL:" 4 1 "" 4 14 53 255 \
  63. 2> $data
  64. sel=$?
  65. case $sel in
  66. 1) return;;
  67. 255) return;;
  68. esac
  69. storage_hostname=$(cat $data | sed -n 1p)
  70. public_key="$(cat $data | sed -n 2p)"
  71. nick=$(cat $data | sed -n 3p)
  72. furl=$(cat $data | sed -n 4p)
  73. if [ ${#public_key} -eq 0 ]; then
  74. return
  75. fi
  76. add_tahoelafs_server "${storage_hostname}" "${public_key}" "${nick}" "${furl}"
  77. if grep -q "$public_key" ${tahoelafs_storage_file}; then
  78. dialog --title $"Add Tahoe-LAFS storage node" \
  79. --msgbox $"Storage node added" 6 40
  80. fi
  81. }
  82. function edit_tahoelafs_nodes {
  83. editor $tahoelafs_storage_file
  84. chown tahoelafs:debian-tor $tahoelafs_storage_file
  85. systemctl restart tahoelafs-client
  86. }
  87. function edit_tahoelafs_shares {
  88. read_config_param TAHOELAFS_SHARES_NEEDED
  89. read_config_param TAHOELAFS_SHARES_HAPPY
  90. read_config_param TAHOELAFS_SHARES_TOTAL
  91. data=$(tempfile 2>/dev/null)
  92. trap "rm -f $data" 0 1 2 5 15
  93. dialog --backtitle $"Freedombone Configuration" \
  94. --title $"Tahoe-LAFS shares" \
  95. --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
  96. $"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
  97. $"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
  98. $"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
  99. 2> $data
  100. sel=$?
  101. case $sel in
  102. 1) return;;
  103. 255) return;;
  104. esac
  105. tl_needed="$(cat $data | sed -n 1p)"
  106. tl_happy="$(cat $data | sed -n 2p)"
  107. tl_total="$(cat $data | sed -n 3p)"
  108. if [ ${#tl_needed} -gt 0 ]; then
  109. TAHOELAFS_SHARES_NEEDED=${tl_needed}
  110. fi
  111. if [ ${#tl_happy} -gt 0 ]; then
  112. TAHOELAFS_SHARES_HAPPY=${tl_happy}
  113. fi
  114. if [ ${#tl_total} -gt 0 ]; then
  115. TAHOELAFS_SHARES_TOTAL=${tl_total}
  116. fi
  117. sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
  118. sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
  119. sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" /home/tahoelafs/tahoelafs/client/tahoe.cfg
  120. sed -i "s|shares.needed.*|shares.needed = ${TAHOELAFS_SHARES_NEEDED}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
  121. sed -i "s|shares.happy.*|shares.happy = ${TAHOELAFS_SHARES_HAPPY}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
  122. sed -i "s|shares.total.*|shares.total = ${TAHOELAFS_SHARES_TOTAL}|g" /home/tahoelafs/tahoelafs/storage/tahoe.cfg
  123. systemctl restart tahoelafs-storage
  124. systemctl restart tahoelafs-client
  125. dialog --title $"Tahoe-LAFS shares" \
  126. --msgbox $"Shares settings changed" 6 40
  127. }
  128. function configure_interactive_tahoelafs {
  129. data=$(tempfile 2>/dev/null)
  130. trap "rm -f $data" 0 1 2 5 15
  131. dialog --backtitle $"Freedombone Configuration" \
  132. --title $"Tahoe-LAFS" \
  133. --radiolist $"The least authority is always the best" 10 50 4 \
  134. 1 "Add a storage node" off \
  135. 2 "Manually edit storage nodes" off \
  136. 3 "Shares settings" off \
  137. 4 "Back to main menu" on 2> $data
  138. sel=$?
  139. case $sel in
  140. 1) exit 1;;
  141. 255) exit 1;;
  142. esac
  143. case $(cat $data) in
  144. 1) add_tahoelafs_storage_node_interactive;;
  145. 2) edit_tahoelafs_nodes;;
  146. 3) edit_tahoelafs_shares;;
  147. esac
  148. }
  149. function tahoelafs_setup_client_config {
  150. config_file=$1
  151. nick="$2"
  152. echo '[node]' > $config_file
  153. echo "nickname = $nick" >> $config_file
  154. echo 'reveal-IP-address = false' >> $config_file
  155. echo "web.port = tcp:${TAHOELAFS_PORT}:interface=127.0.0.1" >> $config_file
  156. echo 'web.static = public_html' >> $config_file
  157. echo 'tub.port = disabled' >> $config_file
  158. echo 'tub.location = disabled' >> $config_file
  159. echo '' >> $config_file
  160. echo '[client]' >> $config_file
  161. echo 'introducer.furl =' >> $config_file
  162. echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
  163. echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
  164. echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
  165. echo '' >> $config_file
  166. echo '[storage]' >> $config_file
  167. echo 'enabled = false' >> $config_file
  168. echo 'reserved_space = 3G' >> $config_file
  169. echo '' >> $config_file
  170. echo '[helper]' >> $config_file
  171. echo 'enabled = false' >> $config_file
  172. echo '' >> $config_file
  173. echo '[connections]' >> $config_file
  174. echo 'tcp = tor' >> $config_file
  175. }
  176. function tahoelafs_setup_storage_config {
  177. config_file=$1
  178. nick="$2"
  179. echo '[node]' > $config_file
  180. echo "nickname = $nick" >> $config_file
  181. echo 'reveal-IP-address = false' >> $config_file
  182. echo 'web.port =' >> $config_file
  183. echo 'web.static = public_html' >> $config_file
  184. echo "tub.port = tcp:${TAHOELAFS_STORAGE_ONION_PORT}:interface=127.0.0.1" >> $config_file
  185. echo "tub.location = tor:${TAHOELAFS_STORAGE_ONION_HOSTNAME}:${TAHOELAFS_STORAGE_PORT}" >> $config_file
  186. echo '' >> $config_file
  187. echo '[client]' >> $config_file
  188. echo 'introducer.furl =' >> $config_file
  189. echo 'helper.furl =' >> $config_file
  190. echo '' >> $config_file
  191. echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
  192. echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
  193. echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
  194. echo '' >> $config_file
  195. echo '[storage]' >> $config_file
  196. echo 'enabled = true' >> $config_file
  197. echo 'reserved_space = 3G' >> $config_file
  198. echo 'expire.enabled = true' >> $config_file
  199. echo 'expire.mode = age' >> $config_file
  200. echo 'expire.override_lease_duration = 3 months' >> $config_file
  201. echo '' >> $config_file
  202. echo '[helper]' >> $config_file
  203. echo 'enabled = false' >> $config_file
  204. echo '' >> $config_file
  205. echo '[connections]' >> $config_file
  206. echo 'tcp = tor' >> $config_file
  207. chown -R tahoelafs:debian-tor /home/tahoelafs
  208. }
  209. function install_interactive_tahoelafs {
  210. echo -n ''
  211. APP_INSTALLED=1
  212. }
  213. function upgrade_tahoelafs {
  214. systemctl stop tahoelafs
  215. function_check set_repo_commit
  216. set_repo_commit /home/tahoelafs/tahoelafs "tahoelafs commit" "$TAHOELAFS_COMMIT" $TAHOELAFS_REPO
  217. cd /home/tahoelafs/tahoelafs
  218. git submodule update --init --recursive
  219. virtualenv venv
  220. venv/bin/pip install --editable .
  221. chown -R tahoelafs:debian-tor /home/tahoelafs
  222. systemctl start tahoelafs
  223. }
  224. function backup_local_tahoelafs {
  225. source_directory=/home/tahoelafs
  226. if [ ! -d $source_directory ]; then
  227. return
  228. fi
  229. systemctl stop tahoelafs
  230. dest_directory=tahoelafs
  231. function_check backup_directory_to_usb
  232. backup_directory_to_usb $source_directory $dest_directory
  233. systemctl start tahoelafs
  234. }
  235. function restore_local_tahoelafs {
  236. echo $"Restoring Tahoe-LAFS"
  237. systemctl stop tahoelafs-storage
  238. systemctl stop tahoelafs-client
  239. temp_restore_dir=/root/temptahoelafs
  240. restore_directory_from_usb $temp_restore_dir tahoelafs
  241. mv /home/tahoelafs /home/tahoelafs-old
  242. cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs
  243. if [ ! "$?" = "0" ]; then
  244. mv /home/tahoelafs-old /home/tahoelafs
  245. exit 246833
  246. fi
  247. rm -rf /home/tahoelafs-old
  248. chown -R tahoelafs:debian-tor /home/tahoelafs
  249. systemctl start tahoelafs-client
  250. systemctl start tahoelafs-storage
  251. echo $"Restore complete"
  252. }
  253. function backup_remote_tahoelafs {
  254. source_directory=/home/tahoelafs
  255. if [ ! -d $source_directory ]; then
  256. return
  257. fi
  258. systemctl stop tahoelafs-storage
  259. systemctl stop tahoelafs-client
  260. dest_directory=tahoelafs
  261. function_check backup_directory_to_usb
  262. backup_directory_to_friend $source_directory $dest_directory
  263. systemctl start tahoelafs-client
  264. systemctl start tahoelafs-storage
  265. }
  266. function restore_remote_tahoelafs {
  267. echo $"Restoring Tahoe-LAFS"
  268. systemctl stop tahoelafs-storage
  269. systemctl stop tahoelafs-client
  270. temp_restore_dir=/root/temptahoelafs
  271. restore_directory_from_friend $temp_restore_dir tahoelafs
  272. mv /home/tahoelafs /home/tahoelafs-old
  273. cp -r $temp_restore_dir/home/tahoelafs /home/tahoelafs
  274. if [ ! "$?" = "0" ]; then
  275. mv /home/tahoelafs-old /home/tahoelafs
  276. exit 623925
  277. fi
  278. rm -rf /home/tahoelafs-old
  279. chown -R tahoelafs:debian-tor /home/tahoelafs
  280. systemctl start tahoelafs-client
  281. systemctl start tahoelafs-storage
  282. echo $"Restore complete"
  283. }
  284. function reconfigure_tahoelafs {
  285. if [ -f $tahoelafs_storage_file ]; then
  286. shred -zu $tahoelafs_storage_file
  287. fi
  288. sed -i '/HidServAuth /d' /etc/tor/torrc
  289. }
  290. function remove_tahoelafs {
  291. if [ -f /etc/nginx/sites-available/tahoelafs ]; then
  292. nginx_dissite tahoelafs
  293. rm /etc/nginx/sites-available/tahoelafs
  294. if [ -d /var/www/tahoelafs ]; then
  295. rm -rf /var/www/tahoelafs
  296. fi
  297. systemctl reload nginx
  298. fi
  299. systemctl stop tahoelafs-storage
  300. systemctl disable tahoelafs-storage
  301. rm /etc/systemd/system/tahoelafs-storage.serice
  302. systemctl stop tahoelafs-client
  303. systemctl disable tahoelafs-client
  304. rm /etc/systemd/system/tahoelafs-client.serice
  305. if [ -d /var/lib/tahoelafs ]; then
  306. rm -rf /var/lib/tahoelafs
  307. fi
  308. remove_completion_param install_tahoelafs
  309. function_check remove_onion_service
  310. remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
  311. remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick)
  312. sed -i '/HidServAuth /d' /etc/tor/torrc
  313. deluser tahoelafs
  314. if [ -d /home/tahoelafs ]; then
  315. rm -rf /home/tahoelafs
  316. fi
  317. remove_app tahoelafs
  318. systemctl reload tor
  319. }
  320. function install_tahoelafs_to_directory {
  321. tahoe_dir=$1
  322. git_clone $TAHOELAFS_REPO $tahoe_dir
  323. cd $tahoe_dir
  324. git checkout $TAHOELAFS_COMMIT -b $TAHOELAFS_COMMIT
  325. git submodule update --init --recursive
  326. virtualenv venv --distribute
  327. venv/bin/pip uninstall --yes setuptools
  328. venv/bin/pip install setuptools==11.3
  329. 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
  330. venv/bin/pip install cryptography==1.7.2 markerlib==0.6.0 distribute==0.7.3
  331. venv/bin/pip install txtorcon==0.18.0
  332. venv/bin/pip install --editable .
  333. }
  334. function create_tahoelafs_stealth_node {
  335. node_dir="$1"
  336. client_dir="$2"
  337. node_nick="$3"
  338. client_nick="$4"
  339. if [ ${#node_dir} -eq 0 ]; then
  340. echo $'No tahoe-LAFS storage node directory given'
  341. exit 783522
  342. fi
  343. if [ ${#client_dir} -eq 0 ]; then
  344. echo $'No tahoe-LAFS client directory given'
  345. exit 368935
  346. fi
  347. if [ ${#node_nick} -eq 0 ]; then
  348. echo $'No tahoe-LAFS node nick given'
  349. exit 672351
  350. fi
  351. if [ ${#client_nick} -eq 0 ]; then
  352. echo $'No tahoe-LAFS client nick given'
  353. exit 682362
  354. fi
  355. if [ ! -f ${node_dir}/tahoe.cfg ]; then
  356. su -c "mkdir ${node_dir}" - tahoelafs
  357. su -c "$TAHOE_COMMAND create-node -C ${node_dir} --hostname=fixme" - tahoelafs
  358. tahoelafs_setup_storage_config ${node_dir}/tahoe.cfg ${node_nick}
  359. fi
  360. if [ ! -f ${client_dir}/tahoe.cfg ]; then
  361. su -c "mkdir ${client_dir}" - tahoelafs
  362. su -c "$TAHOE_COMMAND create-client -C ${client_dir}" - tahoelafs
  363. tahoelafs_setup_client_config ${client_dir}/tahoe.cfg ${client_nick}
  364. fi
  365. }
  366. function create_tahoelafs_introducer {
  367. introducer_dir="$1"
  368. if [ -f ${introducer_dir}/tahoe.cfg ]; then
  369. return
  370. fi
  371. su -c "mkdir ${introducer_dir}" - tahoelafs
  372. su -c "$TAHOE_COMMAND create-introducer -C ${introducer_dir} --hide-ip --hostname=127.0.0.1" - tahoelafs
  373. }
  374. function create_tahoelafs_storage_node {
  375. # Nodes can store data
  376. node_dir="$1"
  377. furl="$2"
  378. if [ ${#furl} -eq 0 ]; then
  379. return
  380. fi
  381. if [ -f ${node_dir}/tahoe.cfg ]; then
  382. return
  383. fi
  384. su -c "mkdir ${node_dir}" - tahoelafs
  385. su -c "$TAHOE_COMMAND create-node -C ${node_dir} --introducer=\"$furl\" --listen=tor --hide-ip" - tahoelafs
  386. }
  387. function create_tahoelafs_client {
  388. # Clients have no storage
  389. client_dir="$1"
  390. furl="$2"
  391. if [ ${#furl} -eq 0 ]; then
  392. return
  393. fi
  394. if [ -f ${client_dir}/tahoe.cfg ]; then
  395. return
  396. fi
  397. su -c "mkdir ${client_dir}" - tahoelafs
  398. su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
  399. sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' $client_dir/tahoe.cfg
  400. sed -i 's|tub.port =.*|tub.port = disabled|g' $client_dir/tahoe.cfg
  401. sed -i 's|tub.location =.*|tub.location = disabled|g' $client_dir/tahoe.cfg
  402. }
  403. function get_tahoelafs_furl {
  404. echo "$(cat /home/tahoelafs/storage/private/storage.furl)"
  405. }
  406. function get_tahoelafs_nick {
  407. echo "${MY_USERNAME}-node"
  408. }
  409. function get_tahoelafs_storage_hostname {
  410. echo "$(cat /var/lib/tor/hidden_service_storage-tahoelafs/hostname)"
  411. }
  412. function get_tahoelafs_public_key {
  413. echo "$(cat /home/tahoelafs/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
  414. }
  415. function add_tahoelafs_server {
  416. storage_hostname="$1"
  417. public_key="$2"
  418. nick="$3"
  419. furl="$4"
  420. if [ ${#storage_hostname} -eq 0 ]; then
  421. echo $'No storage hostname'
  422. return
  423. fi
  424. if [ ${#public_key} -eq 0 ]; then
  425. echo $'No public key'
  426. return
  427. fi
  428. if [ ${#nick} -eq 0 ]; then
  429. echo $'No nick'
  430. return
  431. fi
  432. if [ ${#furl} -eq 0 ]; then
  433. echo $'No furl'
  434. return
  435. fi
  436. if [ ! -f ${tahoelafs_storage_file} ]; then
  437. echo 'storage:' > ${tahoelafs_storage_file}
  438. else
  439. if grep -q "${public_key}" ${tahoelafs_storage_file}; then
  440. echo $'Public key already exists'
  441. return
  442. fi
  443. echo '# storage' >> ${tahoelafs_storage_file}
  444. fi
  445. echo " ${public_key}" >> ${tahoelafs_storage_file}
  446. echo " ann:" >> ${tahoelafs_storage_file}
  447. echo " nickname: ${nick}" >> ${tahoelafs_storage_file}
  448. echo " anonymous-storage-FURL: ${furl}" >> ${tahoelafs_storage_file}
  449. chown tahoelafs:debian-tor ${tahoelafs_storage_file}
  450. if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
  451. echo "HidServAuth ${storage_hostname}" >> /etc/tor/torrc
  452. fi
  453. }
  454. function create_tahoelafs_daemon {
  455. daemon_name=$1
  456. TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
  457. echo "Creating daemon: $TAHOELAFS_DAEMON_FILE"
  458. echo '[Unit]' > $TAHOELAFS_DAEMON_FILE
  459. echo "Description=Tahoe-LAFS ${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
  460. echo 'After=syslog.target' >> $TAHOELAFS_DAEMON_FILE
  461. echo 'After=network.target' >> $TAHOELAFS_DAEMON_FILE
  462. echo '' >> $TAHOELAFS_DAEMON_FILE
  463. echo '[Service]' >> $TAHOELAFS_DAEMON_FILE
  464. echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
  465. echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
  466. echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE
  467. echo "WorkingDirectory=/home/tahoelafs/tahoelafs" >> $TAHOELAFS_DAEMON_FILE
  468. echo "ExecStart=/home/tahoelafs/tahoelafs/venv/bin/tahoe run /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
  469. echo "ExecStop=/home/tahoelafs/tahoelafs/venv/bin/tahoe stop /home/tahoelafs/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
  470. echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
  471. echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
  472. echo "Environment=\"USER=tahoelafs\" \"HOME=/home/tahoelafs\"" >> $TAHOELAFS_DAEMON_FILE
  473. echo '' >> $TAHOELAFS_DAEMON_FILE
  474. echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
  475. echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
  476. systemctl enable tahoelafs-${daemon_name}
  477. systemctl daemon-reload
  478. systemctl start tahoelafs-${daemon_name}
  479. }
  480. function create_tahoelafs_web {
  481. if [ ! -d /var/www/tahoelafs/htdocs ]; then
  482. mkdir -p /var/www/tahoelafs/htdocs
  483. fi
  484. tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
  485. echo 'server {' > $tahoelafs_nginx_site
  486. echo " listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;" >> $tahoelafs_nginx_site
  487. echo " server_name $TAHOELAFS_ONION_HOSTNAME;" >> $tahoelafs_nginx_site
  488. echo '' >> $tahoelafs_nginx_site
  489. function_check nginx_disable_sniffing
  490. nginx_disable_sniffing tahoelafs
  491. echo '' >> $tahoelafs_nginx_site
  492. echo ' # Logs' >> $tahoelafs_nginx_site
  493. echo ' access_log /dev/null;' >> $tahoelafs_nginx_site
  494. echo ' error_log /dev/null;' >> $tahoelafs_nginx_site
  495. echo '' >> $tahoelafs_nginx_site
  496. echo ' # Root' >> $tahoelafs_nginx_site
  497. echo " root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
  498. echo '' >> $tahoelafs_nginx_site
  499. echo ' location / {' >> $tahoelafs_nginx_site
  500. function_check nginx_limits
  501. nginx_limits tahoelafs '15m'
  502. echo ' rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
  503. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $tahoelafs_nginx_site
  504. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $tahoelafs_nginx_site
  505. echo ' proxy_set_header Host $http_host;' >> $tahoelafs_nginx_site
  506. echo ' proxy_set_header X-NginX-Proxy true;' >> $tahoelafs_nginx_site
  507. echo " proxy_pass http://localhost:${TAHOELAFS_PORT};" >> $tahoelafs_nginx_site
  508. echo ' proxy_redirect off;' >> $tahoelafs_nginx_site
  509. echo ' }' >> $tahoelafs_nginx_site
  510. echo '}' >> $tahoelafs_nginx_site
  511. function_check nginx_ensite
  512. nginx_ensite tahoelafs
  513. systemctl reload nginx
  514. }
  515. function install_tahoelafs {
  516. if [ $INSTALLING_MESH ]; then
  517. return
  518. fi
  519. apt-get -yq install build-essential python-pip python-dev libffi-dev libssl-dev
  520. apt-get -yq install libcrypto++-dev python-pycryptopp python-cffi python-virtualenv
  521. # create a user
  522. if [ ! -d /home/tahoelafs ]; then
  523. # add a gogs user account
  524. adduser --disabled-login --gecos 'tahoe-lafs' tahoelafs
  525. adduser tahoelafs debian-tor
  526. fi
  527. if [ -d /home/tahoelafs/Maildir ]; then
  528. rm -rf /home/tahoelafs/Maildir
  529. fi
  530. install_tahoelafs_to_directory /home/tahoelafs/tahoelafs
  531. # remove files we don't need
  532. rm -rf /home/tahoelafs/.mutt
  533. rm /home/tahoelafs/.emacs-mutt
  534. rm /home/tahoelafs/.muttrc
  535. rm /home/tahoelafs/.mutt-alias
  536. rm /home/tahoelafs/.procmailrc
  537. # set permissions
  538. chown -R tahoelafs:debian-tor /home/tahoelafs
  539. node_nick=$(get_tahoelafs_nick)
  540. client_nick=${MY_USERNAME}-client
  541. # create an onion address for storage node
  542. TAHOELAFS_STORAGE_ONION_HOSTNAME=$(add_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_PORT} ${TAHOELAFS_STORAGE_ONION_PORT} ${node_nick})
  543. # create an onion address for client node
  544. TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs ${TAHOELAFS_PORT} ${TAHOELAFS_ONION_PORT})
  545. create_tahoelafs_stealth_node /home/tahoelafs/storage /home/tahoelafs/client ${node_nick} ${client_nick}
  546. # start the storage node
  547. su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/storage' - tahoelafs
  548. create_tahoelafs_daemon "storage"
  549. add_tahoelafs_server "$(get_tahoelafs_storage_hostname)" "$(get_tahoelafs_public_key)" "${node_nick}" "$(get_tahoelafs_furl)"
  550. if ! grep -q "HidServAuth $(get_tahoelafs_storage_hostname)" /etc/tor/torrc; then
  551. echo $'Unable to create tahoelafs server'
  552. exit 738752
  553. fi
  554. if [ ! -f ${tahoelafs_storage_file} ]; then
  555. echo $'tahoelafs server file missing'
  556. exit 529362
  557. fi
  558. # start the client
  559. su -c '/home/tahoelafs/tahoelafs/venv/bin/python2 /home/tahoelafs/tahoelafs/venv/bin/tahoe start /home/tahoelafs/client' - tahoelafs
  560. create_tahoelafs_daemon "client"
  561. set_completion_param "tahoelafs commit" "$TAHOELAFS_COMMIT"
  562. set_completion_param "tahoelafs onion domain" "$TAHOELAFS_ONION_HOSTNAME"
  563. create_tahoelafs_web
  564. systemctl reload tor
  565. APP_INSTALLED=1
  566. }
  567. # NOTE: deliberately no exit 0