Improve publish-to-ipfs.ps1

This commit is contained in:
Markus Fleschutz 2021-08-01 11:57:54 +02:00
parent f7d5d366f7
commit dc6b183696

View File

@ -2,7 +2,7 @@
.SYNOPSIS
publish-to-ipfs.ps1 [<file(s)/dir>] [<to-hash-list>]
.DESCRIPTION
Publishes the given files or directory to IPFS
Publishes the given files and folders to IPFS
.EXAMPLE
PS> .\publish-to-ipfs.ps1 C:\MyFile.txt
.LINK
@ -20,23 +20,29 @@ try {
if ($Files -eq "") { $Files = read-host "Enter file(s) or directory tree to publish" }
$StopWatch = [system.diagnostics.stopwatch]::startNew()
$Files = (get-childItem "$Files")
[int]$Count = $Files.Count
foreach ($File in $Files) {
if (test-path "$File" -pathType container) {
"Adding directory tree $File to IPFS..."
ipfs add -r "$File" > $HashList
if (test-path "$Files" -pathType container) {
"Adding folder $Files to IPFS..."
[int]$Count = 1
& ipfs add -r "$Files" > $HashList
echo "Calculating digital forensics hashes to $DF_HASHES ..."
nice hashdeep -c md5,sha1,sha256 -r -d -l -j 1 "$File" > $DF_Hashes
} else {
"Adding file $File to IPFS..."
ipfs add "$File" > $HashList
echo "Calculating digital forensics hashes to $DF_HASHES ..."
& nice hashdeep -c md5,sha1,sha256 -r -d -l -j 1 "$Files" > $DF_Hashes
} else {
$FileList = (get-childItem "$Files")
[int]$Count = $FileList.Count
foreach ($File in $FileList) {
if (test-path "$Files" -pathType container) {
"Adding folder $File to IPFS..."
& ipfs add -r "$File" >> $HashList
} else {
"Adding file $File to IPFS..."
& ipfs add "$File" >> $HashList
}
}
}
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ published $Count files(s)/directory to IPFS in $Elapsed sec"
"✔️ published $Count file(s)/folder(s) to IPFS in $Elapsed sec"
" NOTE: to publish it to IPNS execute: ipfs name publish <HASH>"
exit 0
} catch {