diff --git a/ipfs4astroport.sh b/ipfs4astroport.sh new file mode 100755 index 0000000..0497177 --- /dev/null +++ b/ipfs4astroport.sh @@ -0,0 +1,229 @@ +#!/bin/bash +######################################################################## +{ # this ensures the entire script is downloaded # +MY_PATH="`dirname \"$0\"`" # relative +MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized +ME="${0##*/}" + +# CHECK not root user !! +if [ "$EUID" -eq 0 ] + then echo -e "DO NOT EXECUTE AS root. Choose a user for your Astroport Station (we like pi)" + exit 1 +else echo -e "OK $USER, let's go!"; +fi + +# Ask user password on start +sudo true + +## Error funciton +err() { + echo -e "ERREUR: $1" + exit 1 +} + +# CHECK if daemon is already running +if [[ $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ]]; then + ipfs id && echo "ipfs swarm peers: " && ipfs swarm peers + echo "ipfs bootstrap list: " && ipfs bootstrap list + echo "ipfs daemon already running...! Must STOP ipfs AND remove ~/.ipfs to install again !!" + echo "Please RUN : sudo service ipfs stop" + exit 1 +fi + +[[ -d ~/.ipfs ]] && echo "IPFS install exist! Please remove or backup before executing this script EXIT" && exit 1 + +echo -e "Astroport IPFS Layer installation..." + +[[ $(which pip3) ]] && sudo pip3 install duniterpy || (echo "python3 pip3 is missing on your device. EXIT" && exit 1) +[[ ! $(which curl) ]] && sudo apt-get install curl -y +[[ ! $(which git) ]] && sudo apt-get install git -y + +[[ ! -d ~/.zen ]] && mkdir ~/.zen + +# CHECK node IP isLAN? +myIP=$(hostname -I | awk '{print $1}') +isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") + +MACHINE_TYPE=`uname -m` + +if [ ${MACHINE_TYPE} == 'x86_64' ]; then + curl -s https://dist.ipfs.io/ipfs-update/v1.6.0/ipfs-update_v1.6.0_linux-amd64.tar.gz -o $MY_PATH/ipfs-update.tar.gz +elif [ ${MACHINE_TYPE:0:3} == 'arm' ]; then + curl -s https://dist.ipfs.io/ipfs-update/v1.6.0/ipfs-update_v1.6.0_linux-arm.tar.gz -o $MY_PATH/ipfs-update.tar.gz +elif [ ${MACHINE_TYPE} == 'aarch64' ]; then + curl -s https://dist.ipfs.io/go-ipfs/v0.9.1/go-ipfs_v0.9.1_linux-arm64.tar.gz -o /tmp/ipfs_aarch64_v0.9.1.tar.gz +else + echo "Your $MACHINE_TYPE is not supported yet... Please add an issue." && exit 1 +fi + +if [ -f $MY_PATH/ipfs-update.tar.gz ]; then + echo "INSTALL ipfs-update >>>>>>>>>>>>>>>>>>>>>>>>>>" + sudo tar -xvzf $MY_PATH/ipfs-update.tar.gz -C /usr/src/ || err "Untar ipfs-update" + rm $MY_PATH/ipfs-update.tar.gz + cd /usr/src/ipfs-update/ + sudo ./install.sh || err "Install ipfs-update" + cd $MY_PATH + + echo "INSTALL ipfs 0.9.1 >>>>>>>>>>>>>>>>>>>>>>>>>>" + sudo ipfs-update install 0.9.1 || err "Install IPFS" + +else + ## TERRAPI4 aarch64 install ipfs_aarch64_v0.9.1 + sudo tar -xvzf /tmp/ipfs_aarch64_v0.9.1.tar.gz -C /usr/src/ || err "Untar ipfs_aarch64" + rm /tmp/ipfs_aarch64_v0.9.1.tar.gz + cd /usr/src/go-ipfs/ + sudo ./install.sh || err "Install ipfs_aarch64" + cd $MY_PATH + +fi + +# INIT ipfs +[[ $isLAN ]] && ipfs init -p lowpower \ +|| ipfs init -p server + +## Special Xbian init.d config +if [[ "$USER" == "xbian" ]]; then + sudo cp ~/.zen/astrXbian/.install/templates/ipfs/ipfs-initV.sh /etc/init.d/ipfs + sudo chmod 755 /etc/init.d/ipfs + sudo touch /var/log/ipfs.log && sudo chown xbian /var/log/ipfs.log +else + ## DEBIAN SYSTEMCTL + echo "CREATE SYSTEMD ipfs SERVICE >>>>>>>>>>>>>>>>>>" +cat > /tmp/ipfs.service <>>>>>>>>>>>>>>>>> " +# echo "Vous pouvez régler la ressouce CPU maximum (60%)?" && read cpuy + + [[ -d ~/.ipfs ]] && sudo chown -R $USER:$USER ~/.ipfs + sudo systemctl daemon-reload + sudo systemctl enable ipfs +fi + + +########################################### +# ACTIVATE IPFS OPTIONS: #swarm0 INIT +########################################### +### IMPORTANT !!!!!!! IMPORTANT !!!!!! +########################################### +# DHT PUBSUB mode +ipfs config Pubsub.Router gossipsub +# MAXSTORAGE = 1/2 available +availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}') +diskSize="$((availableDiskSize / 2))" +ipfs config Datastore.StorageMax $diskSize +## Activate Rapid "ipfs p2p" +ipfs config --json Experimental.Libp2pStreamMounting true +ipfs config --json Experimental.P2pHttpProxy true +ipfs config --json Swarm.ConnMgr.LowWater 0 +ipfs config --json Swarm.ConnMgr.HighWater 0 + +## Install gateway on 8181 port +ipfs config Addresses.Gateway "/ip4/127.0.0.1/tcp/8181" + +######### CLEAN DEFAULT BOOTSTRAP TO STAY INVISIBLE ########### +# ipfs bootstrap rm --all +## get code from https://tube.copylaradio.com/ipfs/ + +########################################### +# BOOTSTRAP NODES ARE ADDED LATER +########################################### +## Declare directory transfered in IPFS +IPFS_sync_directory="$HOME/astroport" +mkdir -p $IPFS_sync_directory + +######################################################################## +# INSTALL KEYS +######################################################################## +IPFSNODEID=$(ipfs config Identity.PeerID) + +######################################################################## +echo "INIT ~/.zen/ipfs/.${IPFSNODEID} INDEX" +######################################################################## +rm -Rf ~/.zen/ipfs +mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/G1SSB +######################################################################## +# Give $XZUID to your (gchange friends) +######################################################################## +echo "SETTING ASTRXBIAN PROFILE NAME = $XZUID" +echo "$XZUID" > ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid + +######################################################################## +######################################################################## +echo "Getting tryme.addr & .mycode from OASIS +-- Change oasis address to fork Astroport Code Universe --" +######################################################################## +ipfs bootstrap rm --all + +OASIS=12D3KooWBYme2BsNUrtx4mEdNX6Yioa9AV7opWzQp6nrPs6ZKabN +# aries=12D3KooWSQYTxeoZZ39SNosEKxi7RUdGTtAQAqpKeZJxjzqqrZTx +for bootnode in $(curl https://tube.copylaradio.com/ipns/$OASIS/.$OASIS/tryme.addr) +do + ## ADD $bootnode TO BOOTSTRAP + ipfs bootstrap add $bootnode +done + +codesign=$(curl https://tube.copylaradio.com/ipns/$OASIS/.$OASIS/.mycode) +######################################################################## +echo "RESTARTING ipfs" +######################################################################## +sudo service ipfs restart +echo ".... WAIT for SWARM to connect ..." +sleep 10 + +echo ".... ACTUAL SWARM PEERS ..." +ipfs swarm peers + +echo "Station IPFS OK + +astrXbian $codesign INSTALL OK +Activation ~/.zen/astrXbian/zen/cron_VRFY.sh +" +mkdir -p /home/$USER/.zen/astrXbian/ +ipfs get --output=/home/$USER/.zen/astrXbian/ /ipfs/$codesign + +######################################################################## +# SUDO permissions +######################################################################## +## USED FOR fail2ban-client (DEFCON) +echo "$USER ALL=(ALL) NOPASSWD:/usr/bin/fail2ban-client" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/fail2ban-client') +## USED FOR RAMDISK (video live streaming) +echo "$USER ALL=(ALL) NOPASSWD:/bin/mount" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/mount') +echo "$USER ALL=(ALL) NOPASSWD:/bin/umount" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/umount') +## USED FOR SYSTEM UPGRADE +echo "$USER ALL=(ALL) NOPASSWD:/usr/bin/apt-get" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/apt-get') +echo "$USER ALL=(ALL) NOPASSWD:/usr/bin/apt" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/apt') +## USED FOR "systemctl restart ipfs" +echo "$USER ALL=(ALL) NOPASSWD:/bin/systemctl" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/systemctl') + +## INSTALL TiddlyWiki +[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/index.html ]] && mkdir -p ~/.zen/ipfs/.${IPFSNODEID} && cp ~/.zen/astrXbian/.install/templates/tiddlywiki/index.html ~/.zen/ipfs/.${IPFSNODEID}/index.html + + +echo "OK. + +Ajoutez le compagnon IFPS à votre navigateur. + +Documentation : https://docs.ipfs.io/install/ipfs-companion/ +Traduction FR : https://translate.google.com/translate?sl=auto&tl=fr&u=https://docs.ipfs.io/install/ipfs-companion/ +" + +## OPEN https://translate.google.com/translate?sl=auto&tl=fr&u=https://docs.ipfs.io/install/ipfs-companion/ + +} # this ensures the entire script is downloaded # +# IPFS CONFIG documentation: https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#addressesswarm