freedombone-app-ipfs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. 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.2
  41. ipfs_variables=(IPFS_COMMIT
  42. IPFS_GO_VERSION
  43. IPFS_KEY_LENGTH
  44. IPFS_PORT)
  45. function install_interactive_ipfs {
  46. echo -n ''
  47. }
  48. function change_password_ipfs {
  49. echo -n ''
  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=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  80. source_directory=/home/$ADMIN_USERNAME/.ipfs
  81. if [ -d $source_directory ]; then
  82. dest_directory=ipfs
  83. echo $"Backing up $source_directory to $dest_directory"
  84. function_check backup_directory_to_usb
  85. backup_directory_to_usb $source_directory $dest_directory
  86. echo $"Backup to $dest_directory complete"
  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=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  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=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
  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. if [[ $(app_is_installed ipfs_go) == "0" ]]; then
  142. return
  143. fi
  144. systemctl stop ipfs
  145. systemctl disable ipfs
  146. systemctl daemon-reload
  147. rm /etc/systemd/system/ipfs.service
  148. rm -rf $GOPATH/src/github.com/ipfs
  149. iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
  150. function_check save_firewall_settings
  151. save_firewall_settings
  152. sed -i '/install_ipfs/d' $COMPLETION_FILE
  153. sed -i '/ipfs/d' $COMPLETION_FILE
  154. sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
  155. }
  156. function remove_ipfs_js {
  157. if [[ $(app_is_installed ipfs_js) == "0" ]]; then
  158. return
  159. fi
  160. systemctl stop ipfs
  161. systemctl disable ipfs
  162. rm /etc/systemd/system/ipfs.service
  163. systemctl daemon-reload
  164. npm uninstall ipfs --global
  165. npm uninstall ronin --global
  166. iptables -D INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
  167. function_check save_firewall_settings
  168. save_firewall_settings
  169. sed -i '/install_ipfs/d' $COMPLETION_FILE
  170. sed -i '/ipfs/d' $COMPLETION_FILE
  171. sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
  172. }
  173. function remove_ipfs {
  174. remove_ipfs_js
  175. remove_ipfs_go
  176. }
  177. function configure_firewall_for_ipfs {
  178. if grep -Fxq "configure_firewall_for_ipfs" $COMPLETION_FILE; then
  179. return
  180. fi
  181. if [[ $ONION_ONLY != "no" ]]; then
  182. return
  183. fi
  184. iptables -A INPUT -p tcp --dport $IPFS_PORT -j ACCEPT
  185. function_check save_firewall_settings
  186. save_firewall_settings
  187. OPEN_PORTS+=("IPFS $IPFS_PORT")
  188. echo 'configure_firewall_for_ipfs' >> $COMPLETION_FILE
  189. }
  190. function mesh_install_ipfs_js {
  191. if grep -Fxq "mesh_install_ipfs_js" $COMPLETION_FILE; then
  192. return
  193. fi
  194. chroot ${rootdir} apt-get -y install nodejs
  195. chroot ${rootdir} apt-get -y install npm curl
  196. chroot ${rootdir} apt-get -y install libpam0g-dev fuse
  197. if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
  198. echo $'nodejs was not installed'
  199. exit 63962
  200. fi
  201. cat <<EOF > ${rootdir}/root/install-ipfs.sh
  202. #!/bin/bash
  203. PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
  204. NODE_PATH="/usr/lib/node_modules"
  205. cp /usr/bin/nodejs /usr/local/bin/node
  206. cp /usr/bin/nodejs /usr/bin/node
  207. /usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
  208. npm install -g n@${IPFS_N_VERSION} --save
  209. n ${IPFS_NODE_VERSION}
  210. npm install -g ronin@${IPFS_JS_RONIN_VERSION} --save
  211. npm install -g ipfs@${IPFS_JS_VERSION} --save
  212. exit 0
  213. EOF
  214. chroot ${rootdir} /bin/chmod +x /root/install-ipfs.sh
  215. chroot ${rootdir} /root/install-ipfs.sh
  216. rm -f ${rootdir}/root/install-ipfs.sh
  217. IPFS_PATH=/usr/bin
  218. if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
  219. exit 637292
  220. fi
  221. # directories to mount to
  222. if [ ! -d ${rootdir}/ipfs ]; then
  223. chroot ${rootdir} /bin/mkdir /ipfs
  224. chroot ${rootdir} /bin/mkdir /ipns
  225. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipfs
  226. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipns
  227. fi
  228. if [ -f ${rootdir}/etc/fuse.conf ]; then
  229. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  230. fi
  231. if [ -f ${rootdir}/dev/fuse ]; then
  232. chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  233. fi
  234. IPFS_DAEMON_NAME=ipfs
  235. IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
  236. echo '[Unit]' > $IPFS_DAEMON_FILE
  237. echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
  238. echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
  239. echo 'After=network.target' >> $IPFS_DAEMON_FILE
  240. echo '' >> $IPFS_DAEMON_FILE
  241. echo '[Service]' >> $IPFS_DAEMON_FILE
  242. echo 'Type=simple' >> $IPFS_DAEMON_FILE
  243. echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  244. echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  245. echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
  246. echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
  247. echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
  248. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
  249. echo '' >> $IPFS_DAEMON_FILE
  250. echo '[Install]' >> $IPFS_DAEMON_FILE
  251. echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
  252. chroot ${rootdir} systemctl enable ${IPFS_DAEMON_NAME}
  253. echo 'mesh install_ipfs_js' >> $COMPLETION_FILE
  254. }
  255. function install_ipfs_js {
  256. if [ $INSTALLING_MESH ]; then
  257. mesh_install_ipfs_js
  258. return
  259. fi
  260. if [[ $(app_is_installed ipfs_js) == "1" ]]; then
  261. return
  262. fi
  263. apt-get -y install nodejs
  264. apt-get -y install npm
  265. apt-get -y 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]' > $IPFS_DAEMON_FILE
  303. echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
  304. echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
  305. echo 'After=network.target' >> $IPFS_DAEMON_FILE
  306. echo '' >> $IPFS_DAEMON_FILE
  307. echo '[Service]' >> $IPFS_DAEMON_FILE
  308. echo 'Type=simple' >> $IPFS_DAEMON_FILE
  309. echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  310. echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
  311. echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
  312. echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
  313. echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
  314. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
  315. echo '' >> $IPFS_DAEMON_FILE
  316. echo '[Install]' >> $IPFS_DAEMON_FILE
  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 -y 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
  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"* ]]; 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"* ]]; then
  361. IPFS_ARCH=arm
  362. fi
  363. if [[ $ARCHITECTURE == "amd"* || $ARCHITECTURE == "x86_64" ]]; then
  364. IPFS_ARCH=amd64
  365. fi
  366. if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
  367. IPFS_ARCH=386
  368. fi
  369. fi
  370. IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
  371. wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE}
  372. if [ ! -f $rootdir$INSTALL_DIR/ipfs/${IPFS_FILE} ]; then
  373. echo $'IPFS package could not be downloaded'
  374. exit 63725
  375. fi
  376. tar -xzvf ${IPFS_FILE}
  377. if [ ! -f $rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs ]; then
  378. echo $"ipfs was not found in downloaded package"
  379. exit 638235
  380. fi
  381. chroot "$rootdir" /bin/cp $INSTALL_DIR/ipfs/go-ipfs/ipfs $IPFS_PATH
  382. if [ ! -f $rootdir$IPFS_PATH/ipfs ]; then
  383. echo $'IPFS was not installed'
  384. exit 63722
  385. fi
  386. IPFS_USER_DAEMON=${rootdir}/home/${MY_USERNAME}/.config/systemd/user/ipfs.service
  387. mkdir -p ${rootdir}/home/${MY_USERNAME}/.config/systemd/user
  388. echo '[Unit]' > $IPFS_USER_DAEMON
  389. echo 'Description=IPFS go daemon' >> $IPFS_USER_DAEMON
  390. echo '' >> $IPFS_USER_DAEMON
  391. echo '[Service]' >> $IPFS_USER_DAEMON
  392. echo "ExecStart=$IPFS_PATH/ipfs daemon" >> $IPFS_USER_DAEMON
  393. echo 'Restart=on-failure' >> $IPFS_USER_DAEMON
  394. echo 'RestartSec=10' >> $IPFS_USER_DAEMON
  395. echo '' >> $IPFS_USER_DAEMON
  396. echo '[Install]' >> $IPFS_USER_DAEMON
  397. echo 'WantedBy=default.target' >> $IPFS_USER_DAEMON
  398. chroot ${rootdir} /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/${MY_USERNAME}/.config
  399. }
  400. function install_ipfs_go {
  401. if [ $INSTALLING_MESH ]; then
  402. mesh_install_ipfs_go
  403. return
  404. fi
  405. if [[ $(app_is_installed ipfs_go) == "1" ]]; then
  406. return
  407. fi
  408. apt-get -y install golang libpam0g-dev fuse
  409. if [ ! -d /home/git ]; then
  410. # add a gogs user account
  411. adduser --disabled-login --gecos 'Gogs' git
  412. # install Go
  413. if ! grep -q "export GOPATH=" ~/.bashrc; then
  414. echo "export GOPATH=$GOPATH" >> ~/.bashrc
  415. else
  416. sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
  417. fi
  418. systemctl set-environment GOPATH=$GOPATH
  419. if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
  420. echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
  421. else
  422. sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
  423. fi
  424. if [ ! -d $GOPATH ]; then
  425. mkdir -p $GOPATH
  426. fi
  427. fi
  428. IPFS_PATH=$GOPATH/bin
  429. export PATH="$GOPATH/bin:$PATH:"
  430. if ! grep -q 'GOPATH/bin' ~/.bashrc; then
  431. echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
  432. else
  433. sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
  434. fi
  435. # set gopath for the user
  436. if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
  437. echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
  438. echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
  439. else
  440. sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
  441. fi
  442. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
  443. go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs
  444. if [ ! "$?" = "0" ]; then
  445. exit 8242
  446. fi
  447. if [ ! -d $GOPATH/src/$IPFS_GO_REPO_BASE ]; then
  448. echo $'go get failed to get ipfs'
  449. exit 63923
  450. fi
  451. cd $GOPATH/src/$IPFS_GO_REPO_BASE
  452. git checkout $IPFS_COMMIT -b $IPFS_COMMIT
  453. if [ ! "$?" = "0" ]; then
  454. exit 735639
  455. fi
  456. if ! grep -q "ipfs commit" $COMPLETION_FILE; then
  457. echo "ipfs commit:$IPFS_COMMIT" >> $COMPLETION_FILE
  458. else
  459. sed -i "s/ipfs commit.*/ipfs commit:$IPFS_COMMIT/g" $COMPLETION_FILE
  460. fi
  461. make install
  462. if [ ! "$?" = "0" ]; then
  463. exit 547242
  464. fi
  465. # initialise
  466. su -c "$IPFS_PATH/ipfs init -b 4096" - $MY_USERNAME
  467. if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
  468. echo "IPFS could not be initialised for user $MY_USERNAME"
  469. exit 7358
  470. fi
  471. # directories to mount to
  472. if [ ! -d /ipfs ]; then
  473. mkdir /ipfs
  474. mkdir /ipns
  475. chown $MY_USERNAME:$MY_USERNAME /ipfs
  476. chown $MY_USERNAME:$MY_USERNAME /ipns
  477. fi
  478. if [ -f /etc/fuse.conf ]; then
  479. chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
  480. fi
  481. if [ -f /dev/fuse ]; then
  482. chown $MY_USERNAME:$MY_USERNAME /dev/fuse
  483. fi
  484. echo '[Unit]' > /etc/systemd/system/ipfs.service
  485. echo 'Description=IPFS go daemon' >> /etc/systemd/system/ipfs.service
  486. echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
  487. echo 'After=network.target' >> /etc/systemd/system/ipfs.service
  488. echo '' >> /etc/systemd/system/ipfs.service
  489. echo '[Service]' >> /etc/systemd/system/ipfs.service
  490. echo 'Type=simple' >> /etc/systemd/system/ipfs.service
  491. echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
  492. echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
  493. echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
  494. echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
  495. echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
  496. echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
  497. echo '' >> /etc/systemd/system/ipfs.service
  498. echo '[Install]' >> /etc/systemd/system/ipfs.service
  499. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
  500. systemctl enable ipfs
  501. systemctl daemon-reload
  502. systemctl restart ipfs
  503. if [ -d /etc/avahi ]; then
  504. su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
  505. if [ ! -f /tmp/ipfsid ]; then
  506. echo 'No IPFS identity was created'
  507. exit 37895
  508. fi
  509. IPFS_PEER_ID=$(cat /tmp/ipfsid)
  510. if [ ${#IPFS_PEER_ID} -lt 10 ]; then
  511. echo 'Invalid IPFS peer ID'
  512. echo "$IPFS_PEER_ID"
  513. exit 74782
  514. fi
  515. # Add an avahi service
  516. function_check create_avahi_service
  517. create_avahi_service ipfs_id "ipfs_id" 'udp' $IPFS_PORT "$IPFS_PEER_ID:none"
  518. rm /tmp/ipfsid
  519. fi
  520. function_check configure_firewall_for_ipfs
  521. configure_firewall_for_ipfs
  522. install_completed ipfs_go
  523. }
  524. function install_ipfs {
  525. #install_ipfs_js
  526. install_ipfs_go
  527. }