2021-08-26 10:46:12 +02:00
|
|
|
|
<#
|
2021-07-16 16:40:06 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
publish-to-ipfs.ps1 [<file(s)/dir>] [<to-hash-list>]
|
|
|
|
|
.DESCRIPTION
|
2021-08-29 17:50:03 +02:00
|
|
|
|
Publishes the given files and folders to IPFS.
|
2021-07-16 16:40:06 +02:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> .\publish-to-ipfs.ps1 C:\MyFile.txt
|
2021-08-29 17:50:03 +02:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz · License: CC0
|
2021-07-16 16:40:06 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
#>
|
|
|
|
|
|
2021-08-02 07:47:31 +02:00
|
|
|
|
param([string]$Files = "", [string]$HashList = "IPFS_hashes.txt", [string]$DF_Hashes = "file_checksums.xml")
|
2021-07-16 16:40:06 +02:00
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if ($Files -eq "") { $Files = read-host "Enter file(s) or directory tree to publish" }
|
|
|
|
|
|
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
2021-08-11 07:34:54 +02:00
|
|
|
|
|
2021-09-01 09:23:25 +02:00
|
|
|
|
""
|
2021-09-11 11:17:17 +02:00
|
|
|
|
"Step 1/3: Searching for IPFS..."
|
2021-08-11 07:34:54 +02:00
|
|
|
|
& ipfs --version
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'ipfs' - make sure IPFS is installed and available" }
|
|
|
|
|
|
2021-08-01 11:57:54 +02:00
|
|
|
|
if (test-path "$Files" -pathType container) {
|
2021-09-01 09:23:25 +02:00
|
|
|
|
""
|
|
|
|
|
"Step 2/3: Publishing folder $Files/ to IPFS..."
|
2021-08-01 11:57:54 +02:00
|
|
|
|
& ipfs add -r "$Files" > $HashList
|
2021-09-11 11:17:17 +02:00
|
|
|
|
[int]$Count = 1
|
2021-09-01 09:23:25 +02:00
|
|
|
|
""
|
|
|
|
|
echo "Step 3/3: Calculating digital forensics hashes to $DF_HASHES ..."
|
2021-08-01 11:57:54 +02:00
|
|
|
|
& nice hashdeep -c md5,sha1,sha256 -r -d -l -j 1 "$Files" > $DF_Hashes
|
|
|
|
|
} else {
|
|
|
|
|
$FileList = (get-childItem "$Files")
|
|
|
|
|
foreach ($File in $FileList) {
|
|
|
|
|
if (test-path "$Files" -pathType container) {
|
2021-09-01 09:23:25 +02:00
|
|
|
|
"Step 2/3: Publishing folder $File/ to IPFS..."
|
2021-08-01 11:57:54 +02:00
|
|
|
|
& ipfs add -r "$File" >> $HashList
|
|
|
|
|
} else {
|
2021-09-01 09:23:25 +02:00
|
|
|
|
"Step 2/3: Publishing file $File to IPFS..."
|
2021-08-01 11:57:54 +02:00
|
|
|
|
& ipfs add "$File" >> $HashList
|
|
|
|
|
}
|
2021-07-16 16:40:06 +02:00
|
|
|
|
}
|
2021-09-11 11:17:17 +02:00
|
|
|
|
[int]$Count = $FileList.Count
|
2021-07-16 16:40:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2021-08-01 11:57:54 +02:00
|
|
|
|
"✔️ published $Count file(s)/folder(s) to IPFS in $Elapsed sec"
|
2021-07-16 16:40:06 +02:00
|
|
|
|
" NOTE: to publish it to IPNS execute: ipfs name publish <HASH>"
|
|
|
|
|
exit 0
|
|
|
|
|
} catch {
|
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|