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