freedombone-app-ipfs 18KB

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