ipfs sites list

This commit is contained in:
Bob Mottram 2016-09-04 16:12:12 +01:00
parent e0fbc044b3
commit 045453e9ec
2 changed files with 78 additions and 5 deletions

View File

@ -751,20 +751,30 @@ function setup_ipfs {
IPFS_PATH=/usr/bin IPFS_PATH=/usr/bin
IPFS_KEY_LENGTH=2048 IPFS_KEY_LENGTH=2048
IPFS_COMMAND=$IPFS_PATH/ipfs IPFS_COMMAND=$IPFS_PATH/ipfs
IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
su -c "systemctl --user enable ipfs" - $MY_USERNAME su -c "systemctl --user enable ipfs" - $MY_USERNAME
su -c "systemctl --user start ipfs" - $MY_USERNAME su -c "systemctl --user start ipfs" - $MY_USERNAME
if [ -d /home/$MY_USERNAME/Public ]; then
rm -rf /home/$MY_USERNAME/Public
fi
if [ -d /home/$MY_USERNAME/.ipfs ]; then if [ -d /home/$MY_USERNAME/.ipfs ]; then
shred -zu /home/$MY_USERNAME/.ipfs/config
rm -rf /home/$MY_USERNAME/.ipfs rm -rf /home/$MY_USERNAME/.ipfs
fi fi
if [ -f /home/$MY_USERNAME/.ipfs-id ]; then if [ -f /home/$MY_USERNAME/.ipfs-id ]; then
rm -f /home/$MY_USERNAME/.ipfs-id shred -zu /home/$MY_USERNAME/.ipfs-id
fi
if [ -f /home/$MY_USERNAME/.ipfs-public ]; then
shred -zu /home/$MY_USERNAME/.ipfs-public
fi fi
if [ -f /home/$MY_USERNAME/.ipfs-users ]; then if [ -f /home/$MY_USERNAME/.ipfs-users ]; then
rm -f /home/$MY_USERNAME/.ipfs-users shred -zu /home/$MY_USERNAME/.ipfs-users
fi fi
su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME su -c "$IPFS_COMMAND init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
@ -787,8 +797,21 @@ function setup_ipfs {
return return
fi fi
# make a public directory
if [ -d /home/$MY_USERNAME/Desktop ]; then
if [ ! -d /home/$MY_USERNAME/Public ]; then
mkdir /home/$MY_USERNAME/Public
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
su -c "echo \$($IPFS_COMMAND add -rq /home/$MY_USERNAME/Public | tail -n 1) > $IPFS_PUBLIC" - $MY_USERNAME
if [ ! -f $IPFS_PUBLIC ]; then
echo $'Unable to create public IPFS directory' >> $INSTALL_LOG
exit 368225
fi
fi
fi
TOX_ID=$(su -c 'toxid' - $MY_USERNAME) TOX_ID=$(su -c 'toxid' - $MY_USERNAME)
create_avahi_service ipfs "ipfs" udp $IPFS_PORT "$IPFS_PEER_ID:$TOX_ID" create_avahi_service ipfs "ipfs" udp $IPFS_PORT "${IPFS_PEER_ID}:${TOX_ID}"
echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG echo 'IPFS installed with ID $IPFS_PEER_ID' >> $INSTALL_LOG
} }

View File

@ -55,6 +55,8 @@ IPFS_PORT=4001
IPFS_PATH=/usr/bin IPFS_PATH=/usr/bin
IPFS_COMMAND=$IPFS_PATH/ipfs IPFS_COMMAND=$IPFS_PATH/ipfs
IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users IPFS_USERS_FILE=/home/$MY_USERNAME/.ipfs-users
IPFS_PUBLIC=/home/$MY_USERNAME/.ipfs-public
IPFS_URL='http://127.0.0.1:8080/ipns'
MY_BLOG_STR=$"My Blog" MY_BLOG_STR=$"My Blog"
MY_MAIL_STR=$"My Mail" MY_MAIL_STR=$"My Mail"
@ -84,13 +86,45 @@ TEMPFILE=$(mktemp /tmp/zeronetavahi.XXXXXX)
# List of tox users previously seen # List of tox users previously seen
PREV_TOX_USERS_FILE=/root/.prev_tox_users PREV_TOX_USERS_FILE=/root/.prev_tox_users
function ipfs_publish {
# Publishes anything within the ~/Public directory
DIR_TO_CHECK=/home/$MY_USERNAME/Public
if [ ! -d $DIR_TO_CHECK ]; then
return
fi
OLD_STAT_FILE=/home/$MY_USERNAME/.old_stat.txt
if [ -e $OLD_STAT_FILE ]
then
OLD_STAT=$(cat $OLD_STAT_FILE)
else
OLD_STAT="nothing"
fi
NEW_STAT=$(stat -t $DIR_TO_CHECK)
if [ "$OLD_STAT" != "$NEW_STAT" ]; then
su -c "echo \$($IPFS_COMMAND add -rq /home/$MY_USERNAME/Public | tail -n 1) > $IPFS_PUBLIC" - $MY_USERNAME
echo $NEW_STAT > $OLD_STAT_FILE
fi
if [ -f $IPFS_PUBLIC ]; then
IPFS_PUBLIC_ID=$(cat $IPFS_PUBLIC)
su -c "$IPFS_COMMAND name publish /ipfs/$IPFS_PUBLIC_ID" - $MY_USERNAME
fi
}
function ipfs_bootstrap { function ipfs_bootstrap {
cat $TEMPFILE_BASE | grep "IPFS\|hostname =\|address =\|port =\|txt =" > $TEMPFILE cat $TEMPFILE_BASE | grep "IPFS\|hostname =\|address =\|port =\|txt =" > $TEMPFILE
state=0 state=0
address="" address=""
peer="" peer=""
echo -n '' > $IPFS_USERS_FILE if [ -d /home/$MY_USERNAME/Desktop ]; then
echo -n '' > ${IPFS_USERS_FILE}.new
fi
while IFS='' read -r line || [[ -n "$line" ]]; do while IFS='' read -r line || [[ -n "$line" ]]; do
if [ ${state} -eq "3" ]; then if [ ${state} -eq "3" ]; then
if [[ $line == *"txt ="* ]]; then if [[ $line == *"txt ="* ]]; then
@ -98,7 +132,12 @@ function ipfs_bootstrap {
ipfs_peer_id=$(echo "$ipfs_txt" | awk -F ':' '{print $1}') ipfs_peer_id=$(echo "$ipfs_txt" | awk -F ':' '{print $1}')
ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}') ipfs_tox_id=$(echo "$ipfs_txt" | awk -F ':' '{print $2}')
$IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id} $IPFS_COMMAND bootstrap add /ip4/${address}/tcp/${IPFS_PORT}/ipfs/${ipfs_peer_id}
echo "$ipfs_tox_id $ipfs_peer_id" >> $IPFS_USERS_FILE if [ -d /home/$MY_USERNAME/Desktop ]; then
if grep -q "$ipfs_tox_id" $TOX_USERS_FILE; then
ipfs_tox_nick=$(cat $TOX_USERS_FILE | grep $ipfs_tox_id | awk -F ' ' '{print $1}')
echo "$ipfs_tox_nick:${IPFS_URL}/$ipfs_peer_id" >> ${IPFS_USERS_FILE}.new
fi
fi
state=0 state=0
fi fi
fi fi
@ -118,6 +157,16 @@ function ipfs_bootstrap {
state=1 state=1
fi fi
done < "$TEMPFILE" done < "$TEMPFILE"
# Create a list of user sites, in alphabetical order by Tox nick
if [ -d /home/$MY_USERNAME/Desktop ]; then
if [ -f ${IPFS_USERS_FILE}.new ]; then
sites_list=$(cat ${IPFS_USERS_FILE}.new | sort -d)
echo "${sites_list}" > ${IPFS_USERS_FILE}
chown $MY_USERNAME:$MY_USERNAME ${IPFS_USERS_FILE}
rm ${IPFS_USERS_FILE}.new
fi
fi
} }
function detect_new_tox_users { function detect_new_tox_users {
@ -506,6 +555,7 @@ fi
avahi_ipfs avahi_ipfs
ipfs_bootstrap ipfs_bootstrap
ipfs_publish
#detect_tox_users #detect_tox_users
avahi_remove_info avahi_remove_info