Setting up IPFS with IPFS-Update on a Raspberry Pi
Setting up IPFS-Update
I use my notes every now and then to setup IPFS on a Raspberry Pi, so I thought that I'd share them here!
We will be using IPFS-Update to install the latest version of IPFS.
First, download and install ipfs-update version 1.5.2 with the following commands:
wget https://dist.ipfs.io/ipfs-update/v1.5.2/ipfs-update_v1.5.2_linux-arm.tar.gz
sudo tar xvfz ipfs-update_v1.5.2_linux-arm.tar.gz
cd ipfs-update/
sudo ./install.sh
Now we will install the latest version of IPFS.
sudo ipfs-update install latest
You can also run this command periodically to ensure that IPFS is up to date.
If there are issues with an update you can revert to the previously installed version of IPFS with command:
sudo ipfs-update revert
Setting up IPFS
Initialise IPFS.
ipfs init
Install screen.
sudo apt-get update && sudo apt-get install screen -y
Create a script.
nano check_ipfs.sh
The nano text editor will open a blank file, paste in the below code.
if !(screen -list | grep -q ipfs)
then
echo "Starting.."
screen -dmS ipfs sh -c 'ipfs daemon'
else
echo "Already running.."
fi
Save and close the file with CTRL+X, 'Y' and then 'Enter'.
This code will check if our 'ipfs' screen is currently running, and if it isn't then it will be create it.
Make the file executable with:
chmod +x /home/pi/check_ipfs.sh
Edit crontab with:
crontab -e
You will be prompted to choose a default editor on the first time running crontab.
Choose '2', for nano, and then press enter.
When nano has opened crontab for editing, paste the following lines at the end of the file:
PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
* * * * * /home/pi/ipfs_check_and_restart.sh
Save and close the file with CTRL+X, 'Y' and then 'Enter'.
Our script will now run every 1 minute.
Now to launch the IPFS daemon, either wait 1 minute or run the script:
/home/pi/check_ipfs.sh
Setup complete
Now that IPFS is setup and running, we can add a file and test that it's working.
echo "Test text file" > test.txt
ipfs add test.txt
If it completed successfully you should see this output:
added QmWuvsvCHYta1BJLQFaKfQGWNbByNuPTuQijo8QUpqZi2j test.txt
You can now retrieve this file through any IPFS node by using the previous command output hash with the below command.
ipfs cat QmWuvsvCHYta1BJLQFaKfQGWNbByNuPTuQijo8QUpqZi2j
Congratulations @vexl! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!