freedombone-app-ipfs 18KB

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