ipfs tweaks

This commit is contained in:
Bob Mottram 2016-09-04 10:55:24 +01:00
parent 1c0c2a3031
commit e0fbc044b3
2 changed files with 39 additions and 1 deletions

View File

@ -78,6 +78,32 @@ TOX_USERS_FILE=$ZERONET_INSTALL/${PROJECT_NAME}-tox-users.html
# whether to enable zeronet
ENABLE_ZERONET=
function create_avahi_service {
service_name=$1
service_type=$2
service_protocol=$3
service_port=$4
service_description="$5"
if [ ! -d /etc/avahi ]; then
echo $'create_avahi_service: avahi was not installed'
exit 52925
fi
echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /etc/avahi/services/${service_name}.service
echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /etc/avahi/services/${service_name}.service
echo '<service-group>' >> /etc/avahi/services/${service_name}.service
echo " <name replace-wildcards=\"yes\">%h ${service_type}</name>" >> /etc/avahi/services/${service_name}.service
echo ' <service>' >> /etc/avahi/services/${service_name}.service
echo " <type>_${service_type}._${service_protocol}</type>" >> /etc/avahi/services/${service_name}.service
echo " <port>${service_port}</port>" >> /etc/avahi/services/${service_name}.service
if [ "$service_description" ]; then
echo " <txt-record>$service_description</txt-record>" >> /tmp/zeronet-blog.service
fi
echo ' </service>' >> /etc/avahi/services/${service_name}.service
echo '</service-group>' >> /etc/avahi/services/${service_name}.service
}
function create_ram_disk {
ramdisk_size_mb=$1
if [ ! -d /mnt/ramdisk ]; then
@ -737,6 +763,10 @@ function setup_ipfs {
rm -f /home/$MY_USERNAME/.ipfs-id
fi
if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
rm -f /home/$MY_USERNAME/.ipfs-users
fi
su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
echo "IPFS could not be initialised for user $MY_USERNAME" >> $INSTALL_LOG
@ -757,6 +787,9 @@ function setup_ipfs {
return
fi
TOX_ID=$(su -c 'toxid' - $MY_USERNAME)
create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID:$TOX_ID"
echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
}

View File

@ -54,6 +54,7 @@ ZERONET_CONFIG=$ZERONET_INSTALL/bootstrap
IPFS_PORT=4001
IPFS_PATH=/usr/bin
IPFS_COMMAND=$IPFS_PATH/ipfs
IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users
MY_BLOG_STR=$"My Blog"
MY_MAIL_STR=$"My Mail"
@ -89,11 +90,15 @@ function ipfs_bootstrap {
state=0
address=""
peer=""
echo -n '' > $IPFS_USERS_FILE
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ ${state} -eq "3" ]; then
if [[ $line == *"txt ="* ]]; then
ipfs_peer_id=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}' | awk -F '"' '{print $2}')
ipfs_txt=$(echo "$line" | awk -F '[' '{print $2}' | awk -F ']' '{print $1}' | awk -F '"' '{print $2}')
ipfs_peer_id=$(echo "$ipfs_txt" | awk -F ':' '{print $1}')
ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}')
$IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id}
echo "$ipfs_tox_id $ipfs_peer_id" >> $IPFS_USERS_FILE
state=0
fi
fi