freedombone-app-cjdns 19KB

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