freedombone-app-ipfs 18KB

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