freedombone-app-ipfs 19KB

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