freedombone-app-cjdns 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # cjdns functions
  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. VARIANTS=''
  31. ENABLE_CJDNS="no"
  32. CJDNS_PRIVATE_KEY=
  33. CJDNS_PUBLIC_KEY=
  34. CJDNS_IPV6=
  35. CJDNS_PASSWORD=
  36. CJDNS_PORT=
  37. CJDNS_REPO="https://github.com/cjdelisle/cjdns.git"
  38. CJDNS_COMMIT='13189fde111d0500427a7a0ce06a970753527bca'
  39. CJDCMD_REPO="https://github.com/inhies/cjdcmd"
  40. CJDCMD_COMMIT='973cca6ed0eecf9041c3403a40193c0b1291b808'
  41. function install_interactive_cjdns {
  42. echo -n ''
  43. }
  44. function change_password_cjdns {
  45. echo -n ''
  46. }
  47. function reconfigure_cjdns {
  48. echo -n ''
  49. }
  50. function upgrade_cjdns {
  51. if ! grep -Fxq "install_cjdns" $COMPLETION_FILE; then
  52. return
  53. fi
  54. function_check set_repo_commit
  55. set_repo_commit /etc/cjdns "cjdns commit" "$CJDNS_COMMIT" $CJDNS_REPO
  56. }
  57. function configure_firewall_for_cjdns {
  58. if grep -Fxq "configure_firewall_for_cjdns" $COMPLETION_FILE; then
  59. return
  60. fi
  61. if [[ $ENABLE_CJDNS != "yes" ]]; then
  62. return
  63. fi
  64. ip6tables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
  65. ip6tables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  66. ip6tables -A INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
  67. ip6tables -A INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
  68. function_check save_firewall_settings
  69. save_firewall_settings
  70. echo 'configure_firewall_for_cjdns' >> $COMPLETION_FILE
  71. }
  72. function get_cjdns_public_key {
  73. if [ -f /home/$MY_USERNAME/README ]; then
  74. if grep -q "cjdns public key" /home/$MY_USERNAME/README; then
  75. if [ ! $CJDNS_PUBLIC_KEY ]; then
  76. CJDNS_PUBLIC_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns public key" | awk -F ':' '{print $2}' | sed 's/^ *//')
  77. fi
  78. fi
  79. fi
  80. }
  81. function get_cjdns_private_key {
  82. if [ -f /home/$MY_USERNAME/README ]; then
  83. if grep -q "cjdns private key" /home/$MY_USERNAME/README; then
  84. if [ ! $CJDNS_PRIVATE_KEY ]; then
  85. CJDNS_PRIVATE_KEY=$(cat /home/$MY_USERNAME/README | grep "cjdns private key" | awk -F ':' '{print $2}' | sed 's/^ *//')
  86. fi
  87. fi
  88. fi
  89. }
  90. function get_cjdns_ipv6_address {
  91. if [ -f /home/$MY_USERNAME/README ]; then
  92. if grep -q "cjdns IPv6 address" /home/$MY_USERNAME/README; then
  93. if [ ! $CJDNS_IPV6 ]; then
  94. CJDNS_IPV6=$(cat /home/$MY_USERNAME/README | grep "cjdns IPv6 address" | awk -F ':' '{print $2}' | sed 's/^ *//')
  95. fi
  96. fi
  97. fi
  98. }
  99. function get_cjdns_port {
  100. if [ -f /home/$MY_USERNAME/README ]; then
  101. if grep -q "cjdns port" /home/$MY_USERNAME/README; then
  102. if [ ! $CJDNS_PORT ]; then
  103. CJDNS_PORT=$(cat /home/$MY_USERNAME/README | grep "cjdns port" | awk -F ':' '{print $2}' | sed 's/^ *//')
  104. fi
  105. fi
  106. fi
  107. }
  108. function get_cjdns_password {
  109. if [ -f /home/$MY_USERNAME/README ]; then
  110. if grep -q "cjdns password" /home/$MY_USERNAME/README; then
  111. if [ ! $CJDNS_PASSWORD ]; then
  112. CJDNS_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "cjdns password" | awk -F ':' '{print $2}' | sed 's/^ *//')
  113. fi
  114. fi
  115. fi
  116. }
  117. function backup_local_cjdns {
  118. echo -n ''
  119. }
  120. function restore_local_cjdns {
  121. if [ -d $USB_MOUNT/backup/cjdns ]; then
  122. echo $"Restoring cjdns installation"
  123. temp_restore_dir=/root/tempcjdns
  124. function_check restore_directory_from_usb
  125. restore_directory_from_usb $temp_restore_dir cjdns
  126. rm -rf /etc/cjdns
  127. cp -r $temp_restore_dir/etc/cjdns /etc/
  128. if [ ! "$?" = "0" ]; then
  129. function_check set_user_permissions
  130. set_user_permissions
  131. function_check backup_unmount_drive
  132. backup_unmount_drive
  133. exit 8472
  134. fi
  135. rm -rf $temp_restore_dir
  136. fi
  137. }
  138. function backup_remote_cjdns {
  139. echo -n ''
  140. }
  141. function restore_remote_cjdns {
  142. if [ -d $SERVER_DIRECTORY/backup/cjdns ]; then
  143. echo $"Restoring cjdns installation"
  144. temp_restore_dir=/root/tempcjdns
  145. function_check restore_directory_from_friend
  146. restore_directory_from_friend $temp_restore_dir cjdns
  147. rm -rf /etc/cjdns
  148. cp -r $temp_restore_dir/etc/cjdns /etc/
  149. if [ ! "$?" = "0" ]; then
  150. exit 7438
  151. fi
  152. rm -rf $temp_restore_dir
  153. fi
  154. }
  155. function remove_cjdns {
  156. if [[ $(app_is_installed cjdns) == "0" ]]; then
  157. return
  158. fi
  159. service cjdns stop
  160. ip6tables -D nat -D POSTROUTING -o tun0 -j MASQUERADE
  161. ip6tables -D FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  162. ip6tables -D INPUT -p udp --dport $CJDNS_PORT -j ACCEPT
  163. ip6tables -D INPUT -p tcp --dport $CJDNS_PORT -j ACCEPT
  164. function_check save_firewall_settings
  165. save_firewall_settings
  166. rm -rf /etc/cjdns
  167. sed -i '/install_cjdns/d' $COMPLETION_FILE
  168. sed -i '/cjdns /d' $COMPLETION_FILE
  169. sed -i '/configure_firewall_for_cjdns/d' $COMPLETION_FILE
  170. }
  171. function install_cjdns_main {
  172. if [[ $ENABLE_CJDNS != "yes" ]]; then
  173. return
  174. fi
  175. if grep -Fxq "install_cjdns_main" $COMPLETION_FILE; then
  176. return
  177. fi
  178. apt-get -y install nodejs git build-essential nmap
  179. # if a README exists then obtain the cjdns parameters
  180. function_check get_cjdns_ipv6_address
  181. get_cjdns_ipv6_address
  182. function_check get_cjdns_public_key
  183. get_cjdns_public_key
  184. function_check get_cjdns_private_key
  185. get_cjdns_private_key
  186. function_check get_cjdns_port
  187. get_cjdns_port
  188. function_check get_cjdns_password
  189. get_cjdns_password
  190. # special compile settings for running ./do on the Beaglebone Black
  191. if [[ $INSTALLING_ON_BBB == "yes" ]]; then
  192. CFLAGS="-O2 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=hard -marm -Wno-error=maybe-uninitialized"
  193. export LDFLAGS="$CFLAGS"
  194. fi
  195. if [ ! -d /etc/cjdns ]; then
  196. function_check git_pull
  197. git_clone $CJDNS_REPO /etc/cjdns
  198. cd /etc/cjdns
  199. git checkout $CJDNS_COMMIT -b $CJDNS_COMMIT
  200. if ! grep -q "cjdns commit" $COMPLETION_FILE; then
  201. echo "cjdns commit:$CJDNS_COMMIT" >> $COMPLETION_FILE
  202. else
  203. sed -i "s/cjdns commit.*/cjdns commit:$CJDNS_COMMIT/g" $COMPLETION_FILE
  204. fi
  205. ./do
  206. if [ ! "$?" = "0" ]; then
  207. exit 7439
  208. fi
  209. # create a configuration
  210. if [ ! -f /etc/cjdns/cjdroute.conf ]; then
  211. ./cjdroute --genconf > /etc/cjdns/cjdroute.conf
  212. if [ ! "$?" = "0" ]; then
  213. exit 5922
  214. fi
  215. fi
  216. # create a user to run as
  217. useradd cjdns
  218. else
  219. cd /etc/cjdns
  220. function_check git_pull
  221. git_pull $CJDNS_REPO
  222. ./do
  223. if [ ! "$?" = "0" ]; then
  224. exit 9926
  225. fi
  226. fi
  227. # set permissions
  228. chown -R cjdns:cjdns /etc/cjdns
  229. chmod 600 /etc/cjdns/cjdroute.conf
  230. /sbin/ip tuntap add mode tun user cjdns dev cjdroute0
  231. # insert values into the configuration file
  232. if [ $CJDNS_PRIVATE_KEY ]; then
  233. sed -i "s/\"privateKey\":.*/\"privateKey\": \"$CJDNS_PRIVATE_KEY\",/g" /etc/cjdns/cjdroute.conf
  234. else
  235. CJDNS_PRIVATE_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"privateKey"' | awk -F '"' '{print $4}' | sed -n 1p)
  236. fi
  237. if [ $CJDNS_PUBLIC_KEY ]; then
  238. sed -i "s/\"publicKey\":.*/\"publicKey\": \"$CJDNS_PUBLIC_KEY\",/g" /etc/cjdns/cjdroute.conf
  239. else
  240. CJDNS_PUBLIC_KEY=$(cat /etc/cjdns/cjdroute.conf | grep '"publicKey"' | awk -F '"' '{print $4}' | sed -n 1p)
  241. fi
  242. if [ $CJDNS_IPV6 ]; then
  243. sed -i "s/\"ipv6\":.*/\"ipv6\": \"$CJDNS_IPV6\",/g" /etc/cjdns/cjdroute.conf
  244. else
  245. CJDNS_IPV6=$(cat /etc/cjdns/cjdroute.conf | grep '"ipv6"' | awk -F '"' '{print $4}' | sed -n 1p)
  246. fi
  247. if [ $CJDNS_PASSWORD ]; then
  248. sed -i "0,/{\"password\":.*/s//{\"password\": \"$CJDNS_PASSWORD\"}/g" /etc/cjdns/cjdroute.conf
  249. else
  250. CJDNS_PASSWORD=$(cat /etc/cjdns/cjdroute.conf | grep '"password"' | awk -F '"' '{print $4}' | sed -n 1p)
  251. fi
  252. if [ $CJDNS_PORT ]; then
  253. sed -i "s/\"bind\": \"0.0.0.0:.*/\"bind\": \"0.0.0.0:$CJDNS_PORT\",/g" /etc/cjdns/cjdroute.conf
  254. else
  255. CJDNS_PORT=$(cat /etc/cjdns/cjdroute.conf | grep '"bind": "0.0.0.0:' | awk -F '"' '{print $4}' | awk -F ':' '{print $2}' | sed -n 1p)
  256. fi
  257. function_check enable_ipv6
  258. enable_ipv6
  259. echo '#!/bin/sh -e' > /etc/init.d/cjdns
  260. echo '### BEGIN INIT INFO' >> /etc/init.d/cjdns
  261. echo '# hyperboria.sh - An init script (/etc/init.d/) for cjdns' >> /etc/init.d/cjdns
  262. echo '# Provides: cjdroute' >> /etc/init.d/cjdns
  263. echo '# Required-Start: $remote_fs $network' >> /etc/init.d/cjdns
  264. echo '# Required-Stop: $remote_fs $network' >> /etc/init.d/cjdns
  265. echo '# Default-Start: 2 3 4 5' >> /etc/init.d/cjdns
  266. echo '# Default-Stop: 0 1 6' >> /etc/init.d/cjdns
  267. echo '# Short-Description: Cjdns router' >> /etc/init.d/cjdns
  268. echo '# Description: A routing engine designed for security, scalability, speed and ease of use.' >> /etc/init.d/cjdns
  269. echo '# cjdns git repo: https://github.com/cjdelisle/cjdns/' >> /etc/init.d/cjdns
  270. echo '### END INIT INFO' >> /etc/init.d/cjdns
  271. echo '' >> /etc/init.d/cjdns
  272. echo 'PROG="cjdroute"' >> /etc/init.d/cjdns
  273. echo 'GIT_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
  274. echo 'PROG_PATH="/etc/cjdns"' >> /etc/init.d/cjdns
  275. echo 'CJDNS_CONFIG="cjdroute.conf"' >> /etc/init.d/cjdns
  276. echo 'CJDNS_USER="cjdns"' >> /etc/init.d/cjdns
  277. echo "CJDNS_IP='$CJDNS_IPV6'" >> /etc/init.d/cjdns
  278. echo '' >> /etc/init.d/cjdns
  279. echo 'start() {' >> /etc/init.d/cjdns
  280. echo ' # Start it up with the user cjdns' >> /etc/init.d/cjdns
  281. echo ' if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
  282. echo ' then' >> /etc/init.d/cjdns
  283. echo ' echo "cjdroute is already running. Doing nothing..."' >> /etc/init.d/cjdns
  284. echo ' else' >> /etc/init.d/cjdns
  285. echo ' echo " * Starting cjdroute"' >> /etc/init.d/cjdns
  286. echo ' su -c "$PROG_PATH/$PROG < $PROG_PATH/$CJDNS_CONFIG" - $CJDNS_USER' >> /etc/init.d/cjdns
  287. echo ' /sbin/ip addr add $CJDNS_IP/8 dev tun0' >> /etc/init.d/cjdns
  288. echo ' /sbin/ip link set mtu 1312 dev tun0' >> /etc/init.d/cjdns
  289. echo ' /sbin/ip link set tun0 up' >> /etc/init.d/cjdns
  290. echo ' /sbin/ip tuntap add mode tun user cjdns dev tun0' >> /etc/init.d/cjdns
  291. echo ' fi' >> /etc/init.d/cjdns
  292. echo '}' >> /etc/init.d/cjdns
  293. echo '' >> /etc/init.d/cjdns
  294. echo 'stop() {' >> /etc/init.d/cjdns
  295. echo '' >> /etc/init.d/cjdns
  296. echo ' if [ $(pgrep cjdroute | wc -l) != 2 ];' >> /etc/init.d/cjdns
  297. echo ' then' >> /etc/init.d/cjdns
  298. echo ' echo "cjdns isnt running."' >> /etc/init.d/cjdns
  299. echo ' else' >> /etc/init.d/cjdns
  300. echo ' echo "Killing cjdroute"' >> /etc/init.d/cjdns
  301. echo ' killall cjdroute' >> /etc/init.d/cjdns
  302. echo ' fi' >> /etc/init.d/cjdns
  303. echo '}' >> /etc/init.d/cjdns
  304. echo '' >> /etc/init.d/cjdns
  305. echo 'status() {' >> /etc/init.d/cjdns
  306. echo ' if [ $(pgrep cjdroute | wc -l) != 0 ];' >> /etc/init.d/cjdns
  307. echo ' then' >> /etc/init.d/cjdns
  308. echo ' echo "Cjdns is running"' >> /etc/init.d/cjdns
  309. echo ' else' >> /etc/init.d/cjdns
  310. echo ' echo "Cjdns is not running"' >> /etc/init.d/cjdns
  311. echo ' fi' >> /etc/init.d/cjdns
  312. echo '}' >> /etc/init.d/cjdns
  313. echo '' >> /etc/init.d/cjdns
  314. echo ' update() {' >> /etc/init.d/cjdns
  315. echo ' cd $GIT_PATH' >> /etc/init.d/cjdns
  316. echo ' echo "Updating..."' >> /etc/init.d/cjdns
  317. echo ' git pull' >> /etc/init.d/cjdns
  318. echo ' ./do' >> /etc/init.d/cjdns
  319. echo '}' >> /etc/init.d/cjdns
  320. echo '' >> /etc/init.d/cjdns
  321. echo '## Check to see if we are running as root first.' >> /etc/init.d/cjdns
  322. echo 'if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/cjdns
  323. echo ' echo "This script must be run as root" 1>&2' >> /etc/init.d/cjdns
  324. echo ' exit 1' >> /etc/init.d/cjdns
  325. echo 'fi' >> /etc/init.d/cjdns
  326. echo '' >> /etc/init.d/cjdns
  327. echo 'case $1 in' >> /etc/init.d/cjdns
  328. echo ' start)' >> /etc/init.d/cjdns
  329. echo ' start' >> /etc/init.d/cjdns
  330. echo ' exit 0' >> /etc/init.d/cjdns
  331. echo ' ;;' >> /etc/init.d/cjdns
  332. echo ' stop)' >> /etc/init.d/cjdns
  333. echo ' stop' >> /etc/init.d/cjdns
  334. echo ' exit 0' >> /etc/init.d/cjdns
  335. echo ' ;;' >> /etc/init.d/cjdns
  336. echo ' reload|restart|force-reload)' >> /etc/init.d/cjdns
  337. echo ' stop' >> /etc/init.d/cjdns
  338. echo ' sleep 1' >> /etc/init.d/cjdns
  339. echo ' start' >> /etc/init.d/cjdns
  340. echo ' exit 0' >> /etc/init.d/cjdns
  341. echo ' ;;' >> /etc/init.d/cjdns
  342. echo ' status)' >> /etc/init.d/cjdns
  343. echo ' status' >> /etc/init.d/cjdns
  344. echo ' exit 0' >> /etc/init.d/cjdns
  345. echo ' ;;' >> /etc/init.d/cjdns
  346. echo ' update|upgrade)' >> /etc/init.d/cjdns
  347. echo ' update' >> /etc/init.d/cjdns
  348. echo ' stop' >> /etc/init.d/cjdns
  349. echo ' sleep 2' >> /etc/init.d/cjdns
  350. echo ' start' >> /etc/init.d/cjdns
  351. echo ' exit 0' >> /etc/init.d/cjdns
  352. echo ' ;;' >> /etc/init.d/cjdns
  353. echo ' **)' >> /etc/init.d/cjdns
  354. echo ' echo "Usage: $0 (start|stop|restart|status|update)" 1>&2' >> /etc/init.d/cjdns
  355. echo ' exit 1' >> /etc/init.d/cjdns
  356. echo ' ;;' >> /etc/init.d/cjdns
  357. echo 'esac' >> /etc/init.d/cjdns
  358. chmod +x /etc/init.d/cjdns
  359. update-rc.d cjdns defaults
  360. service cjdns start
  361. if [ ! "$?" = "0" ]; then
  362. systemctl status cjdns.service
  363. exit 8260
  364. fi
  365. apt-get -y install radvd
  366. echo 'interface eth0' > /etc/radvd.conf
  367. echo '{' >> /etc/radvd.conf
  368. echo ' AdvSendAdvert on;' >> /etc/radvd.conf
  369. echo ' prefix fdfc::1/64' >> /etc/radvd.conf
  370. echo ' {' >> /etc/radvd.conf
  371. echo ' AdvRouterAddr on;' >> /etc/radvd.conf
  372. echo ' };' >> /etc/radvd.conf
  373. echo '};' >> /etc/radvd.conf
  374. systemctl restart radvd
  375. if [ ! "$?" = "0" ]; then
  376. systemctl status radvd.service
  377. exit 4395
  378. fi
  379. if ! grep -q "# Mesh Networking (cjdns)" /etc/network/interfaces; then
  380. echo '' >> /etc/network/interfaces
  381. echo '# Mesh Networking (cjdns)' >> /etc/network/interfaces
  382. echo 'iface eth0 inet6 static' >> /etc/network/interfaces
  383. echo ' pre-up modprobe ipv6' >> /etc/network/interfaces
  384. echo ' address fdfc:0000:0000:0000:0000:0000:0000:0001' >> /etc/network/interfaces
  385. echo ' netmask 64' >> /etc/network/interfaces
  386. service network-manager restart
  387. if [ ! "$?" = "0" ]; then
  388. systemctl status networking.service
  389. exit 6949
  390. fi
  391. fi
  392. if ! grep -q $"Mesh Networking (cjdns)" /home/$MY_USERNAME/README; then
  393. CURRENT_IP_ADDRESS=$(ip addr show | grep "inet " | sed -n 2p | awk -F ' ' '{print $2}' | awk -F '/' '{print $1}')
  394. echo '' >> /home/$MY_USERNAME/README
  395. echo '' >> /home/$MY_USERNAME/README
  396. echo $'Mesh Networking (cjdns)' >> /home/$MY_USERNAME/README
  397. echo '=======================' >> /home/$MY_USERNAME/README
  398. echo $"cjdns IPv6 address: $CJDNS_IPV6" >> /home/$MY_USERNAME/README
  399. echo $"cjdns public key: $CJDNS_PUBLIC_KEY" >> /home/$MY_USERNAME/README
  400. echo $"cjdns private key: $CJDNS_PRIVATE_KEY" >> /home/$MY_USERNAME/README
  401. echo $"cjdns password: $CJDNS_PASSWORD" >> /home/$MY_USERNAME/README
  402. echo $"cjdns port: $CJDNS_PORT" >> /home/$MY_USERNAME/README
  403. echo '' >> /home/$MY_USERNAME/README
  404. echo $"Forward port $CJDNS_PORT from your internet router to the ${PROJECT_NAME}" >> /home/$MY_USERNAME/README
  405. echo '' >> /home/$MY_USERNAME/README
  406. echo $'Below is an example of your connection credentials' >> /home/$MY_USERNAME/README
  407. echo $'that you can give to other people so they can connect' >> /home/$MY_USERNAME/README
  408. echo $'to you using your default password' >> /home/$MY_USERNAME/README
  409. echo $'Adding a unique password for each user is advisable' >> /home/$MY_USERNAME/README
  410. echo $'so that leaks can be isolated.' >> /home/$MY_USERNAME/README
  411. echo '' >> /home/$MY_USERNAME/README
  412. echo "\"$CURRENT_IP_ADDRESS:$CJDNS_PORT\":{\"password\":\"$CJDNS_PASSWORD\",\"publicKey\":\"$CJDNS_PUBLIC_KEY\"}" >> /home/$MY_USERNAME/README
  413. echo '' >> /home/$MY_USERNAME/README
  414. echo $'More is not better. 3-5 cjdns peers is good. 30 peers is bad.' >> /home/$MY_USERNAME/README
  415. echo '' >> /home/$MY_USERNAME/README
  416. echo $'NEVER USE A PUBLIC PEER. These degrade the network and make it centralized.' >> /home/$MY_USERNAME/README
  417. echo $'Each node can handle many peers, but no node can handle the entire internet.' >> /home/$MY_USERNAME/README
  418. echo $'As this network grows any public peer will simply become saturated and' >> /home/$MY_USERNAME/README
  419. echo $'useless causing issues for the entire network.' >> /home/$MY_USERNAME/README
  420. echo $'Please report anyone offering you a public peer as they are promoting shared' >> /home/$MY_USERNAME/README
  421. echo $'passwords which could lead to people pretending to be you. A peering pass' >> /home/$MY_USERNAME/README
  422. echo $'should not contain someone elses nickname or info but should contain yours' >> /home/$MY_USERNAME/README
  423. echo $'to ensure it is not shared. It also helps when editing the conf to know who' >> /home/$MY_USERNAME/README
  424. echo $'each password is for.' >> /home/$MY_USERNAME/README
  425. echo '' >> /home/$MY_USERNAME/README
  426. echo $'Possible cjdns destinations of interest:' >> /home/$MY_USERNAME/README
  427. echo ' http://transitiontech.ca/faq' >> /home/$MY_USERNAME/README
  428. echo ' http://cjdns.ca/hypeirc.txt' >> /home/$MY_USERNAME/README
  429. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  430. chmod 600 /home/$MY_USERNAME/README
  431. fi
  432. function_check configure_firewall_for_cjdns
  433. configure_firewall_for_cjdns
  434. echo 'install_cjdns_main' >> $COMPLETION_FILE
  435. }
  436. function install_cjdns_tools {
  437. if grep -Fxq "install_cjdns_tools" $COMPLETION_FILE; then
  438. return
  439. fi
  440. if [[ $ENABLE_CJDNS != "yes" ]]; then
  441. return
  442. fi
  443. if [ ! -d /etc/cjdns ]; then
  444. install_cjdns
  445. fi
  446. apt-get -y install mercurial
  447. if [ ! -f ~/.bashrc ]; then
  448. touch ~/.bashrc
  449. fi
  450. if [ ! -d /home/git ]; then
  451. # add a gogs user account
  452. adduser --disabled-login --gecos 'Gogs' git
  453. # install Go
  454. if ! grep -q "export GOPATH=" ~/.bashrc; then
  455. echo "export GOPATH=$GOPATH" >> ~/.bashrc
  456. fi
  457. systemctl set-environment GOPATH=$GOPATH
  458. if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
  459. echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
  460. fi
  461. if [ ! -d $GOPATH ]; then
  462. mkdir -p $GOPATH
  463. fi
  464. fi
  465. if ! grep -q "export GOPATH=" ~/.bashrc; then
  466. echo "export GOPATH=$GOPATH" >> ~/.bashrc
  467. fi
  468. expected_go_path='export PATH=$PATH:'${GOPATH}'/bin'
  469. export PATH=$PATH:${GOPATH}/bin
  470. if ! grep -q "$expected_go_path" ~/.bashrc; then
  471. echo "$expected_go_path" >> ~/.bashrc
  472. fi
  473. export PATH=$PATH:$GOPATH/bin
  474. CJDCMD_REPO2=$(echo "$CJDCMD_REPO" | sed 's|https://||g')
  475. go get $CJDCMD_REPO2
  476. if [ ! -f $GOPATH/bin/cjdcmd ]; then
  477. echo $'cjdcmd was not compiled. Check your golang installation'
  478. exit 7439
  479. fi
  480. cp $GOPATH/bin/cjdcmd /usr/bin
  481. # initialise from the cjdns config
  482. /usr/bin/cjdcmd cjdnsadmin -file /etc/cjdns/cjdroute.conf
  483. install_completed cjdns_tools
  484. }
  485. function install_cjdns {
  486. install_cjdns_main
  487. install_cjdns_tools
  488. install_completed cjdns
  489. }
  490. # NOTE: deliberately no exit 0