freedombone-app-ipfs 19KB

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