2016-07-03 17:13:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# ipfs functions
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2018-02-21 20:32:13 +01:00
|
|
|
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
|
2016-07-03 17:13:34 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-09-29 11:16:52 +02:00
|
|
|
VARIANTS=''
|
2016-07-06 17:47:55 +02:00
|
|
|
|
2016-10-19 22:52:59 +02:00
|
|
|
IN_DEFAULT_INSTALL=0
|
2016-11-20 22:14:37 +01:00
|
|
|
SHOW_ON_ABOUT=0
|
2016-10-19 22:52:59 +02:00
|
|
|
|
2016-08-15 09:42:10 +02:00
|
|
|
IPFS_GO_REPO_BASE="github.com/ipfs/go-ipfs"
|
2017-09-12 14:39:30 +02:00
|
|
|
IPFS_GO_REPO="https://$IPFS_GO_REPO_BASE"
|
2016-09-02 18:17:44 +02:00
|
|
|
IPFS_COMMIT='6fdfaaf6e4783ae1be7b348e7a6bc0640982c7df'
|
2016-07-03 17:13:34 +02:00
|
|
|
IPFS_PORT=4001
|
2016-08-12 10:19:09 +02:00
|
|
|
IPFS_NODE_VERSION='6.2.2'
|
2016-08-13 20:36:56 +02:00
|
|
|
IPFS_N_VERSION='2.1.4'
|
2016-08-12 10:19:09 +02:00
|
|
|
IPFS_JS_VERSION='0.14.3'
|
|
|
|
IPFS_JS_RONIN_VERSION='0.3.11'
|
2016-08-12 11:18:28 +02:00
|
|
|
IPFS_KEY_LENGTH=2048
|
2017-12-30 14:27:02 +01:00
|
|
|
IPFS_GO_VERSION=0.4.13
|
2016-07-03 17:13:34 +02:00
|
|
|
|
2016-11-24 19:37:10 +01:00
|
|
|
ipfs_variables=(IPFS_GO_VERSION
|
2016-10-05 23:33:41 +02:00
|
|
|
IPFS_KEY_LENGTH
|
|
|
|
IPFS_PORT)
|
|
|
|
|
2017-07-01 20:14:28 +02:00
|
|
|
function logging_on_ipfs {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function logging_off_ipfs {
|
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:34:39 +02:00
|
|
|
function install_interactive_ipfs {
|
|
|
|
echo -n ''
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-09-30 12:34:39 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 12:36:12 +02:00
|
|
|
function reconfigure_ipfs {
|
2016-08-12 10:19:09 +02:00
|
|
|
echo -n ''
|
2016-07-09 12:36:12 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:19:09 +02:00
|
|
|
function upgrade_ipfs_go {
|
2017-06-12 23:59:25 +02:00
|
|
|
CURR_IPFS_COMMIT=$(get_completion_param "ipfs commit")
|
|
|
|
if [[ "$CURR_IPFS_COMMIT" == "$IPFS_COMMIT" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-01 20:52:39 +02:00
|
|
|
if [[ $(app_is_installed ipfs_go) == "0" ]]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
function_check set_repo_commit
|
2018-02-27 15:11:56 +01:00
|
|
|
set_repo_commit "$GOPATH/src/github.com/ipfs/go-ipfs" "ipfs commit" "$IPFS_COMMIT" "$IPFS_REPO"
|
2016-08-12 10:19:09 +02:00
|
|
|
}
|
2016-07-06 16:40:09 +02:00
|
|
|
|
2016-08-12 10:19:09 +02:00
|
|
|
function upgrade_ipfs_js {
|
2016-10-01 20:52:39 +02:00
|
|
|
if [[ $(app_is_installed ipfs_js) == "0" ]]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-07-06 16:40:09 +02:00
|
|
|
|
2016-08-12 10:19:09 +02:00
|
|
|
npm cache clean -f
|
|
|
|
npm install -g n
|
|
|
|
n ${IPFS_NODE_VERSION}
|
|
|
|
npm install ronin@${IPFS_JS_RONIN_VERSION} --global
|
|
|
|
npm install ipfs@${IPFS_JS_VERSION} --global
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_ipfs {
|
|
|
|
upgrade_ipfs_js
|
|
|
|
upgrade_ipfs_go
|
2016-07-06 16:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_local_ipfs {
|
2018-02-27 15:11:56 +01:00
|
|
|
if ! grep -q "Admin user" "$COMPLETION_FILE"; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-10-16 20:50:56 +02:00
|
|
|
ADMIN_USERNAME=$(get_completion_param "Admin user")
|
2018-02-27 15:11:56 +01:00
|
|
|
source_directory="/home/$ADMIN_USERNAME/.ipfs"
|
|
|
|
if [ -d "$source_directory" ]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
dest_directory=ipfs
|
|
|
|
function_check backup_directory_to_usb
|
2018-02-27 15:11:56 +01:00
|
|
|
backup_directory_to_usb "$source_directory" "$dest_directory"
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
2016-07-06 15:55:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 11:54:41 +02:00
|
|
|
function restore_local_ipfs {
|
2018-02-27 15:11:56 +01:00
|
|
|
if ! grep -q "Admin user" "$COMPLETION_FILE"; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -d "$USB_MOUNT/backup/ipfs" ]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
echo $"Restoring IPFS"
|
|
|
|
temp_restore_dir=/root/tempipfs
|
|
|
|
function_check restore_directory_from_usb
|
|
|
|
restore_directory_from_usb $temp_restore_dir ipfs
|
2016-10-16 20:50:56 +02:00
|
|
|
ADMIN_USERNAME=$(get_completion_param "Admin user")
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs" ]; then
|
2018-03-03 12:49:17 +01:00
|
|
|
cp -rf "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/"* "/home/$ADMIN_USERNAME/.ipfs"
|
2017-08-25 18:35:33 +02:00
|
|
|
else
|
2018-03-03 12:49:17 +01:00
|
|
|
cp -rf "$temp_restore_dir/"* "/home/$ADMIN_USERNAME/.ipfs"
|
2017-08-25 18:35:33 +02:00
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
# shellcheck disable=SC2181
|
2016-08-12 10:19:09 +02:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
function_check set_user_permissions
|
|
|
|
set_user_permissions
|
|
|
|
function_check backup_unmount_drive
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 27627
|
|
|
|
fi
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
echo $"Restore of IPFS complete"
|
|
|
|
fi
|
2016-07-09 11:54:41 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 15:55:09 +02:00
|
|
|
function backup_remote_ipfs {
|
2018-02-27 15:11:56 +01:00
|
|
|
if ! grep -q "Admin user" "$COMPLETION_FILE"; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
2016-10-16 20:50:56 +02:00
|
|
|
ADMIN_USERNAME=$(get_completion_param "Admin user")
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -d "/home/$ADMIN_USERNAME/.ipfs" ]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
echo $"Backing up IPFS"
|
2018-02-27 15:11:56 +01:00
|
|
|
backup_directory_to_friend "/home/$ADMIN_USERNAME/.ipfs" ipfs
|
2016-08-12 10:19:09 +02:00
|
|
|
echo $"Backup of IPFS complete"
|
|
|
|
fi
|
2016-07-09 11:54:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function restore_remote_ipfs {
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -d "$SERVER_DIRECTORY/backup/ipfs" ]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
echo $"Restoring IPFS"
|
|
|
|
temp_restore_dir=/root/tempipfs
|
|
|
|
function_check restore_directory_from_friend
|
|
|
|
restore_directory_from_friend $temp_restore_dir ipfs
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs" ]; then
|
2018-03-03 12:49:17 +01:00
|
|
|
cp -rf "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/"* "/home/$ADMIN_USERNAME/.ipfs"
|
2017-08-25 18:35:33 +02:00
|
|
|
else
|
2018-03-03 12:49:17 +01:00
|
|
|
cp -rf "$temp_restore_dir/"* "/home/$ADMIN_USERNAME/.ipfs"
|
2017-08-25 18:35:33 +02:00
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
# shellcheck disable=SC2181
|
2016-08-12 10:19:09 +02:00
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
function_check set_user_permissions
|
|
|
|
set_user_permissions
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
exit 276357
|
|
|
|
fi
|
|
|
|
rm -rf $temp_restore_dir
|
|
|
|
echo $"Restore of IPFS complete"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_ipfs_go {
|
|
|
|
systemctl stop ipfs
|
|
|
|
systemctl disable ipfs
|
|
|
|
systemctl daemon-reload
|
|
|
|
rm /etc/systemd/system/ipfs.service
|
2017-06-10 22:37:50 +02:00
|
|
|
systemctl daemon-reload
|
2018-02-27 15:11:56 +01:00
|
|
|
rm -rf "$GOPATH/src/github.com/ipfs"
|
2016-10-22 11:39:34 +02:00
|
|
|
firewall_remove $IPFS_PORT tcp
|
2016-10-17 15:44:49 +02:00
|
|
|
remove_completion_param install_ipfs
|
|
|
|
remove_completion_param configure_firewall_for_ipfs
|
2018-02-27 15:11:56 +01:00
|
|
|
sed -i '/ipfs/d' "$COMPLETION_FILE"
|
2016-08-12 10:19:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_ipfs_js {
|
|
|
|
systemctl stop ipfs
|
|
|
|
systemctl disable ipfs
|
|
|
|
rm /etc/systemd/system/ipfs.service
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
|
|
|
npm uninstall ipfs --global
|
|
|
|
npm uninstall ronin --global
|
|
|
|
|
2016-10-22 11:39:34 +02:00
|
|
|
firewall_remove $IPFS_PORT tcp
|
2018-02-27 15:11:56 +01:00
|
|
|
sed -i '/install_ipfs/d' "$COMPLETION_FILE"
|
|
|
|
sed -i '/ipfs/d' "$COMPLETION_FILE"
|
|
|
|
sed -i '/configure_firewall_for_ipfs/d' "$COMPLETION_FILE"
|
2016-07-04 22:02:22 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 23:00:09 +02:00
|
|
|
function remove_ipfs {
|
2016-08-12 10:19:09 +02:00
|
|
|
remove_ipfs_js
|
|
|
|
remove_ipfs_go
|
2016-07-03 23:00:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 19:52:57 +02:00
|
|
|
function configure_firewall_for_ipfs {
|
2018-02-25 13:50:46 +01:00
|
|
|
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [[ $ONION_ONLY != "no" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-22 11:39:34 +02:00
|
|
|
firewall_add IPFS $IPFS_PORT tcp
|
2018-02-25 13:50:46 +01:00
|
|
|
mark_completed "${FUNCNAME[0]}"
|
2016-08-12 10:19:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 14:32:23 +02:00
|
|
|
function mesh_install_ipfs_js {
|
2018-02-25 13:50:46 +01:00
|
|
|
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
|
2016-08-12 14:32:23 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
chroot "${rootdir}" apt-get -yq install libpam0g-dev fuse
|
2016-08-12 14:32:23 +02:00
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then
|
2016-08-13 13:15:20 +02:00
|
|
|
echo $'nodejs was not installed'
|
|
|
|
exit 63962
|
|
|
|
fi
|
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
cat <<EOF > "${rootdir}/root/install-ipfs.sh"
|
2016-08-13 20:36:56 +02:00
|
|
|
#!/bin/bash
|
|
|
|
PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
|
|
|
|
NODE_PATH="/usr/lib/node_modules"
|
|
|
|
cp /usr/bin/nodejs /usr/local/bin/node
|
|
|
|
cp /usr/bin/nodejs /usr/bin/node
|
|
|
|
/usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
|
|
|
|
npm install -g n@${IPFS_N_VERSION} --save
|
|
|
|
n ${IPFS_NODE_VERSION}
|
|
|
|
npm install -g ronin@${IPFS_JS_RONIN_VERSION} --save
|
|
|
|
npm install -g ipfs@${IPFS_JS_VERSION} --save
|
2016-08-14 23:04:34 +02:00
|
|
|
exit 0
|
2016-08-13 20:36:56 +02:00
|
|
|
EOF
|
2018-02-27 15:11:56 +01:00
|
|
|
chroot "${rootdir}" /bin/chmod +x /root/install-ipfs.sh
|
|
|
|
chroot "${rootdir}" /root/install-ipfs.sh
|
|
|
|
rm -f "${rootdir}/root/install-ipfs.sh"
|
2016-08-13 20:36:56 +02:00
|
|
|
|
|
|
|
IPFS_PATH=/usr/bin
|
2016-08-12 14:32:23 +02:00
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -f "${rootdir}$IPFS_PATH/jsipfs" ]; then
|
2016-08-12 14:32:23 +02:00
|
|
|
exit 637292
|
|
|
|
fi
|
|
|
|
|
|
|
|
# directories to mount to
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -d "${rootdir}/ipfs" ]; then
|
|
|
|
chroot "${rootdir}" /bin/mkdir /ipfs
|
|
|
|
chroot "${rootdir}" /bin/mkdir /ipns
|
|
|
|
chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /ipfs
|
|
|
|
chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /ipns
|
2016-08-12 14:32:23 +02:00
|
|
|
fi
|
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -f "${rootdir}/etc/fuse.conf" ]; then
|
|
|
|
chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /etc/fuse.conf
|
2016-08-12 14:32:23 +02:00
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ -f "${rootdir}/dev/fuse" ]; then
|
|
|
|
chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
|
2016-08-12 14:32:23 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
IPFS_DAEMON_NAME=ipfs
|
|
|
|
IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
|
2018-02-27 15:11:56 +01:00
|
|
|
{ echo '[Unit]';
|
|
|
|
echo 'Description=IPFS javascript daemon';
|
|
|
|
echo 'After=syslog.target';
|
|
|
|
echo 'After=network.target';
|
|
|
|
echo '';
|
|
|
|
echo '[Service]';
|
|
|
|
echo 'Type=simple';
|
|
|
|
echo "User=$MY_USERNAME";
|
|
|
|
echo "Group=$MY_USERNAME";
|
|
|
|
echo "WorkingDirectory=/home/$MY_USERNAME";
|
|
|
|
echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount";
|
|
|
|
echo 'Restart=on-failure';
|
|
|
|
echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"";
|
|
|
|
echo '';
|
|
|
|
echo '[Install]';
|
|
|
|
echo 'WantedBy=multi-user.target'; } > "$IPFS_DAEMON_FILE"
|
|
|
|
|
|
|
|
chroot "${rootdir}" systemctl enable ${IPFS_DAEMON_NAME}
|
2016-08-12 14:32:23 +02:00
|
|
|
|
2018-02-25 13:50:46 +01:00
|
|
|
mark_completed "${FUNCNAME[0]}"
|
2016-08-12 14:32:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 10:19:09 +02:00
|
|
|
function install_ipfs_js {
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ "$INSTALLING_MESH" ]; then
|
2016-08-12 14:32:23 +02:00
|
|
|
mesh_install_ipfs_js
|
|
|
|
return
|
|
|
|
fi
|
2016-09-30 17:00:45 +02:00
|
|
|
if [[ $(app_is_installed ipfs_js) == "1" ]]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-23 20:38:14 +02:00
|
|
|
apt-get -yq install libpam0g-dev fuse
|
2016-08-12 10:19:09 +02:00
|
|
|
|
2016-08-13 13:15:20 +02:00
|
|
|
if [ ! -f /usr/bin/nodejs ]; then
|
|
|
|
echo $'nodejs was not installed'
|
|
|
|
exit 63962
|
|
|
|
fi
|
|
|
|
|
2016-08-13 20:36:56 +02:00
|
|
|
cp /usr/bin/nodejs /usr/local/bin/node
|
|
|
|
cp /usr/bin/nodejs /usr/bin/node
|
|
|
|
/usr/bin/curl -0 -L https://npmjs.org/install.sh | sh
|
|
|
|
/usr/local/bin/npm install -g n@${IPFS_N_VERSION}
|
|
|
|
/usr/local/bin/n ${IPFS_NODE_VERSION}
|
|
|
|
/usr/local/bin/npm install -g ronin@${IPFS_JS_RONIN_VERSION}
|
|
|
|
/usr/local/bin/npm install -g ipfs@${IPFS_JS_VERSION}
|
2016-08-12 10:19:09 +02:00
|
|
|
|
2016-08-13 20:36:56 +02:00
|
|
|
IPFS_PATH=/usr/bin
|
2016-08-12 10:19:09 +02:00
|
|
|
|
2016-08-12 10:27:30 +02:00
|
|
|
if [ ! -f $IPFS_PATH/jsipfs ]; then
|
|
|
|
exit 637292
|
|
|
|
fi
|
|
|
|
|
2016-08-12 10:19:09 +02:00
|
|
|
# initialise
|
2018-02-27 15:11:56 +01:00
|
|
|
su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - "$MY_USERNAME"
|
|
|
|
if [ ! -d "/home/$MY_USERNAME/.ipfs" ]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
echo "IPFS could not be initialised for user $MY_USERNAME"
|
|
|
|
exit 7358
|
|
|
|
fi
|
|
|
|
|
|
|
|
# directories to mount to
|
|
|
|
if [ ! -d /ipfs ]; then
|
|
|
|
mkdir /ipfs
|
|
|
|
mkdir /ipns
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /ipfs
|
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /ipns
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/fuse.conf ]; then
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /etc/fuse.conf
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
|
|
|
if [ -f /dev/fuse ]; then
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
IPFS_DAEMON_NAME=ipfs
|
|
|
|
IPFS_DAEMON_FILE=/etc/systemd/system/${IPFS_DAEMON_NAME}.service
|
2018-02-27 15:11:56 +01:00
|
|
|
{ echo '[Unit]';
|
|
|
|
echo 'Description=IPFS javascript daemon';
|
|
|
|
echo 'After=syslog.target';
|
|
|
|
echo 'After=network.target';
|
|
|
|
echo '';
|
|
|
|
echo '[Service]';
|
|
|
|
echo 'Type=simple';
|
|
|
|
echo "User=$MY_USERNAME";
|
|
|
|
echo "Group=$MY_USERNAME";
|
|
|
|
echo "WorkingDirectory=/home/$MY_USERNAME";
|
|
|
|
echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount";
|
|
|
|
echo 'Restart=on-failure';
|
|
|
|
echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"";
|
|
|
|
echo '';
|
|
|
|
echo '[Install]';
|
|
|
|
echo 'WantedBy=multi-user.target'; } > $IPFS_DAEMON_FILE
|
2016-08-12 10:19:09 +02:00
|
|
|
|
|
|
|
systemctl enable ${IPFS_DAEMON_NAME}
|
2016-08-12 10:24:22 +02:00
|
|
|
systemctl daemon-reload
|
2016-08-12 10:19:09 +02:00
|
|
|
systemctl restart ${IPFS_DAEMON_NAME}
|
|
|
|
|
|
|
|
if [ -d /etc/avahi ]; then
|
2018-03-02 20:52:07 +01:00
|
|
|
su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - "$MY_USERNAME"
|
2016-08-12 10:19:09 +02:00
|
|
|
if [ ! -f /tmp/ipfsid ]; then
|
|
|
|
echo 'No IPFS identity was created'
|
|
|
|
exit 37895
|
|
|
|
fi
|
|
|
|
IPFS_PEER_ID=$(cat /tmp/ipfsid)
|
|
|
|
if [ ${#IPFS_PEER_ID} -lt 10 ]; then
|
|
|
|
echo 'Invalid IPFS peer ID'
|
|
|
|
echo "$IPFS_PEER_ID"
|
|
|
|
exit 74782
|
|
|
|
fi
|
|
|
|
rm /tmp/ipfsid
|
|
|
|
fi
|
|
|
|
|
|
|
|
function_check configure_firewall_for_ipfs
|
|
|
|
configure_firewall_for_ipfs
|
|
|
|
|
2016-09-30 17:00:45 +02:00
|
|
|
install_completed ipfs_js
|
2016-08-12 10:19:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 23:04:34 +02:00
|
|
|
function mesh_install_ipfs_go {
|
2018-02-27 15:11:56 +01:00
|
|
|
chroot "${rootdir}" apt-get -yq install libpam0g-dev fuse wget
|
2016-08-14 23:04:34 +02:00
|
|
|
|
|
|
|
mesh_upgrade_golang
|
|
|
|
|
2016-09-03 16:36:44 +02:00
|
|
|
IPFS_ARCH=
|
2016-09-02 18:17:44 +02:00
|
|
|
IPFS_PATH=/usr/bin
|
2016-08-14 23:04:34 +02:00
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -d "$rootdir$INSTALL_DIR/ipfs" ]; then
|
|
|
|
mkdir -p "$rootdir$INSTALL_DIR/ipfs"
|
2016-09-03 16:36:44 +02:00
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
cd "$rootdir$INSTALL_DIR/ipfs" || exit 23468264
|
2016-08-15 09:42:10 +02:00
|
|
|
|
2016-09-06 14:51:56 +02:00
|
|
|
if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
|
2016-09-03 16:36:44 +02:00
|
|
|
IPFS_ARCH=386
|
|
|
|
fi
|
2016-09-29 11:16:52 +02:00
|
|
|
if [[ $ARCHITECTURE == *"amd64" || $ARCHITECTURE == "x86_64" ]]; then
|
2016-09-03 16:36:44 +02:00
|
|
|
IPFS_ARCH=amd64
|
|
|
|
fi
|
2017-09-18 16:27:11 +02:00
|
|
|
if [[ $ARCHITECTURE == *"arm"* || $ARCHITECTURE == *"aarch"* ]]; then
|
2016-09-03 16:36:44 +02:00
|
|
|
IPFS_ARCH=arm
|
|
|
|
fi
|
|
|
|
if [ ! $IPFS_ARCH ]; then
|
2016-09-29 11:16:52 +02:00
|
|
|
echo $'No architecture specified'
|
|
|
|
ARCHITECTURE=$(uname -m)
|
2017-09-18 16:27:11 +02:00
|
|
|
if [[ $ARCHITECTURE == "arm"* || $ARCHITECTURE == *"aarch"* ]]; then
|
2016-09-29 11:16:52 +02:00
|
|
|
IPFS_ARCH=arm
|
2017-06-16 16:46:51 +02:00
|
|
|
echo $"Using $IPFS_ARCH"
|
2016-09-29 11:16:52 +02:00
|
|
|
fi
|
|
|
|
if [[ $ARCHITECTURE == "amd"* || $ARCHITECTURE == "x86_64" ]]; then
|
|
|
|
IPFS_ARCH=amd64
|
2017-06-16 16:46:51 +02:00
|
|
|
echo $"Using $IPFS_ARCH"
|
2016-09-29 11:16:52 +02:00
|
|
|
fi
|
|
|
|
if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
|
|
|
|
IPFS_ARCH=386
|
2017-06-16 16:46:51 +02:00
|
|
|
echo $"Using $IPFS_ARCH"
|
2016-09-29 11:16:52 +02:00
|
|
|
fi
|
2016-09-03 16:36:44 +02:00
|
|
|
fi
|
2017-09-18 16:21:27 +02:00
|
|
|
if [ ! $IPFS_ARCH ]; then
|
|
|
|
echo $'Architecture not detected for IPFS install'
|
|
|
|
exit 738765235
|
|
|
|
fi
|
2016-09-02 18:17:44 +02:00
|
|
|
|
2016-09-03 16:36:44 +02:00
|
|
|
IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
|
|
|
|
wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE}
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -f "$rootdir$INSTALL_DIR/ipfs/${IPFS_FILE}" ]; then
|
2016-09-03 16:36:44 +02:00
|
|
|
echo $'IPFS package could not be downloaded'
|
|
|
|
exit 63725
|
|
|
|
fi
|
|
|
|
tar -xzvf ${IPFS_FILE}
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -f "$rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs" ]; then
|
2016-09-03 16:36:44 +02:00
|
|
|
echo $"ipfs was not found in downloaded package"
|
|
|
|
exit 638235
|
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
chroot "$rootdir" /bin/cp "$INSTALL_DIR/ipfs/go-ipfs/ipfs" $IPFS_PATH
|
|
|
|
if [ ! -f "$rootdir$IPFS_PATH/ipfs" ]; then
|
2016-09-03 16:36:44 +02:00
|
|
|
echo $'IPFS was not installed'
|
|
|
|
exit 63722
|
2016-08-14 23:04:34 +02:00
|
|
|
fi
|
|
|
|
|
2016-09-03 18:03:23 +02:00
|
|
|
IPFS_USER_DAEMON=${rootdir}/home/${MY_USERNAME}/.config/systemd/user/ipfs.service
|
2018-02-27 15:11:56 +01:00
|
|
|
mkdir -p "${rootdir}/home/${MY_USERNAME}/.config/systemd/user"
|
|
|
|
|
|
|
|
{ echo '[Unit]';
|
|
|
|
echo 'Description=IPFS go daemon';
|
|
|
|
echo 'After=syslog.target';
|
|
|
|
echo 'After=network.target';
|
|
|
|
echo '';
|
|
|
|
echo '[Service]';
|
|
|
|
echo 'Type=simple';
|
|
|
|
echo "ExecStart=$IPFS_PATH/ipfs daemon";
|
|
|
|
echo 'Restart=on-failure';
|
|
|
|
echo 'RestartSec=60';
|
|
|
|
echo '';
|
|
|
|
echo '[Install]';
|
|
|
|
echo 'WantedBy=default.target'; } > "$IPFS_USER_DAEMON"
|
|
|
|
chroot "${rootdir}" /bin/chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/${MY_USERNAME}/.config"
|
2016-08-14 23:04:34 +02:00
|
|
|
}
|
2016-08-12 10:19:09 +02:00
|
|
|
|
|
|
|
function install_ipfs_go {
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ "$INSTALLING_MESH" ]; then
|
2016-08-14 23:04:34 +02:00
|
|
|
mesh_install_ipfs_go
|
|
|
|
return
|
|
|
|
fi
|
2016-09-30 17:00:45 +02:00
|
|
|
if [[ $(app_is_installed ipfs_go) == "1" ]]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-10-23 20:38:14 +02:00
|
|
|
apt-get -yq install golang libpam0g-dev fuse
|
2016-08-12 10:19:09 +02:00
|
|
|
|
|
|
|
if [ ! -d /home/git ]; then
|
|
|
|
# add a gogs user account
|
|
|
|
adduser --disabled-login --gecos 'Gogs' git
|
2017-06-10 19:34:45 +02:00
|
|
|
if [ ! -d /home/git ]; then
|
|
|
|
echo $"/home/git directory not created"
|
|
|
|
exit 735272
|
|
|
|
fi
|
2016-08-12 10:19:09 +02:00
|
|
|
|
|
|
|
# install Go
|
|
|
|
if ! grep -q "export GOPATH=" ~/.bashrc; then
|
|
|
|
echo "export GOPATH=$GOPATH" >> ~/.bashrc
|
|
|
|
else
|
|
|
|
sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
|
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
systemctl set-environment GOPATH="$GOPATH"
|
2016-08-12 10:19:09 +02:00
|
|
|
if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
|
|
|
|
echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
|
|
|
|
else
|
|
|
|
sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
|
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -d "$GOPATH" ]; then
|
|
|
|
mkdir -p "$GOPATH"
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
IPFS_PATH=$GOPATH/bin
|
|
|
|
export PATH="$GOPATH/bin:$PATH:"
|
|
|
|
if ! grep -q 'GOPATH/bin' ~/.bashrc; then
|
2018-02-27 15:11:56 +01:00
|
|
|
echo "export PATH=\"\$GOPATH/bin:\$PATH:\";" >> ~/.bashrc
|
2016-08-12 10:19:09 +02:00
|
|
|
else
|
|
|
|
sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set gopath for the user
|
2018-02-27 15:11:56 +01:00
|
|
|
if ! grep -q "GOPATH=" "/home/$MY_USERNAME/.bashrc"; then
|
|
|
|
echo "export GOPATH=$GOPATH" >> "/home/$MY_USERNAME/.bashrc"
|
|
|
|
echo "export PATH=\"\$GOPATH/bin:\$PATH:\";" >> "/home/$MY_USERNAME/.bashrc"
|
2016-08-12 10:19:09 +02:00
|
|
|
else
|
2018-02-27 15:11:56 +01:00
|
|
|
sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" "/home/$MY_USERNAME/.bashrc"
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.bashrc"
|
2016-08-12 10:19:09 +02:00
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if ! go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs; then
|
2016-08-12 10:19:09 +02:00
|
|
|
exit 8242
|
|
|
|
fi
|
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if [ ! -d "$GOPATH/src/$IPFS_GO_REPO_BASE" ]; then
|
2016-08-15 08:56:52 +02:00
|
|
|
echo $'go get failed to get ipfs'
|
|
|
|
exit 63923
|
|
|
|
fi
|
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
cd "$GOPATH/src/$IPFS_GO_REPO_BASE" || exit 346824
|
|
|
|
if ! git checkout $IPFS_COMMIT -b $IPFS_COMMIT; then
|
2016-08-15 09:42:10 +02:00
|
|
|
exit 735639
|
|
|
|
fi
|
|
|
|
|
2016-10-16 20:50:56 +02:00
|
|
|
set_completion_param "ipfs commit" "$IPFS_COMMIT"
|
2016-08-12 10:19:09 +02:00
|
|
|
|
2018-02-27 15:11:56 +01:00
|
|
|
if ! make install; then
|
2016-09-02 18:17:44 +02:00
|
|
|
exit 547242
|
|
|
|
fi
|
|
|
|
|
2016-08-12 10:19:09 +02:00
|
|
|
# initialise
|
2018-02-27 15:11:56 +01:00
|
|
|
chmod 755 "$IPFS_PATH/ipfs"
|
|
|
|
su -c "$IPFS_PATH/ipfs init -b 2048" - "$MY_USERNAME"
|
|
|
|
if [ ! -d "/home/$MY_USERNAME/.ipfs" ]; then
|
2016-08-12 10:19:09 +02:00
|
|
|
echo "IPFS could not be initialised for user $MY_USERNAME"
|
|
|
|
exit 7358
|
|
|
|
fi
|
|
|
|
|
|
|
|
# directories to mount to
|
|
|
|
if [ ! -d /ipfs ]; then
|
|
|
|
mkdir /ipfs
|
|
|
|
mkdir /ipns
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /ipfs
|
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /ipns
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/fuse.conf ]; then
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /etc/fuse.conf
|
2016-08-12 10:19:09 +02:00
|
|
|
fi
|
|
|
|
if [ -f /dev/fuse ]; then
|
2018-02-27 15:11:56 +01:00
|
|
|
chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
|
|
|
|
fi
|
|
|
|
|
|
|
|
{ echo '[Unit]';
|
|
|
|
echo 'Description=IPFS go daemon';
|
|
|
|
echo 'After=syslog.target';
|
|
|
|
echo 'After=network.target';
|
|
|
|
echo '';
|
|
|
|
echo '[Service]';
|
|
|
|
echo 'Type=simple';
|
|
|
|
echo "User=$MY_USERNAME";
|
|
|
|
echo "Group=$MY_USERNAME";
|
|
|
|
echo "WorkingDirectory=/home/$MY_USERNAME";
|
|
|
|
echo "ExecStart=$IPFS_PATH/ipfs daemon --mount";
|
|
|
|
echo 'Restart=on-failure';
|
|
|
|
echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"";
|
|
|
|
echo '';
|
|
|
|
echo '[Install]';
|
|
|
|
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/ipfs.service
|
2016-08-12 10:19:09 +02:00
|
|
|
|
|
|
|
systemctl enable ipfs
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl restart ipfs
|
|
|
|
|
|
|
|
if [ -d /etc/avahi ]; then
|
2018-03-02 20:52:07 +01:00
|
|
|
su -c "echo $("$IPFS_PATH/ipfs" id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - "$MY_USERNAME"
|
2016-08-12 10:19:09 +02:00
|
|
|
if [ ! -f /tmp/ipfsid ]; then
|
|
|
|
echo 'No IPFS identity was created'
|
|
|
|
exit 37895
|
|
|
|
fi
|
|
|
|
IPFS_PEER_ID=$(cat /tmp/ipfsid)
|
|
|
|
if [ ${#IPFS_PEER_ID} -lt 10 ]; then
|
|
|
|
echo 'Invalid IPFS peer ID'
|
|
|
|
echo "$IPFS_PEER_ID"
|
|
|
|
exit 74782
|
|
|
|
fi
|
|
|
|
# Add an avahi service
|
|
|
|
function_check create_avahi_service
|
2016-09-07 23:47:01 +02:00
|
|
|
create_avahi_service ipfs_id "ipfs_id" 'udp' $IPFS_PORT "$IPFS_PEER_ID:none"
|
2016-08-12 10:19:09 +02:00
|
|
|
rm /tmp/ipfsid
|
|
|
|
fi
|
|
|
|
|
|
|
|
function_check configure_firewall_for_ipfs
|
|
|
|
configure_firewall_for_ipfs
|
|
|
|
|
2016-09-30 17:00:45 +02:00
|
|
|
install_completed ipfs_go
|
2016-07-03 19:52:57 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 17:13:34 +02:00
|
|
|
function install_ipfs {
|
2016-08-14 23:04:34 +02:00
|
|
|
#install_ipfs_js
|
|
|
|
install_ipfs_go
|
2016-10-10 20:11:33 +02:00
|
|
|
APP_INSTALLED=1
|
2016-07-03 17:13:34 +02:00
|
|
|
}
|