2021-06-24 11:53:58 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
start-ipfs-server.ps1
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Starts a local IPFS server as a daemon process
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> .\start-ipfs-server.ps1
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2021-08-03 15:53:57 +02:00
|
|
|
|
Author: Markus Fleschutz
|
|
|
|
|
License: CC0
|
2021-06-24 11:39:48 +02:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
try {
|
2021-06-24 11:49:59 +02:00
|
|
|
|
"⚠️ Make sure your router does not block port 4001 (TCP/UDP) for IPv4/v6!"
|
|
|
|
|
""
|
|
|
|
|
|
2021-06-24 12:38:18 +02:00
|
|
|
|
"Step 1/5: searching for ipfs executable..."
|
2021-06-24 11:39:48 +02:00
|
|
|
|
$Result = (ipfs --version)
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'ipfs' - make sure IPFS is installed and available" }
|
|
|
|
|
|
2021-06-24 11:49:59 +02:00
|
|
|
|
"Step 2/5: initializing..."
|
2021-06-24 11:39:48 +02:00
|
|
|
|
& ipfs init --profile server
|
|
|
|
|
|
2021-06-24 11:49:59 +02:00
|
|
|
|
"Step 3/5: configuring..."
|
2021-06-24 11:39:48 +02:00
|
|
|
|
& 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" }
|
|
|
|
|
|
2021-06-25 15:02:33 +02:00
|
|
|
|
$Hostname = $(hostname)
|
2021-06-28 21:29:58 +02:00
|
|
|
|
& ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"http://raspi:5001\", \"http://localhost:3000\", \"http://127.0.0.1:5001\", \"https://webui.ipfs.io\"]'
|
2021-06-25 15:02:33 +02:00
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config Access-Control-Allow-Origin' failed" }
|
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\"]'
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "'ipfs config Access-Control-Allow-Methods' failed" }
|
2021-06-24 11:39:48 +02:00
|
|
|
|
|
2021-06-24 11:49:59 +02:00
|
|
|
|
"Step 4/5: increasing UDP receive buffer size..."
|
2021-06-28 21:29:58 +02:00
|
|
|
|
|
2021-06-24 11:39:48 +02:00
|
|
|
|
& sudo sysctl -w net.core.rmem_max=2500000
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "'sysctl' failed" }
|
|
|
|
|
|
2021-06-24 11:49:59 +02:00
|
|
|
|
"Step 5/5: starting daemon..."
|
2021-06-24 11:39:48 +02:00
|
|
|
|
|
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-24 20:46:03 +02:00
|
|
|
|
"✔️ Done."
|
2021-06-24 12:38:18 +02:00
|
|
|
|
exit 0
|
2021-06-24 11:39:48 +02:00
|
|
|
|
} catch {
|
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|