From dc6b1836961cfdea00b5d040ae29d6bcf1f2db1b Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sun, 1 Aug 2021 11:57:54 +0200 Subject: [PATCH] Improve publish-to-ipfs.ps1 --- Scripts/publish-to-ipfs.ps1 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Scripts/publish-to-ipfs.ps1 b/Scripts/publish-to-ipfs.ps1 index ac82625c..f23dd36d 100755 --- a/Scripts/publish-to-ipfs.ps1 +++ b/Scripts/publish-to-ipfs.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS publish-to-ipfs.ps1 [] [] .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 " exit 0 } catch {