init: ps-profile bootstrap + gper-core

This commit is contained in:
2026-07-21 12:48:24 +03:00
commit e3f6db5796
3 changed files with 241 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
# bootstrap.ps1 — Установка профиля PS gper
# Версия: 1.0.0
# Дата: 2026-07-21
# Запуск с любой машины:
# iwr 'https://sc.gper.ru/tarakan/ps-profile/raw/branch/main/bootstrap.ps1' | iex
# ============================================
# КОНФИГУРАЦИЯ
# ============================================
$PROFILE_REPO = 'https://sc.gper.ru/tarakan/ps-profile.git'
$PROFILE_DIR = Join-Path $HOME 'Documents\PowerShell\gper-profile'
$MODULES = @(
'PSReadLine',
'Terminal-Icons',
'Posh-SSH',
'Microsoft.PowerShell.SecretManagement',
'Microsoft.PowerShell.SecretStore',
'TableUI'
)
# ============================================
# BOOTSTRAP
# ============================================
Write-Host ''
Write-Host '=== Bootstrap: gper PS Profile ===' -ForegroundColor Cyan
Write-Host ''
# 1. Execution Policy
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Write-Host '[OK] ExecutionPolicy = RemoteSigned' -ForegroundColor Green
# 2. PSResourceGet — современный установщик модулей
if (-not (Get-Module Microsoft.PowerShell.PSResourceGet -ListAvailable -ErrorAction SilentlyContinue)) {
Write-Host '[..] Устанавливаю PSResourceGet...' -ForegroundColor Yellow -NoNewline
Install-Module Microsoft.PowerShell.PSResourceGet -Scope CurrentUser -Force -AllowClobber
Write-Host ' готово' -ForegroundColor Green
}
# 3. Модули
Write-Host ''
Write-Host '--- Модули ---' -ForegroundColor Cyan
foreach ($mod in $MODULES) {
if (Get-Module $mod -ListAvailable -ErrorAction SilentlyContinue) {
Write-Host "[OK] $mod" -ForegroundColor Green
} else {
Write-Host "[..] $mod..." -ForegroundColor Yellow -NoNewline
Install-PSResource -Name $mod -Scope CurrentUser -TrustRepository -Quiet -ErrorAction SilentlyContinue
Write-Host ' установлен' -ForegroundColor Green
}
}
# 4. Клонировать / обновить репо профиля
Write-Host ''
Write-Host '--- Репо профиля ---' -ForegroundColor Cyan
if (Test-Path (Join-Path $PROFILE_DIR '.git')) {
Write-Host '[..] Обновляю репо...' -ForegroundColor Yellow -NoNewline
Push-Location $PROFILE_DIR
git pull --quiet
Pop-Location
Write-Host ' готово' -ForegroundColor Green
} else {
if (Test-Path $PROFILE_DIR) { Remove-Item $PROFILE_DIR -Recurse -Force }
Write-Host '[..] Клонирую профиль...' -ForegroundColor Yellow -NoNewline
git clone --quiet $PROFILE_REPO $PROFILE_DIR
Write-Host ' готово' -ForegroundColor Green
}
# 5. Подключить в $PROFILE (CurrentUserCurrentHost)
Write-Host ''
Write-Host '--- Профиль ---' -ForegroundColor Cyan
$profileLine = ". `"$PROFILE_DIR\profile.ps1`""
if (-not (Test-Path $PROFILE)) {
New-Item -Path $PROFILE -ItemType File -Force | Out-Null
}
$profileContent = Get-Content $PROFILE -Raw -ErrorAction SilentlyContinue
if ($profileContent -notmatch 'gper-profile') {
Add-Content -Path $PROFILE -Value "`n$profileLine"
Write-Host "[OK] Подключён: $PROFILE" -ForegroundColor Green
} else {
Write-Host '[OK] Уже подключён' -ForegroundColor Yellow
}
Write-Host ''
Write-Host '=== Готово! Перезапусти терминал ===' -ForegroundColor Cyan
Write-Host ''
+109
View File
@@ -0,0 +1,109 @@
# gper-core.psm1 — Личный модуль функций gper
# Версия: 1.0.0
# Дата: 2026-07-21
# ============================================================
# WOL — Wake-On-LAN
# ============================================================
function Send-WakeOnLan {
<#
.SYNOPSIS Отправить магический пакет WOL по MAC-адресу.
.EXAMPLE Send-WakeOnLan -MacAddress 'BC:24:11:AA:BB:CC'
#>
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0)]
[ValidatePattern('^([0-9A-Fa-f]{2}[:\-]){5}[0-9A-Fa-f]{2}$')]
[string]$MacAddress,
[string]$BroadcastAddress = '255.255.255.255',
[int]$Port = 9
)
$mac = $MacAddress -replace '[:\-]', ''
$bytes = [byte[]](@(0xFF) * 6 + ($mac -split '(..)' | Where-Object { $_ } | ForEach-Object { [Convert]::ToByte($_, 16) }) * 16)
$udp = [System.Net.Sockets.UdpClient]::new()
$udp.Connect($BroadcastAddress, $Port)
$udp.Send($bytes, $bytes.Length) | Out-Null
$udp.Close()
Write-Host "WOL → $MacAddress" -ForegroundColor Green
}
Set-Alias -Name wol -Value Send-WakeOnLan -Option AllScope -Force
# ============================================================
# SSH — быстрый доступ к узлам
# ============================================================
function Connect-VPS {
<#
.SYNOPSIS SSH на VPS по алиасу (ru/us/us2/iz/ya).
.EXAMPLE Connect-VPS ru
#>
param(
[Parameter(Mandatory, Position = 0)]
[ValidateSet('ru', 'us', 'us2', 'iz', 'ya')]
[string]$Node
)
$keyPath = 'c:\Users\tarakan\.ssh\ai_ssh_key'
$ipMap = @{
ru = '5.129.200.97'
us = '77.91.126.90'
us2 = '77.91.126.64'
iz = '185.239.48.145'
ya = '158.160.227.222'
}
ssh -p 63121 -i $keyPath "uai@$($ipMap[$Node])"
}
Set-Alias -Name vps -Value Connect-VPS -Option AllScope -Force
# ============================================================
# Профиль — обновление
# ============================================================
function Update-GperProfile {
<#
.SYNOPSIS git pull в директории профиля + перезагрузить профиль.
#>
$profileDir = Join-Path $HOME 'Documents\PowerShell\gper-profile'
if (-not (Test-Path $profileDir)) {
Write-Host 'Директория профиля не найдена' -ForegroundColor Red
return
}
Push-Location $profileDir
git pull
Pop-Location
. (Join-Path $profileDir 'profile.ps1')
Write-Host 'Профиль обновлён и перезагружен' -ForegroundColor Green
}
Set-Alias -Name reload -Value Update-GperProfile -Option AllScope -Force
# ============================================================
# Утилиты
# ============================================================
function Get-ExternalIP {
# Показать внешний IP (через us-vps для проверки обхода)
(Invoke-RestMethod -Uri 'https://api.ipify.org?format=json' -TimeoutSec 10).ip
}
Set-Alias -Name myip -Value Get-ExternalIP -Option AllScope -Force
function Test-PortOpen {
<#
.SYNOPSIS Проверить доступность TCP-порта.
.EXAMPLE Test-PortOpen 10.10.10.1 22
#>
param(
[Parameter(Mandatory)][string]$Host,
[Parameter(Mandatory)][int]$Port,
[int]$TimeoutMs = 2000
)
$tcp = [System.Net.Sockets.TcpClient]::new()
$result = $tcp.BeginConnect($Host, $Port, $null, $null)
$ok = $result.AsyncWaitHandle.WaitOne($TimeoutMs, $false)
$tcp.Close()
if ($ok) {
Write-Host "$Host`:$Port OPEN" -ForegroundColor Green
} else {
Write-Host "$Host`:$Port CLOSED / timeout" -ForegroundColor Red
}
}
Set-Alias -Name portcheck -Value Test-PortOpen -Option AllScope -Force
Export-ModuleMember -Function * -Alias *
+47
View File
@@ -0,0 +1,47 @@
# profile.ps1 — Профиль PS7 gper
# Версия: 1.0.0
# Дата: 2026-07-21
# Подключается через $PROFILE: . "$HOME\Documents\PowerShell\gper-profile\profile.ps1"
# ── Terminal-Icons ───────────────────────────────────────────────────────
Import-Module Terminal-Icons -ErrorAction SilentlyContinue
# ── PSReadLine ───────────────────────────────────────────────────────────
if (Get-Module PSReadLine -ListAvailable -ErrorAction SilentlyContinue) {
Import-Module PSReadLine
Set-PSReadLineOption -EditMode Windows
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key Ctrl+d -Function DeleteCharOrExit
}
# ── Промпт ───────────────────────────────────────────────────────────────
function prompt {
$loc = $ExecutionContext.SessionState.Path.CurrentLocation
$ver = $PSVersionTable.PSVersion.Major
$host_str = $env:COMPUTERNAME.ToLower()
"`e[32m[PS$ver`e[0m `e[33m$host_str`e[0m `e[36m$loc`e[0m]`n`e[32m>`e[0m "
}
# ── Алиасы ───────────────────────────────────────────────────────────────
Set-Alias -Name g -Value git -Option AllScope -Force
Set-Alias -Name grep -Value Select-String -Option AllScope -Force
Set-Alias -Name np -Value notepad -Option AllScope -Force
# ── Функции навигации ────────────────────────────────────────────────────
function .. { Set-Location .. }
function ... { Set-Location ..\.. }
function l { Get-ChildItem -Force @args }
# ── Модуль gper-core ────────────────────────────────────────────────────
$gperCore = Join-Path $PSScriptRoot 'modules\gper-core.psm1'
if (Test-Path $gperCore) {
Import-Module $gperCore -Force -DisableNameChecking
}
# ── Информация при старте ────────────────────────────────────────────────
Write-Host "PS $($PSVersionTable.PSVersion) | $env:COMPUTERNAME | $(Get-Date -Format 'dd.MM.yyyy HH:mm')" -ForegroundColor DarkGray