freedombone-app-ipfs 18KB

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