freedombone-app-cjdns 18KB

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