Add start-ipfs-server.sh

This commit is contained in:
Markus Fleschutz 2021-06-24 11:39:48 +02:00
parent df0f871ded
commit fecca0ae82
4 changed files with 45 additions and 24 deletions

View File

@ -181,6 +181,7 @@ speak-joke.ps1, speaks the next joke by text-to-speech (TTS)
speak-test.ps1, performs a speak test by text-to-speech (TTS)
speak-text.ps1, speaks the given text by text-to-speech (TTS)
speak-time.ps1, speaks the current time by text-to-speech (TTS)
start-ipfs-server.ps1, starts a local IPFS server
switch-branch.ps1, switches the branch in the current/given Git repository (including submodules)
switch-shelly1.ps1, switches a Shelly1 device in the local network
sync-repo.ps1, synchronizes a Git repository by push & pull (including submodules)

1 Script Description
181 speak-test.ps1 performs a speak test by text-to-speech (TTS)
182 speak-text.ps1 speaks the given text by text-to-speech (TTS)
183 speak-time.ps1 speaks the current time by text-to-speech (TTS)
184 start-ipfs-server.ps1 starts a local IPFS server
185 switch-branch.ps1 switches the branch in the current/given Git repository (including submodules)
186 switch-shelly1.ps1 switches a Shelly1 device in the local network
187 sync-repo.ps1 synchronizes a Git repository by push & pull (including submodules)

View File

@ -218,6 +218,7 @@ Mega Collection of PowerShell Scripts
* [set-timer.ps1](Scripts/set-timer.ps1) - sets a timer for a countdown
* [simulate-matrix.ps1](Scripts/simulate-matrix.ps1) - simulates the Matrix (fun)
* [simulate-presence.ps1](Scripts/simulate-presence.ps1) - simulates the human presence against burglars
* [start-ipfs-server.ps1](Scripts/start-ipfs-server.ps1) - starts a local IPFS server
* [switch-shelly1.ps1](Scripts/switch-shelly1.ps1) - switches a Shelly1 device in the local network
* [translate-file.ps1](Scripts/translate-file.ps1) - translates the given text file into other languages
* [translate-files.ps1](Scripts/translate-files.ps1) - translates the given text files into any supported language

View File

@ -1,24 +0,0 @@
#!/bin/sh
# Syntax: ./ipfs-server
# Description: starts an IPFS server
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
HOSTNAME="`hostname`"
ipfs init --profile server
ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8765
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://raspi:5001", "http://127.0.0.1:5001", "https://webui.ipfs.io"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
echo "NOTE: Make sure port 4001 for IPv4/v6 is open by your router!"
while true; do
ipfs daemon
echo "IPFS server has stopped, restarting ..."
sleep 1
done
exit 0

43
Scripts/start-ipfs-server.ps1 Executable file
View File

@ -0,0 +1,43 @@
<#
.SYNTAX start-ipfs-server.ps1
.DESCRIPTION starts a local IPFS server
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
try {
$Result = (ipfs --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'ipfs' - make sure IPFS is installed and available" }
"Step 1/4: initializing IPFS..."
& ipfs init --profile server
"Step 2/4: configuring IPFS..."
& ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
if ($lastExitCode -ne "0") { throw "'ipfs config Addresses.API' failed" }
& ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8765
if ($lastExitCode -ne "0") { throw "'ipfs config Addresses.Gateway' failed" }
# & ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://raspi:5001", "http://127.0.0.1:5001", "https://webui.ipfs.io"]'
# if ($lastExitCode -ne "0") { throw "'ipfs config Access-Control-Allow-Origin' failed" }
# & ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
# if ($lastExitCode -ne "0") { throw "'ipfs config Access-Control-Allow-Methods' failed" }
"Step 3/4: increasing UDP receive buffer size..."
& sudo sysctl -w net.core.rmem_max=2500000
if ($lastExitCode -ne "0") { throw "'sysctl' failed" }
"Step 4/4: starting IPFS daemon..."
"NOTE: make sure your router does not block port 4001 (TCP/UDP) for IPv4/v6!"
& ipfs daemon
if ($lastExitCode -ne "0") { throw "'ipfs daemon' failed" }
"IPFS server has stopped"
exit 1
} catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}