freedombone-app-ipfs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # ipfs functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
  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. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=0
  33. IPFS_GO_REPO_BASE="github.com/ipfs/go-ipfs"
  34. IPFS_GO_REPO="https://$IPFS_GO_REPO_BASE"
  35. IPFS_COMMIT='6fdfaaf6e4783ae1be7b348e7a6bc0640982c7df'
  36. IPFS_PORT=4001
  37. IPFS_NODE_VERSION='6.2.2'
  38. IPFS_N_VERSION='2.1.4'
  39. IPFS_JS_VERSION='0.14.3'
  40. IPFS_JS_RONIN_VERSION='0.3.11'
  41. IPFS_KEY_LENGTH=2048
  42. IPFS_GO_VERSION=0.4.2
  43. ipfs_variables=(IPFS_GO_VERSION
  44. IPFS_KEY_LENGTH
  45. IPFS_PORT)
  46. function logging_on_ipfs {
  47. echo -n ''
  48. }
  49. function logging_off_ipfs {
  50. echo -n ''
  51. }
  52. function install_interactive_ipfs {
  53. echo -n ''
  54. APP_INSTALLED=1
  55. }
  56. function reconfigure_ipfs {
  57. echo -n ''
  58. }
  59. function upgrade_ipfs_go {
  60. CURR_IPFS_COMMIT=$(get_completion_param "ipfs commit")
  61. if [[ "$CURR_IPFS_COMMIT" == "$IPFS_COMMIT" ]]; then
  62. return
  63. fi
  64. if [[ $(app_is_installed ipfs_go) == "0" ]]; then
  65. return
  66. fi
  67. function_check set_repo_commit
  68. set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
  69. }
  70. function upgrade_ipfs_js {
  71. if [[ $(app_is_installed ipfs_js) == "0" ]]; then
  72. return
  73. fi
  74. npm cache clean -f
  75. npm install -g n
  76. n ${IPFS_NODE_VERSION}
  77. npm install ronin@${IPFS_JS_RONIN_VERSION} --global
  78. npm install ipfs@${IPFS_JS_VERSION} --global
  79. }
  80. function upgrade_ipfs {
  81. upgrade_ipfs_js
  82. upgrade_ipfs_go
  83. }
  84. function backup_local_ipfs {
  85. if ! grep -q "Admin user" $COMPLETION_FILE; then
  86. return
  87. fi
  88. ADMIN_USERNAME=$(get_completion_param "Admin user")
  89. source_directory=/home/$ADMIN_USERNAME/.ipfs
  90. if [ -d $source_directory ]; then
  91. dest_directory=ipfs
  92. function_check backup_directory_to_usb
  93. backup_directory_to_usb $source_directory $dest_directory
  94. fi
  95. }
  96. function restore_local_ipfs {
  97. if ! grep -q "Admin user" $COMPLETION_FILE; then
  98. return
  99. fi
  100. if [ -d $USB_MOUNT/backup/ipfs ]; then
  101. echo $"Restoring IPFS"
  102. temp_restore_dir=/root/tempipfs
  103. function_check restore_directory_from_usb
  104. restore_directory_from_usb $temp_restore_dir ipfs
  105. ADMIN_USERNAME=$(get_completion_param "Admin user")
  106. if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs ]; then
  107. cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
  108. else
  109. cp -rf $temp_restore_dir/* /home/$ADMIN_USERNAME/.ipfs
  110. fi
  111. if [ ! "$?" = "0" ]; then
  112. rm -rf $temp_restore_dir
  113. function_check set_user_permissions
  114. set_user_permissions
  115. function_check backup_unmount_drive
  116. backup_unmount_drive
  117. exit 27627
  118. fi
  119. rm -rf $temp_restore_dir
  120. echo $"Restore of IPFS complete"
  121. fi
  122. }
  123. function backup_remote_ipfs {
  124. if ! grep -q "Admin user" $COMPLETION_FILE; then
  125. return
  126. fi
  127. ADMIN_USERNAME=$(get_completion_param "Admin user")
  128. if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
  129. echo $"Backing up IPFS"
  130. backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
  131. echo $"Backup of IPFS complete"
  132. fi
  133. }
  134. function restore_remote_ipfs {
  135. if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
  136. echo $"Restoring IPFS"
  137. temp_restore_dir=/root/tempipfs
  138. function_check restore_directory_from_friend
  139. restore_directory_from_friend $temp_restore_dir ipfs
  140. if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs ]; then
  141. cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
  142. else
  143. cp -rf $temp_restore_dir/* /home/$ADMIN_USERNAME/.ipfs
  144. fi
  145. if [ ! "$?" = "0" ]; then
  146. function_check set_user_permissions
  147. set_user_permissions
  148. rm -rf $temp_restore_dir
  149. exit 276357
  150. fi
  151. rm -rf $temp_restore_dir
  152. echo $"Restore of IPFS complete"
  153. fi
  154. }
  155. function remove_ipfs_go {
  156. systemctl stop ipfs
  157. systemctl disable ipfs
  158. systemctl daemon-reload
  159. rm /etc/systemd/system/ipfs.service
  160. systemctl daemon-reload
  161. rm -rf $GOPATH/src/github.com/ipfs
  162. firewall_remove $IPFS_PORT tcp
  163. remove_completion_param install_ipfs
  164. remove_completion_param configure_firewall_for_ipfs
  165. sed -i '/ipfs/d' $COMPLETION_FILE
  166. }
  167. function remove_ipfs_js {
  168. systemctl stop ipfs
  169. systemctl disable ipfs
  170. rm /etc/systemd/system/ipfs.service
  171. systemctl daemon-reload
  172. npm uninstall ipfs --global
  173. npm uninstall ronin --global
  174. firewall_remove $IPFS_PORT tcp
  175. sed -i '/install_ipfs/d' $COMPLETION_FILE
  176. sed -i '/ipfs/d' $COMPLETION_FILE
  177. sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
  178. }
  179. function remove_ipfs {
  180. remove_ipfs_js
  181. remove_ipfs_go
  182. }
  183. function configure_firewall_for_ipfs {
  184. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  185. return
  186. fi
  187. if [[ $ONION_ONLY != "no" ]]; then
  188. return
  189. fi
  190. firewall_add IPFS $IPFS_PORT tcp
  191. mark_completed $FUNCNAME
  192. }
  193. function mesh_install_ipfs_js {
  194. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  195. return
  196. fi
  197. chroot ${rootdir} apt-get -yq install nodejs curl
  198. chroot ${rootdir} apt-get -yq install libpam0g-dev fuse
  199. if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
  200. echo $'nodejs was not installed'
  201. exit 63962
  202. fi
  203. cat <<EOF > ${rootdir}/root/install-ipfs.sh
  204. #!/bin/bash
  205. PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
  206. NODE_PATH="/usr/lib/node_modules"
  207. cp /usr/bin/nodejs /usr/local/bin/node
  208. cp /usr/bin/nodejs /usr/bin/node
  209. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  210. npm install -g n@${IPFS_N_VERSION} --save
  211. n ${IPFS_NODE_VERSION}
  212. npm install -g ronin@${IPFS_JS_RONIN_VERSION} --save
  213. npm install -g ipfs@${IPFS_JS_VERSION} --save
  214. exit 0
  215. EOF
  216. chroot ${rootdir} /bin/chmod +x /root/install-ipfs.sh
  217. chroot ${rootdir} /root/install-ipfs.sh
  218. rm -f ${rootdir}/root/install-ipfs.sh
  219. IPFS_PATH=/usr/bin
  220. if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
  221. exit 637292
  222. fi
  223. # directories to mount to
  224. if [ ! -d ${rootdir}/ipfs ]; then
  225. chroot ${rootdir} /bin/mkdir /ipfs
  226. chroot ${rootdir} /bin/mkdir /ipns
  227. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipfs
  228. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipns
  229. fi
  230. if [ -f ${rootdir}/etc/fuse.conf ]; then
  231. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  232. fi
  233. if [ -f ${rootdir}/dev/fuse ]; then
  234. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  235. fi
  236. IPFS_DAEMON_NAME=ipfs
  237. IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
  238. echo '[Unit]' > $IPFS_DAEMON_FILE
  239. echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
  240. echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
  241. echo 'After=network.target' >> $IPFS_DAEMON_FILE
  242. echo '' >> $IPFS_DAEMON_FILE
  243. echo '[Service]' >> $IPFS_DAEMON_FILE
  244. echo 'Type=simple' >> $IPFS_DAEMON_FILE
  245. echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  246. echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  247. echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
  248. echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
  249. echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
  250. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
  251. echo '' >> $IPFS_DAEMON_FILE
  252. echo '[Install]' >> $IPFS_DAEMON_FILE
  253. echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
  254. chroot ${rootdir} systemctl enable ${IPFS_DAEMON_NAME}
  255. mark_completed $FUNCNAME
  256. }
  257. function install_ipfs_js {
  258. if [ $INSTALLING_MESH ]; then
  259. mesh_install_ipfs_js
  260. return
  261. fi
  262. if [[ $(app_is_installed ipfs_js) == "1" ]]; then
  263. return
  264. fi
  265. apt-get -yq install nodejs
  266. apt-get -yq install npm
  267. apt-get -yq install libpam0g-dev fuse
  268. if [ ! -f /usr/bin/nodejs ]; then
  269. echo $'nodejs was not installed'
  270. exit 63962
  271. fi
  272. cp /usr/bin/nodejs /usr/local/bin/node
  273. cp /usr/bin/nodejs /usr/bin/node
  274. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  275. /usr/local/bin/npm install -g n@${IPFS_N_VERSION}
  276. /usr/local/bin/n ${IPFS_NODE_VERSION}
  277. /usr/local/bin/npm install -g ronin@${IPFS_JS_RONIN_VERSION}
  278. /usr/local/bin/npm install -g ipfs@${IPFS_JS_VERSION}
  279. IPFS_PATH=/usr/bin
  280. if [ ! -f $IPFS_PATH/jsipfs ]; then
  281. exit 637292
  282. fi
  283. # initialise
  284. su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
  285. if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
  286. echo "IPFS could not be initialised for user $MY_USERNAME"
  287. exit 7358
  288. fi
  289. # directories to mount to
  290. if [ ! -d /ipfs ]; then
  291. mkdir /ipfs
  292. mkdir /ipns
  293. chown $MY_USERNAME:$MY_USERNAME /ipfs
  294. chown $MY_USERNAME:$MY_USERNAME /ipns
  295. fi
  296. if [ -f /etc/fuse.conf ]; then
  297. chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  298. fi
  299. if [ -f /dev/fuse ]; then
  300. chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  301. fi
  302. IPFS_DAEMON_NAME=ipfs
  303. IPFS_DAEMON_FILE=/etc/systemd/system/${IPFS_DAEMON_NAME}.service
  304. echo '[Unit]' > $IPFS_DAEMON_FILE
  305. echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
  306. echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
  307. echo 'After=network.target' >> $IPFS_DAEMON_FILE
  308. echo '' >> $IPFS_DAEMON_FILE
  309. echo '[Service]' >> $IPFS_DAEMON_FILE
  310. echo 'Type=simple' >> $IPFS_DAEMON_FILE
  311. echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  312. echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  313. echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
  314. echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
  315. echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
  316. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
  317. echo '' >> $IPFS_DAEMON_FILE
  318. echo '[Install]' >> $IPFS_DAEMON_FILE
  319. echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
  320. systemctl enable ${IPFS_DAEMON_NAME}
  321. systemctl daemon-reload
  322. systemctl restart ${IPFS_DAEMON_NAME}
  323. if [ -d /etc/avahi ]; then
  324. su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
  325. if [ ! -f /tmp/ipfsid ]; then
  326. echo 'No IPFS identity was created'
  327. exit 37895
  328. fi
  329. IPFS_PEER_ID=$(cat /tmp/ipfsid)
  330. if [ ${#IPFS_PEER_ID} -lt 10 ]; then
  331. echo 'Invalid IPFS peer ID'
  332. echo "$IPFS_PEER_ID"
  333. exit 74782
  334. fi
  335. rm /tmp/ipfsid
  336. fi
  337. function_check configure_firewall_for_ipfs
  338. configure_firewall_for_ipfs
  339. install_completed ipfs_js
  340. }
  341. function mesh_install_ipfs_go {
  342. chroot ${rootdir} apt-get -yq install libpam0g-dev fuse wget
  343. mesh_upgrade_golang
  344. IPFS_ARCH=
  345. IPFS_PATH=/usr/bin
  346. if [ ! -d $rootdir$INSTALL_DIR/ipfs ]; then
  347. mkdir -p $rootdir$INSTALL_DIR/ipfs
  348. fi
  349. cd $rootdir$INSTALL_DIR/ipfs
  350. if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
  351. IPFS_ARCH=386
  352. fi
  353. if [[ $ARCHITECTURE == *"amd64" || $ARCHITECTURE == "x86_64" ]]; then
  354. IPFS_ARCH=amd64
  355. fi
  356. if [[ $ARCHITECTURE == *"arm"* || $ARCHITECTURE == *"aarch"* ]]; then
  357. IPFS_ARCH=arm
  358. fi
  359. if [ ! $IPFS_ARCH ]; then
  360. echo $'No architecture specified'
  361. ARCHITECTURE=$(uname -m)
  362. if [[ $ARCHITECTURE == "arm"* || $ARCHITECTURE == *"aarch"* ]]; then
  363. IPFS_ARCH=arm
  364. echo $"Using $IPFS_ARCH"
  365. fi
  366. if [[ $ARCHITECTURE == "amd"* || $ARCHITECTURE == "x86_64" ]]; then
  367. IPFS_ARCH=amd64
  368. echo $"Using $IPFS_ARCH"
  369. fi
  370. if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
  371. IPFS_ARCH=386
  372. echo $"Using $IPFS_ARCH"
  373. fi
  374. fi
  375. if [ ! $IPFS_ARCH ]; then
  376. echo $'Architecture not detected for IPFS install'
  377. exit 738765235
  378. fi
  379. IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
  380. wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE}
  381. if [ ! -f $rootdir$INSTALL_DIR/ipfs/${IPFS_FILE} ]; then
  382. echo $'IPFS package could not be downloaded'
  383. exit 63725
  384. fi
  385. tar -xzvf ${IPFS_FILE}
  386. if [ ! -f $rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs ]; then
  387. echo $"ipfs was not found in downloaded package"
  388. exit 638235
  389. fi
  390. chroot "$rootdir" /bin/cp $INSTALL_DIR/ipfs/go-ipfs/ipfs $IPFS_PATH
  391. if [ ! -f $rootdir$IPFS_PATH/ipfs ]; then
  392. echo $'IPFS was not installed'
  393. exit 63722
  394. fi
  395. IPFS_USER_DAEMON=${rootdir}/home/${MY_USERNAME}/.config/systemd/user/ipfs.service
  396. mkdir -p ${rootdir}/home/${MY_USERNAME}/.config/systemd/user
  397. echo '[Unit]' > $IPFS_USER_DAEMON
  398. echo 'Description=IPFS go daemon' >> $IPFS_USER_DAEMON
  399. echo '' >> $IPFS_USER_DAEMON
  400. echo '[Service]' >> $IPFS_USER_DAEMON
  401. echo "ExecStart=$IPFS_PATH/ipfs daemon" >> $IPFS_USER_DAEMON
  402. echo 'Restart=on-failure' >> $IPFS_USER_DAEMON
  403. echo 'RestartSec=10' >> $IPFS_USER_DAEMON
  404. echo '' >> $IPFS_USER_DAEMON
  405. echo '[Install]' >> $IPFS_USER_DAEMON
  406. echo 'WantedBy=default.target' >> $IPFS_USER_DAEMON
  407. chroot ${rootdir} /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/${MY_USERNAME}/.config
  408. }
  409. function install_ipfs_go {
  410. if [ $INSTALLING_MESH ]; then
  411. mesh_install_ipfs_go
  412. return
  413. fi
  414. if [[ $(app_is_installed ipfs_go) == "1" ]]; then
  415. return
  416. fi
  417. apt-get -yq install golang libpam0g-dev fuse
  418. if [ ! -d /home/git ]; then
  419. # add a gogs user account
  420. adduser --disabled-login --gecos 'Gogs' git
  421. if [ ! -d /home/git ]; then
  422. echo $"/home/git directory not created"
  423. exit 735272
  424. fi
  425. # install Go
  426. if ! grep -q "export GOPATH=" ~/.bashrc; then
  427. echo "export GOPATH=$GOPATH" >> ~/.bashrc
  428. else
  429. sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
  430. fi
  431. systemctl set-environment GOPATH=$GOPATH
  432. if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
  433. echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
  434. else
  435. sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
  436. fi
  437. if [ ! -d $GOPATH ]; then
  438. mkdir -p $GOPATH
  439. fi
  440. fi
  441. IPFS_PATH=$GOPATH/bin
  442. export PATH="$GOPATH/bin:$PATH:"
  443. if ! grep -q 'GOPATH/bin' ~/.bashrc; then
  444. echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
  445. else
  446. sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
  447. fi
  448. # set gopath for the user
  449. if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
  450. echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
  451. echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
  452. else
  453. sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
  454. fi
  455. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
  456. go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs
  457. if [ ! "$?" = "0" ]; then
  458. exit 8242
  459. fi
  460. if [ ! -d $GOPATH/src/$IPFS_GO_REPO_BASE ]; then
  461. echo $'go get failed to get ipfs'
  462. exit 63923
  463. fi
  464. cd $GOPATH/src/$IPFS_GO_REPO_BASE
  465. git checkout $IPFS_COMMIT -b $IPFS_COMMIT
  466. if [ ! "$?" = "0" ]; then
  467. exit 735639
  468. fi
  469. set_completion_param "ipfs commit" "$IPFS_COMMIT"
  470. make install
  471. if [ ! "$?" = "0" ]; then
  472. exit 547242
  473. fi
  474. # initialise
  475. su -c "$IPFS_PATH/ipfs init -b 2048" - $MY_USERNAME
  476. if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
  477. echo "IPFS could not be initialised for user $MY_USERNAME"
  478. exit 7358
  479. fi
  480. # directories to mount to
  481. if [ ! -d /ipfs ]; then
  482. mkdir /ipfs
  483. mkdir /ipns
  484. chown $MY_USERNAME:$MY_USERNAME /ipfs
  485. chown $MY_USERNAME:$MY_USERNAME /ipns
  486. fi
  487. if [ -f /etc/fuse.conf ]; then
  488. chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  489. fi
  490. if [ -f /dev/fuse ]; then
  491. chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  492. fi
  493. echo '[Unit]' > /etc/systemd/system/ipfs.service
  494. echo 'Description=IPFS go daemon' >> /etc/systemd/system/ipfs.service
  495. echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
  496. echo 'After=network.target' >> /etc/systemd/system/ipfs.service
  497. echo '' >> /etc/systemd/system/ipfs.service
  498. echo '[Service]' >> /etc/systemd/system/ipfs.service
  499. echo 'Type=simple' >> /etc/systemd/system/ipfs.service
  500. echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
  501. echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
  502. echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
  503. echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
  504. echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
  505. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
  506. echo '' >> /etc/systemd/system/ipfs.service
  507. echo '[Install]' >> /etc/systemd/system/ipfs.service
  508. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
  509. systemctl enable ipfs
  510. systemctl daemon-reload
  511. systemctl restart ipfs
  512. if [ -d /etc/avahi ]; then
  513. su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
  514. if [ ! -f /tmp/ipfsid ]; then
  515. echo 'No IPFS identity was created'
  516. exit 37895
  517. fi
  518. IPFS_PEER_ID=$(cat /tmp/ipfsid)
  519. if [ ${#IPFS_PEER_ID} -lt 10 ]; then
  520. echo 'Invalid IPFS peer ID'
  521. echo "$IPFS_PEER_ID"
  522. exit 74782
  523. fi
  524. # Add an avahi service
  525. function_check create_avahi_service
  526. create_avahi_service ipfs_id "ipfs_id" 'udp' $IPFS_PORT "$IPFS_PEER_ID:none"
  527. rm /tmp/ipfsid
  528. fi
  529. function_check configure_firewall_for_ipfs
  530. configure_firewall_for_ipfs
  531. install_completed ipfs_go
  532. }
  533. function install_ipfs {
  534. #install_ipfs_js
  535. install_ipfs_go
  536. APP_INSTALLED=1
  537. }