2024-10-01 15:24:16 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2021-12-28 10:30:52 +01:00
|
|
|
|
Start an IPFS server
|
2021-10-04 21:29:23 +02:00
|
|
|
|
.DESCRIPTION
|
2021-12-28 10:30:52 +01:00
|
|
|
|
This PowerShell script starts a local IPFS server as a daemon process.
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2021-09-27 08:35:45 +02:00
|
|
|
|
PS> ./start-ipfs-server
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-30 10:49:30 +01:00
|
|
|
|
.NOTES
|
2022-06-09 09:42:13 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-06-24 11:39:48 +02:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
try {
|
2021-08-31 10:32:20 +02:00
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
2021-06-24 11:49:59 +02:00
|
|
|
|
|
2022-10-29 18:37:41 +02:00
|
|
|
|
Write-Host "⏳ (1/5) Searching for IPFS executable... " -noNewline
|
2021-08-31 10:56:52 +02:00
|
|
|
|
& ipfs --version
|
2021-06-24 11:39:48 +02:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'ipfs' - make sure IPFS is installed and available" }
|
2022-11-05 16:13:56 +01:00
|
|
|
|
"⏳ (2/5) Init IPFS with profile 'lowpower'..."
|
|
|
|
|
& ipfs init --profile lowpower
|
2021-08-31 10:56:52 +02:00
|
|
|
|
|
2022-10-29 18:37:41 +02:00
|
|
|
|
"⏳ (3/5) Configuring IPFS..."
|
2021-06-24 11:39:48 +02:00
|
|
|
|
& ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
|
2022-11-05 15:52:19 +01:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config Addresses.API' failed with exit code $lastExitCode" }
|
2021-06-24 11:39:48 +02:00
|
|
|
|
|
|
|
|
|
& ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8765
|
2022-11-05 15:52:19 +01:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config Addresses.Gateway' failed with exit code $lastExitCode" }
|
2021-06-24 11:39:48 +02:00
|
|
|
|
|
2021-06-25 15:02:33 +02:00
|
|
|
|
$Hostname = $(hostname)
|
2022-04-13 12:06:32 +02:00
|
|
|
|
& ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"http://miami:5001\", \"http://localhost:3000\", \"http://127.0.0.1:5001\", \"https://webui.ipfs.io\"]'
|
2022-11-05 15:52:19 +01:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config Access-Control-Allow-Origin' failed with exit code $lastExitCode" }
|
2021-06-24 11:39:48 +02:00
|
|
|
|
|
2021-06-25 15:02:33 +02:00
|
|
|
|
& ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '[\"PUT\", \"POST\"]'
|
2022-11-05 15:52:19 +01:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config Access-Control-Allow-Methods' failed with exit code $lastExitCode" }
|
2022-06-09 09:42:13 +02:00
|
|
|
|
|
2022-11-05 15:52:19 +01:00
|
|
|
|
& ipfs config --json AutoNAT.Throttle.GlobalLimit 1 # (30 by default)
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config AutoNAT.Throttle.GlobalLimit 1' failed with exit code $lastExitCode" }
|
2022-06-09 09:42:13 +02:00
|
|
|
|
|
2022-11-05 15:52:19 +01:00
|
|
|
|
& ipfs config --json AutoNAT.Throttle.PeerLimit 1 # (3 by default)
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config AutoNAT.Throttle.PeerLimit 1' failed with exit code $lastExitCode" }
|
2021-08-31 10:32:20 +02:00
|
|
|
|
""
|
2022-10-29 18:37:41 +02:00
|
|
|
|
Write-Host "⏳ (4/5) Increasing UDP receive buffer size..." -noNewline
|
2021-06-24 11:39:48 +02:00
|
|
|
|
& sudo sysctl -w net.core.rmem_max=2500000
|
2022-11-05 15:52:19 +01:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'sysctl' failed with exit code $lastExitCode" }
|
2022-10-29 18:37:41 +02:00
|
|
|
|
"⏳ (5/5) Starting IPFS daemon..."
|
2021-06-28 21:29:58 +02:00
|
|
|
|
# Start-Process nohup 'ipfs daemon'
|
|
|
|
|
Start-Process nohup -ArgumentList 'ipfs','daemon' -RedirectStandardOutput "$HOME/console.out" -RedirectStandardError "$HOME/console.err"
|
2021-06-24 11:39:48 +02:00
|
|
|
|
|
2021-08-31 10:32:20 +02:00
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2024-10-01 13:37:53 +02:00
|
|
|
|
"✅ started IPFS server in $Elapsed sec"
|
2022-06-09 09:42:13 +02:00
|
|
|
|
"⚠️ NOTE: make sure your router does not block TCP/UDP port 4001 for IPv4 and IPv6"
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-06-24 11:39:48 +02:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-06-24 11:39:48 +02:00
|
|
|
|
exit 1
|
|
|
|
|
}
|