freedombone-app-ipfs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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@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. IPFS_GO_REPO_BASE="github.com/ipfs/go-ipfs"
  32. IPFS_GO_REPO='https://github.com/ipfs/go-ipfs'
  33. IPFS_COMMIT='6fdfaaf6e4783ae1be7b348e7a6bc0640982c7df'
  34. IPFS_PORT=4001
  35. IPFS_NODE_VERSION='6.2.2'
  36. IPFS_N_VERSION='2.1.4'
  37. IPFS_JS_VERSION='0.14.3'
  38. IPFS_JS_RONIN_VERSION='0.3.11'
  39. IPFS_KEY_LENGTH=2048
  40. IPFS_GO_VERSION=0.4.2
  41. ipfs_variables=(IPFS_COMMIT
  42. IPFS_GO_VERSION
  43. IPFS_KEY_LENGTH
  44. IPFS_PORT)
  45. function install_interactive_ipfs {
  46. echo -n ''
  47. APP_INSTALLED=1
  48. }
  49. function change_password_ipfs {
  50. echo -n ''
  51. }
  52. function reconfigure_ipfs {
  53. echo -n ''
  54. }
  55. function upgrade_ipfs_go {
  56. if [[ $(app_is_installed ipfs_go) == "0" ]]; then
  57. return
  58. fi
  59. function_check set_repo_commit
  60. set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
  61. }
  62. function upgrade_ipfs_js {
  63. if [[ $(app_is_installed ipfs_js) == "0" ]]; then
  64. return
  65. fi
  66. npm cache clean -f
  67. npm install -g n
  68. n ${IPFS_NODE_VERSION}
  69. npm install ronin@${IPFS_JS_RONIN_VERSION} --global
  70. npm install ipfs@${IPFS_JS_VERSION} --global
  71. }
  72. function upgrade_ipfs {
  73. upgrade_ipfs_js
  74. upgrade_ipfs_go
  75. }
  76. function backup_local_ipfs {
  77. if ! grep -q "Admin user" $COMPLETION_FILE; then
  78. return
  79. fi
  80. ADMIN_USERNAME=$(get_completion_param "Admin user")
  81. source_directory=/home/$ADMIN_USERNAME/.ipfs
  82. if [ -d $source_directory ]; then
  83. dest_directory=ipfs
  84. echo $"Backing up $source_directory to $dest_directory"
  85. function_check backup_directory_to_usb
  86. backup_directory_to_usb $source_directory $dest_directory
  87. echo $"Backup to $dest_directory complete"
  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. rm -rf $GOPATH/src/github.com/ipfs
  147. iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
  148. function_check save_firewall_settings
  149. save_firewall_settings
  150. sed -i '/install_ipfs/d' $COMPLETION_FILE
  151. sed -i '/ipfs/d' $COMPLETION_FILE
  152. sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
  153. }
  154. function remove_ipfs_js {
  155. systemctl stop ipfs
  156. systemctl disable ipfs
  157. rm /etc/systemd/system/ipfs.service
  158. systemctl daemon-reload
  159. npm uninstall ipfs --global
  160. npm uninstall ronin --global
  161. iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
  162. function_check save_firewall_settings
  163. save_firewall_settings
  164. sed -i '/install_ipfs/d' $COMPLETION_FILE
  165. sed -i '/ipfs/d' $COMPLETION_FILE
  166. sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
  167. }
  168. function remove_ipfs {
  169. remove_ipfs_js
  170. remove_ipfs_go
  171. }
  172. function configure_firewall_for_ipfs {
  173. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  174. return
  175. fi
  176. if [[ $ONION_ONLY != "no" ]]; then
  177. return
  178. fi
  179. iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
  180. function_check save_firewall_settings
  181. save_firewall_settings
  182. OPEN_PORTS+=("IPFS $IPFS_PORT")
  183. mark_completed $FUNCNAME
  184. }
  185. function mesh_install_ipfs_js {
  186. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  187. return
  188. fi
  189. chroot ${rootdir} apt-get -y install nodejs
  190. chroot ${rootdir} apt-get -y install npm curl
  191. chroot ${rootdir} apt-get -y install libpam0g-dev fuse
  192. if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
  193. echo $'nodejs was not installed'
  194. exit 63962
  195. fi
  196. cat <<EOF > ${rootdir}/root/install-ipfs.sh
  197. #!/bin/bash
  198. PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
  199. NODE_PATH="/usr/lib/node_modules"
  200. cp /usr/bin/nodejs /usr/local/bin/node
  201. cp /usr/bin/nodejs /usr/bin/node
  202. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  203. npm install -g n@${IPFS_N_VERSION} --save
  204. n ${IPFS_NODE_VERSION}
  205. npm install -g ronin@${IPFS_JS_RONIN_VERSION} --save
  206. npm install -g ipfs@${IPFS_JS_VERSION} --save
  207. exit 0
  208. EOF
  209. chroot ${rootdir} /bin/chmod +x /root/install-ipfs.sh
  210. chroot ${rootdir} /root/install-ipfs.sh
  211. rm -f ${rootdir}/root/install-ipfs.sh
  212. IPFS_PATH=/usr/bin
  213. if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
  214. exit 637292
  215. fi
  216. # directories to mount to
  217. if [ ! -d ${rootdir}/ipfs ]; then
  218. chroot ${rootdir} /bin/mkdir /ipfs
  219. chroot ${rootdir} /bin/mkdir /ipns
  220. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipfs
  221. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipns
  222. fi
  223. if [ -f ${rootdir}/etc/fuse.conf ]; then
  224. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  225. fi
  226. if [ -f ${rootdir}/dev/fuse ]; then
  227. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  228. fi
  229. IPFS_DAEMON_NAME=ipfs
  230. IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
  231. echo '[Unit]' > $IPFS_DAEMON_FILE
  232. echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
  233. echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
  234. echo 'After=network.target' >> $IPFS_DAEMON_FILE
  235. echo '' >> $IPFS_DAEMON_FILE
  236. echo '[Service]' >> $IPFS_DAEMON_FILE
  237. echo 'Type=simple' >> $IPFS_DAEMON_FILE
  238. echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  239. echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  240. echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
  241. echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
  242. echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
  243. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
  244. echo '' >> $IPFS_DAEMON_FILE
  245. echo '[Install]' >> $IPFS_DAEMON_FILE
  246. echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
  247. chroot ${rootdir} systemctl enable ${IPFS_DAEMON_NAME}
  248. mark_completed $FUNCNAME
  249. }
  250. function install_ipfs_js {
  251. if [ $INSTALLING_MESH ]; then
  252. mesh_install_ipfs_js
  253. return
  254. fi
  255. if [[ $(app_is_installed ipfs_js) == "1" ]]; then
  256. return
  257. fi
  258. apt-get -y install nodejs
  259. apt-get -y install npm
  260. apt-get -y install libpam0g-dev fuse
  261. if [ ! -f /usr/bin/nodejs ]; then
  262. echo $'nodejs was not installed'
  263. exit 63962
  264. fi
  265. cp /usr/bin/nodejs /usr/local/bin/node
  266. cp /usr/bin/nodejs /usr/bin/node
  267. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  268. /usr/local/bin/npm install -g n@${IPFS_N_VERSION}
  269. /usr/local/bin/n ${IPFS_NODE_VERSION}
  270. /usr/local/bin/npm install -g ronin@${IPFS_JS_RONIN_VERSION}
  271. /usr/local/bin/npm install -g ipfs@${IPFS_JS_VERSION}
  272. IPFS_PATH=/usr/bin
  273. if [ ! -f $IPFS_PATH/jsipfs ]; then
  274. exit 637292
  275. fi
  276. # initialise
  277. su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
  278. if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
  279. echo "IPFS could not be initialised for user $MY_USERNAME"
  280. exit 7358
  281. fi
  282. # directories to mount to
  283. if [ ! -d /ipfs ]; then
  284. mkdir /ipfs
  285. mkdir /ipns
  286. chown $MY_USERNAME:$MY_USERNAME /ipfs
  287. chown $MY_USERNAME:$MY_USERNAME /ipns
  288. fi
  289. if [ -f /etc/fuse.conf ]; then
  290. chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  291. fi
  292. if [ -f /dev/fuse ]; then
  293. chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  294. fi
  295. IPFS_DAEMON_NAME=ipfs
  296. IPFS_DAEMON_FILE=/etc/systemd/system/${IPFS_DAEMON_NAME}.service
  297. echo '[Unit]' > $IPFS_DAEMON_FILE
  298. echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
  299. echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
  300. echo 'After=network.target' >> $IPFS_DAEMON_FILE
  301. echo '' >> $IPFS_DAEMON_FILE
  302. echo '[Service]' >> $IPFS_DAEMON_FILE
  303. echo 'Type=simple' >> $IPFS_DAEMON_FILE
  304. echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  305. echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  306. echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
  307. echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
  308. echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
  309. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
  310. echo '' >> $IPFS_DAEMON_FILE
  311. echo '[Install]' >> $IPFS_DAEMON_FILE
  312. echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
  313. systemctl enable ${IPFS_DAEMON_NAME}
  314. systemctl daemon-reload
  315. systemctl restart ${IPFS_DAEMON_NAME}
  316. if [ -d /etc/avahi ]; then
  317. su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
  318. if [ ! -f /tmp/ipfsid ]; then
  319. echo 'No IPFS identity was created'
  320. exit 37895
  321. fi
  322. IPFS_PEER_ID=$(cat /tmp/ipfsid)
  323. if [ ${#IPFS_PEER_ID} -lt 10 ]; then
  324. echo 'Invalid IPFS peer ID'
  325. echo "$IPFS_PEER_ID"
  326. exit 74782
  327. fi
  328. rm /tmp/ipfsid
  329. fi
  330. function_check configure_firewall_for_ipfs
  331. configure_firewall_for_ipfs
  332. install_completed ipfs_js
  333. }
  334. function mesh_install_ipfs_go {
  335. chroot ${rootdir} apt-get -y install libpam0g-dev fuse wget
  336. mesh_upgrade_golang
  337. IPFS_ARCH=
  338. IPFS_PATH=/usr/bin
  339. if [ ! -d $rootdir$INSTALL_DIR/ipfs ]; then
  340. mkdir -p $rootdir$INSTALL_DIR/ipfs
  341. fi
  342. cd $rootdir$INSTALL_DIR/ipfs
  343. if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
  344. IPFS_ARCH=386
  345. fi
  346. if [[ $ARCHITECTURE == *"amd64" || $ARCHITECTURE == "x86_64" ]]; then
  347. IPFS_ARCH=amd64
  348. fi
  349. if [[ $ARCHITECTURE == *"arm"* ]]; then
  350. IPFS_ARCH=arm
  351. fi
  352. if [ ! $IPFS_ARCH ]; then
  353. echo $'No architecture specified'
  354. ARCHITECTURE=$(uname -m)
  355. if [[ $ARCHITECTURE == "arm"* ]]; then
  356. IPFS_ARCH=arm
  357. fi
  358. if [[ $ARCHITECTURE == "amd"* || $ARCHITECTURE == "x86_64" ]]; then
  359. IPFS_ARCH=amd64
  360. fi
  361. if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
  362. IPFS_ARCH=386
  363. fi
  364. fi
  365. IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
  366. wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE}
  367. if [ ! -f $rootdir$INSTALL_DIR/ipfs/${IPFS_FILE} ]; then
  368. echo $'IPFS package could not be downloaded'
  369. exit 63725
  370. fi
  371. tar -xzvf ${IPFS_FILE}
  372. if [ ! -f $rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs ]; then
  373. echo $"ipfs was not found in downloaded package"
  374. exit 638235
  375. fi
  376. chroot "$rootdir" /bin/cp $INSTALL_DIR/ipfs/go-ipfs/ipfs $IPFS_PATH
  377. if [ ! -f $rootdir$IPFS_PATH/ipfs ]; then
  378. echo $'IPFS was not installed'
  379. exit 63722
  380. fi
  381. IPFS_USER_DAEMON=${rootdir}/home/${MY_USERNAME}/.config/systemd/user/ipfs.service
  382. mkdir -p ${rootdir}/home/${MY_USERNAME}/.config/systemd/user
  383. echo '[Unit]' > $IPFS_USER_DAEMON
  384. echo 'Description=IPFS go daemon' >> $IPFS_USER_DAEMON
  385. echo '' >> $IPFS_USER_DAEMON
  386. echo '[Service]' >> $IPFS_USER_DAEMON
  387. echo "ExecStart=$IPFS_PATH/ipfs daemon" >> $IPFS_USER_DAEMON
  388. echo 'Restart=on-failure' >> $IPFS_USER_DAEMON
  389. echo 'RestartSec=10' >> $IPFS_USER_DAEMON
  390. echo '' >> $IPFS_USER_DAEMON
  391. echo '[Install]' >> $IPFS_USER_DAEMON
  392. echo 'WantedBy=default.target' >> $IPFS_USER_DAEMON
  393. chroot ${rootdir} /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/${MY_USERNAME}/.config
  394. }
  395. function install_ipfs_go {
  396. if [ $INSTALLING_MESH ]; then
  397. mesh_install_ipfs_go
  398. return
  399. fi
  400. if [[ $(app_is_installed ipfs_go) == "1" ]]; then
  401. return
  402. fi
  403. apt-get -y install golang libpam0g-dev fuse
  404. if [ ! -d /home/git ]; then
  405. # add a gogs user account
  406. adduser --disabled-login --gecos 'Gogs' git
  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 4096" - $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. }