2024-11-08 12:38:20 +01:00
|
|
|
The *publish-to-ipfs.ps1* Script
|
|
|
|
===========================
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
This script publishes the given files and folders to IPFS.
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2021-11-08 21:36:42 +01:00
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
/home/markus/Repos/PowerShell/scripts/publish-to-ipfs.ps1 [[-FilePattern] <String>] [[-HashList] <String>] [[-DF_Hashes] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
-FilePattern <String>
|
|
|
|
Specifies the file pattern
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
-HashList <String>
|
|
|
|
Specifies the path to the resulting hash list
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 2
|
|
|
|
Default value IPFS_hashes.txt
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
-DF_Hashes <String>
|
|
|
|
Specifies the path to the resulting digital forensic hashes
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 3
|
|
|
|
Default value file_checksums.xml
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2021-11-08 21:36:42 +01:00
|
|
|
```powershell
|
|
|
|
PS> ./publish-to-ipfs C:\MyFile.txt
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2021-11-08 21:36:42 +01:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Publishes files & folders to IPFS
|
|
|
|
.DESCRIPTION
|
|
|
|
This script publishes the given files and folders to IPFS.
|
|
|
|
.PARAMETER FilePattern
|
|
|
|
Specifies the file pattern
|
|
|
|
.PARAMETER HashList
|
|
|
|
Specifies the path to the resulting hash list
|
|
|
|
.PARAMETER DF_Hashes
|
|
|
|
Specifies the path to the resulting digital forensic hashes
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./publish-to-ipfs C:\MyFile.txt
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
param([string]$FilePattern = "", [string]$HashList = "IPFS_hashes.txt", [string]$DF_Hashes = "file_checksums.xml")
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($FilePattern -eq "") { $FilePattern = read-host "Enter file(s)/directories to publish" }
|
|
|
|
|
|
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
|
|
|
|
Write-Host "⏳ (1/3) Searching for IPFS executable..." -NoNewline
|
|
|
|
& ipfs --version
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'ipfs' - make sure IPFS is installed and available" }
|
|
|
|
|
|
|
|
if (test-path "$FilePattern" -pathType container) {
|
|
|
|
"⏳ (2/3) Publishing folder $FilePattern/..."
|
|
|
|
& ipfs add -r "$FilePattern" > $HashList
|
|
|
|
[int]$Count = 1
|
|
|
|
""
|
|
|
|
"⏳ (3/3) Calculating digital forensics hashes to $DF_HASHES ..."
|
|
|
|
& nice hashdeep -c md5,sha1,sha256 -r -d -l -j 1 "$FilePattern" > $DF_Hashes
|
|
|
|
} else {
|
|
|
|
$FileList = (get-childItem "$FilePattern")
|
|
|
|
foreach ($File in $FileList) {
|
|
|
|
if (test-path "$FilePattern" -pathType container) {
|
|
|
|
"⏳ (2/3) Publishing folder $File/..."
|
|
|
|
& ipfs add -r "$File" >> $HashList
|
|
|
|
} else {
|
|
|
|
"⏳ (3/3) Publishing file $File..."
|
|
|
|
& ipfs add "$File" >> $HashList
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[int]$Count = $FileList.Count
|
|
|
|
}
|
|
|
|
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
2024-11-08 12:35:11 +01:00
|
|
|
"✅ published $Count file(s)/folder(s) to IPFS in $Elapsed sec"
|
2022-11-17 20:02:26 +01:00
|
|
|
" NOTE: to publish it to IPNS execute: ipfs name publish <HASH>"
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:59)*
|