feat(detmir): ship ops, dlp, 1c and mcp updates
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
|
||||
PWSH_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/powershell"
|
||||
PROFILE="$PWSH_DIR/Microsoft.PowerShell_profile.ps1"
|
||||
LOCAL_CFG="$PWSH_DIR/detmir-windows.psd1"
|
||||
SNIPPET="$ROOT/scripts/powershell/detmir-powershell-profile.ps1"
|
||||
EXAMPLE_CFG="$ROOT/scripts/powershell/detmir-windows.psd1.example"
|
||||
INVENTORY="$ROOT/ansible/inventory.ini"
|
||||
MARK_BEGIN="# >>> DetMir PowerShell MCP >>>"
|
||||
MARK_END="# <<< DetMir PowerShell MCP <<<"
|
||||
|
||||
mkdir -p "$PWSH_DIR"
|
||||
touch "$PROFILE"
|
||||
|
||||
TMP_PROFILE="$(mktemp)"
|
||||
awk -v begin="$MARK_BEGIN" -v end="$MARK_END" '
|
||||
$0 == begin { skip = 1; next }
|
||||
$0 == end { skip = 0; next }
|
||||
skip != 1 { print }
|
||||
' "$PROFILE" > "$TMP_PROFILE"
|
||||
|
||||
cat >> "$TMP_PROFILE" <<EOF
|
||||
|
||||
$MARK_BEGIN
|
||||
\$detmirProjectProfile = '$SNIPPET'
|
||||
if (Test-Path -LiteralPath \$detmirProjectProfile) {
|
||||
. \$detmirProjectProfile
|
||||
}
|
||||
$MARK_END
|
||||
EOF
|
||||
|
||||
mv "$TMP_PROFILE" "$PROFILE"
|
||||
|
||||
if [ ! -f "$LOCAL_CFG" ]; then
|
||||
host=""
|
||||
user=""
|
||||
password=""
|
||||
|
||||
if [ -f "$INVENTORY" ]; then
|
||||
line="$(awk '
|
||||
/^\[aw_windows\]/ { in_section = 1; next }
|
||||
/^\[/ { if (in_section) exit }
|
||||
in_section && $0 !~ /^[[:space:]]*#/ && NF { print; exit }
|
||||
' "$INVENTORY")"
|
||||
|
||||
if [ -n "$line" ]; then
|
||||
for token in $line; do
|
||||
case "$token" in
|
||||
ansible_host=*) host="${token#ansible_host=}" ;;
|
||||
ansible_user=*) user="${token#ansible_user=}" ;;
|
||||
ansible_password=*) password="${token#ansible_password=}" ;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$host" ] || [ -n "$user" ] || [ -n "$password" ]; then
|
||||
cat > "$LOCAL_CFG" <<EOF
|
||||
@{
|
||||
Host = '${host:-192.168.100.18}'
|
||||
User = '${user:-Администратор}'
|
||||
Password = '${password:-CHANGE_ME}'
|
||||
Port = 22
|
||||
PowerShellPath = 'powershell.exe'
|
||||
}
|
||||
EOF
|
||||
else
|
||||
cp "$EXAMPLE_CFG" "$LOCAL_CFG"
|
||||
fi
|
||||
fi
|
||||
|
||||
chmod 600 "$LOCAL_CFG"
|
||||
|
||||
printf 'Installed DetMir PowerShell MCP loader in %s\n' "$PROFILE"
|
||||
printf 'DetMir local config: %s\n' "$LOCAL_CFG"
|
||||
printf 'Reopen PowerShell or restart Codex session to pick up the profile.\n'
|
||||
@@ -0,0 +1,140 @@
|
||||
$script:DetMirConfigPath = if ($env:DETMIR_WINDOWS_CONFIG_PATH) {
|
||||
$env:DETMIR_WINDOWS_CONFIG_PATH
|
||||
}
|
||||
else {
|
||||
Join-Path $HOME '.config/powershell/detmir-windows.psd1'
|
||||
}
|
||||
|
||||
$script:DetMirConfig = @{}
|
||||
|
||||
if (Test-Path -LiteralPath $script:DetMirConfigPath) {
|
||||
try {
|
||||
$script:DetMirConfig = Import-PowerShellDataFile -Path $script:DetMirConfigPath
|
||||
}
|
||||
catch {
|
||||
$script:DetMirConfig = @{}
|
||||
}
|
||||
}
|
||||
|
||||
function Get-DetMirWindowsSetting {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$EnvName,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$ConfigKey,
|
||||
|
||||
[string]$Default = ''
|
||||
)
|
||||
|
||||
$envValue = [Environment]::GetEnvironmentVariable($EnvName)
|
||||
if (-not [string]::IsNullOrWhiteSpace($envValue)) {
|
||||
return $envValue
|
||||
}
|
||||
|
||||
if ($script:DetMirConfig.ContainsKey($ConfigKey) -and -not [string]::IsNullOrWhiteSpace([string]$script:DetMirConfig[$ConfigKey])) {
|
||||
return [string]$script:DetMirConfig[$ConfigKey]
|
||||
}
|
||||
|
||||
return $Default
|
||||
}
|
||||
|
||||
$Global:DetMirWindowsHost = Get-DetMirWindowsSetting -EnvName 'DETMIR_WINDOWS_SSH_HOST' -ConfigKey 'Host' -Default '192.168.100.18'
|
||||
$Global:DetMirWindowsUser = Get-DetMirWindowsSetting -EnvName 'DETMIR_WINDOWS_SSH_USER' -ConfigKey 'User' -Default 'Администратор'
|
||||
$Global:DetMirWindowsPassword = Get-DetMirWindowsSetting -EnvName 'DETMIR_WINDOWS_SSH_PASSWORD' -ConfigKey 'Password'
|
||||
$Global:DetMirWindowsPort = [int](Get-DetMirWindowsSetting -EnvName 'DETMIR_WINDOWS_SSH_PORT' -ConfigKey 'Port' -Default '22')
|
||||
$Global:DetMirWindowsPowerShellPath = Get-DetMirWindowsSetting -EnvName 'DETMIR_WINDOWS_POWERSHELL_PATH' -ConfigKey 'PowerShellPath' -Default 'powershell.exe'
|
||||
|
||||
function Get-DetMirWindowsSshTarget {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Global:DetMirWindowsUser)) {
|
||||
return $Global:DetMirWindowsHost
|
||||
}
|
||||
|
||||
return "$($Global:DetMirWindowsUser)@$($Global:DetMirWindowsHost)"
|
||||
}
|
||||
|
||||
function Get-DetMirWindowsSshArguments {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
return @(
|
||||
'-o', 'ServerAliveInterval=15',
|
||||
'-o', 'ServerAliveCountMax=3',
|
||||
'-o', 'StrictHostKeyChecking=accept-new',
|
||||
'-o', 'LogLevel=ERROR',
|
||||
'-o', 'PreferredAuthentications=password,keyboard-interactive,publickey',
|
||||
'-p', [string]$Global:DetMirWindowsPort,
|
||||
(Get-DetMirWindowsSshTarget)
|
||||
)
|
||||
}
|
||||
|
||||
function Invoke-DetMirWindowsSsh {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Command
|
||||
)
|
||||
|
||||
$sshArgs = Get-DetMirWindowsSshArguments
|
||||
$sshArgs += $Command
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Global:DetMirWindowsPassword)) {
|
||||
& ssh @sshArgs
|
||||
return
|
||||
}
|
||||
|
||||
& sshpass '-p' $Global:DetMirWindowsPassword ssh @sshArgs
|
||||
}
|
||||
|
||||
function Enter-DetMirWindowsSsh {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
$sshArgs = Get-DetMirWindowsSshArguments
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Global:DetMirWindowsPassword)) {
|
||||
& ssh @sshArgs
|
||||
return
|
||||
}
|
||||
|
||||
& sshpass '-p' $Global:DetMirWindowsPassword ssh @sshArgs
|
||||
}
|
||||
|
||||
function Invoke-DetMirWindowsPowerShell {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Script
|
||||
)
|
||||
|
||||
$bootstrap = @"
|
||||
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
`$OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$Script
|
||||
"@
|
||||
|
||||
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($bootstrap))
|
||||
Invoke-DetMirWindowsSsh "$($Global:DetMirWindowsPowerShellPath) -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded"
|
||||
}
|
||||
|
||||
function Test-DetMirWindowsPowerShell {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
Invoke-DetMirWindowsPowerShell @'
|
||||
$PSVersionTable.PSVersion.ToString()
|
||||
[Environment]::OSVersion.VersionString
|
||||
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ProductName
|
||||
'@
|
||||
}
|
||||
|
||||
Set-Alias detmir-win-target Get-DetMirWindowsSshTarget
|
||||
Set-Alias detmir-win-ssh Invoke-DetMirWindowsSsh
|
||||
Set-Alias detmir-win-shell Enter-DetMirWindowsSsh
|
||||
Set-Alias detmir-win-ps Invoke-DetMirWindowsPowerShell
|
||||
Set-Alias detmir-win-test Test-DetMirWindowsPowerShell
|
||||
@@ -0,0 +1,7 @@
|
||||
@{
|
||||
Host = '192.168.100.18'
|
||||
User = 'Администратор'
|
||||
Password = 'CHANGE_ME'
|
||||
Port = 22
|
||||
PowerShellPath = 'powershell.exe'
|
||||
}
|
||||
Reference in New Issue
Block a user