freedombone-app-ipfs 18KB

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