modified: RdzeN-Profile.ps1
This commit is contained in:
parent
222371c55d
commit
9a1255a5ce
@ -17,15 +17,24 @@ if (-not (Test-Path $path_gitea_powershell_profile_functions)) {
|
||||
New-Item -ItemType Directory -Path $path_gitea_powershell_profile_functions | Out-Null
|
||||
}
|
||||
|
||||
# 2. Download / pull GIT REPO
|
||||
# 2. Check if local repo is up to date GIT REPO
|
||||
Set-Location $path_gitea_powershell_profile
|
||||
$RepositoryURL = "https://gitea.rdzen.net/najlepszytomasz/PowerShell-Profile.git"
|
||||
|
||||
# Define paths
|
||||
$path_gitea = "$($env:USERPROFILE)\GITEA"
|
||||
$path_gitea_powershell_profile = "$path_gitea\PowerShell-Profile"
|
||||
$path_gitea_powershell_profile_functions = "$path_gitea_powershell_profile\functions"
|
||||
$path_profile_file = "$path_gitea_powershell_profile\RdzeN-Profile.ps1"
|
||||
try {
|
||||
$git_tmp = git fetch origin
|
||||
Write-Host "Success GIT git fetch origin: $RepositoryURL" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "Error occurred while GIT git fetch origin: $RepositoryURL" -ForegroundColor Red
|
||||
}
|
||||
try {
|
||||
$git_tmp = git status
|
||||
Write-Host "Success GIT git status: $RepositoryURL" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "Error occurred while GIT git status: $RepositoryURL" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# 3. Download GIT REPO
|
||||
# Function to pull repository
|
||||
function Pull-Repository {
|
||||
Set-Location $path_gitea_powershell_profile
|
||||
@ -37,83 +46,17 @@ function Pull-Repository {
|
||||
}
|
||||
}
|
||||
|
||||
# Check if the profile file exists locally
|
||||
if (-not (Test-Path $path_profile_file)) {
|
||||
Write-Host "Profile file not found locally. Pulling from repository..." -ForegroundColor Yellow
|
||||
Pull-Repository
|
||||
Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object {
|
||||
. $_.FullName
|
||||
}
|
||||
# 97. Override profile
|
||||
Override-Profile
|
||||
# 98. Override profile
|
||||
#Reload-Profile
|
||||
if ($git_tmp -match "(Your branch is up to date)") {
|
||||
Write-Host "For $RepositoryURL`n`n$git_tmp" -ForegroundColor Green
|
||||
} else {
|
||||
# Check if the profile file has been modified
|
||||
$local_profile_hash = Get-FileHash -Path $path_profile_file -Algorithm SHA1
|
||||
|
||||
# Dodaj nagłówek do lokalnego hasha
|
||||
$local_profile_hash_with_header = "blob $($local_profile_hash.Length)`0" + (Get-Content $path_profile_file -Raw)
|
||||
$local_profile_hash_with_header = Get-FileHash -Algorithm SHA1 -InputStream ([System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($local_profile_hash_with_header)))
|
||||
|
||||
$remote_profile_hash = & git hash-object $path_profile_file
|
||||
|
||||
if ($local_profile_hash_with_header.Hash.ToLower() -ne $remote_profile_hash.Trim()) {
|
||||
Write-Host "Local profile file has been modified. Pulling from repository..." -ForegroundColor Yellow
|
||||
Write-Host "For $RepositoryURL`n`n$git_tmp" -ForegroundColor Red
|
||||
Pull-Repository
|
||||
Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object {
|
||||
. $_.FullName
|
||||
}
|
||||
# 97. Override profile
|
||||
Override-Profile
|
||||
# 98. Override profile
|
||||
#Reload-Profile
|
||||
} else {
|
||||
Write-Host "Local profile file is up to date." -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
# Check if functions have been modified
|
||||
$local_functions_hashes = @{}
|
||||
$remote_functions_hashes = @{}
|
||||
|
||||
# Iterate through local functions
|
||||
Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object {
|
||||
$local_functions_hashes[$_.Name] = (Get-FileHash -Path $_.FullName -Algorithm SHA1).Hash
|
||||
}
|
||||
|
||||
# Get remote functions hashes
|
||||
Set-Location $path_gitea_powershell_profile_functions
|
||||
git pull -q
|
||||
Get-ChildItem | ForEach-Object {
|
||||
$remote_functions_hashes[$_.Name] = (git hash-object $_.Name).Trim()
|
||||
}
|
||||
|
||||
# Compare local and remote function hashes
|
||||
$functions_to_pull = @()
|
||||
foreach ($function_name in $local_functions_hashes.Keys) {
|
||||
if ($local_functions_hashes[$function_name] -ne $remote_functions_hashes[$function_name]) {
|
||||
$functions_to_pull += $function_name
|
||||
}
|
||||
}
|
||||
|
||||
if ($functions_to_pull.Count -gt 0) {
|
||||
Write-Host "Functions have been modified. Pulling from repository..." -ForegroundColor Yellow
|
||||
Pull-Repository
|
||||
Get-ChildItem $path_gitea_powershell_profile_functions | ForEach-Object {
|
||||
. $_.FullName
|
||||
}
|
||||
} else {
|
||||
Write-Host "Functions are up to date." -ForegroundColor Green
|
||||
Write-Host "For set up do date, please run Override-Profile and Reload-Profile" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# 4. List functions
|
||||
# Lokalizacja plików
|
||||
$path_to_search = "$path_gitea_powershell_profile_functions\*"
|
||||
|
||||
# Zmienna do przechowywania wyników
|
||||
$found_functions = @()
|
||||
|
||||
# Szukanie funkcji w plikach
|
||||
Get-ChildItem $path_to_search | ForEach-Object {
|
||||
$file_content = Get-Content $_.FullName -Raw
|
||||
|
Loading…
x
Reference in New Issue
Block a user