freedombone-app-ipfs 18KB

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