move things around do some BullShit
This commit is contained in:
+77
-112
@@ -15,141 +15,106 @@ $ErrorActionPreference = 'Stop'
|
||||
try { $PSStyle.OutputRendering = 'Host' } catch {}
|
||||
|
||||
function Invoke-Ext {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$Exe,
|
||||
[Parameter(Mandatory = $true)][string[]]$Args,
|
||||
[Parameter(Mandatory = $true)][string]$Label
|
||||
)
|
||||
$displayArgs = @($Args)
|
||||
param($Exe, $Arguments, $Label)
|
||||
$displayArgs = $Arguments.Clone()
|
||||
for ($i = 0; $i -lt $displayArgs.Count; $i++) {
|
||||
if ($displayArgs[$i] -eq '-pw' -and ($i + 1) -lt $displayArgs.Count) { $displayArgs[$i + 1] = '****' } # lowkey leaked my password
|
||||
if ($displayArgs[$i] -eq '-pw' -and ($i + 1) -lt $displayArgs.Count) {
|
||||
$displayArgs[$i + 1] = '****'
|
||||
}
|
||||
}
|
||||
Write-Host ("[{0}] {1} {2}" -f $Label, $Exe, ($displayArgs -join ' ')) -ForegroundColor Cyan
|
||||
$out = & $Exe @Args 2>&1
|
||||
$code = $LASTEXITCODE
|
||||
if ($code -ne 0) {
|
||||
Write-Error ("{0} failed ({1}):`n{2}" -f $Label, $code, ($out -join "`n"))
|
||||
throw ("{0} failed ({1})" -f $Label, $code)
|
||||
|
||||
$out = & $Exe @Arguments 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error ("{0} failed ({1}):`n{2}" -f $Label, $LASTEXITCODE, ($out -join "`n"))
|
||||
throw ("{0} failed ({1})" -f $Label, $LASTEXITCODE)
|
||||
}
|
||||
return $out
|
||||
}
|
||||
|
||||
function Get-DeployScript {
|
||||
param($DeployPreferred, $DeployTmp, $RemoteTmp, $RemotePath, $RestartFlag)
|
||||
return @"
|
||||
DEPLOY=$DeployPreferred;
|
||||
if [ ! -x "`$DEPLOY" ] && [ -f $DeployTmp ]; then
|
||||
sed -i "s/\r$//" $DeployTmp 2>/dev/null || true
|
||||
chmod +x $DeployTmp
|
||||
DEPLOY=$DeployTmp
|
||||
fi
|
||||
sh "`$DEPLOY" $RemoteTmp $RemotePath $RestartFlag
|
||||
"@ # -replace "`r", "" -replace "`r`n", "`n"
|
||||
|
||||
}
|
||||
|
||||
function Invoke-Scp {
|
||||
param($Local, $Dest, $Pass, $HostKey, [switch]$Quiet)
|
||||
if ($pscp = Get-Command pscp.exe -ErrorAction SilentlyContinue) {
|
||||
$arguments = @('-scp')
|
||||
if ($Quiet) { $arguments += '-q' }
|
||||
if ($HostKey) { $arguments += @('-batch', '-hostkey', $HostKey) }
|
||||
if ($Pass) { $arguments += @('-pw', $Pass) }
|
||||
$arguments += @($Local, $Dest)
|
||||
Invoke-Ext -Exe $pscp.Path -Arguments $arguments -Label 'scp'
|
||||
}
|
||||
else {
|
||||
$arguments = @('-O')
|
||||
if ($Quiet) { $arguments += '-q' }
|
||||
$arguments += @($Local, $Dest)
|
||||
Invoke-Ext -Exe 'scp' -Arguments $arguments -Label 'scp'
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-Ssh {
|
||||
param($Cmd, $User, $Remote, $Pass, [switch]$Quiet)
|
||||
$Cmd = $Cmd -replace "`r`n", "`n" -replace "`r", ""
|
||||
if ($plink = Get-Command plink.exe -ErrorAction SilentlyContinue) {
|
||||
$arguments = @('-batch', '-ssh')
|
||||
if ($Pass) { $arguments += @('-pw', $Pass) }
|
||||
$arguments += "$User@$Remote", $Cmd
|
||||
Invoke-Ext -Exe $plink.Path -Arguments $arguments -Label 'ssh'
|
||||
}
|
||||
else {
|
||||
$arguments = @()
|
||||
if ($Quiet) { $arguments += '-q' }
|
||||
$arguments += "$User@$Remote", $Cmd
|
||||
Invoke-Ext -Exe 'ssh' -Arguments $arguments -Label 'ssh'
|
||||
}
|
||||
}
|
||||
|
||||
#---- Main Flow ----
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
Push-Location $repoRoot
|
||||
|
||||
try {
|
||||
Write-Host "[build] cargo build --release --target $Target" -ForegroundColor Cyan
|
||||
cargo build --release --target $Target
|
||||
if ($LASTEXITCODE -ne 0) { throw "cargo build failed ($LASTEXITCODE)" }
|
||||
|
||||
$local = Join-Path $repoRoot ("target/" + $Target + "/release/" + $BinName)
|
||||
if (-not (Test-Path $local)) { throw "binary not found: $local" }
|
||||
$localBin = Join-Path $repoRoot "target/$Target/release/$BinName"
|
||||
if (-not (Test-Path $localBin)) { throw "binary not found: $localBin" }
|
||||
|
||||
$remoteTmp = "$RemotePath.tmp"
|
||||
$destTmp = "{0}@{1}:{2}" -f $User, $HostName, $remoteTmp
|
||||
$destTmp = "$User@${HostName}:$remoteTmp"
|
||||
$localDeploy = Join-Path $repoRoot 'scripts/remote_deploy_wakey.sh'
|
||||
$deployTmp = '/var/tmp/remote_deploy_wakey.sh'
|
||||
$destDeployTmp = "{0}@{1}:{2}" -f $User, $HostName, $deployTmp
|
||||
$deployPreferred = '/root/.bin/remote_deploy_wakey.sh'
|
||||
|
||||
if ($Pass) {
|
||||
$pscp = Get-Command pscp.exe -ErrorAction SilentlyContinue
|
||||
if ($pscp) {
|
||||
$pscpArgs = @()
|
||||
if ($Quiet) { $pscpArgs += '-q' }
|
||||
if ($HostKey) { $pscpArgs += @('-batch', '-scp', '-hostkey', $HostKey, '-pw', $Pass, $local, $destTmp) }
|
||||
else { $pscpArgs += @('-scp', '-pw', $Pass, $local, $destTmp) }
|
||||
Invoke-Ext -Exe $pscp.Path -Args $pscpArgs -Label 'push'
|
||||
# Push main binary
|
||||
Invoke-Scp -Local $localBin -Dest $destTmp -Pass $Pass -HostKey $HostKey -Quiet:$Quiet
|
||||
|
||||
$plink = Get-Command plink.exe -ErrorAction SilentlyContinue
|
||||
if (Test-Path $localDeploy) {
|
||||
$pscpArgsD = @()
|
||||
if ($Quiet) { $pscpArgsD += '-q' }
|
||||
if ($HostKey) { $pscpArgsD += @('-batch', '-scp', '-hostkey', $HostKey, '-pw', $Pass, $localDeploy, $destDeployTmp) }
|
||||
else { $pscpArgsD += @('-scp', '-pw', $Pass, $localDeploy, $destDeployTmp) }
|
||||
Invoke-Ext -Exe $pscp.Path -Args $pscpArgsD -Label 'push-deploy'
|
||||
}
|
||||
$remoteCmdCore = @'
|
||||
DEPLOY=$DEPLOY_PREFERRED
|
||||
if [ ! -x "$DEPLOY" ] && [ -f $DEPLOY_TMP ]; then
|
||||
sed -i "s/\r$//" $DEPLOY_TMP 2>/dev/null || true
|
||||
chmod +x $DEPLOY_TMP; DEPLOY=$DEPLOY_TMP
|
||||
fi
|
||||
sh "$DEPLOY" $REMOTE_TMP $REMOTE_PATH $DO_RESTART
|
||||
'@
|
||||
$remoteCmdCore = $remoteCmdCore.Replace('$DEPLOY_PREFERRED', $deployPreferred).Replace('$DEPLOY_TMP', $deployTmp).Replace('$REMOTE_TMP', $remoteTmp).Replace('$REMOTE_PATH', $RemotePath)
|
||||
$remoteCmdCore = if ($Restart) { $remoteCmdCore.Replace('$DO_RESTART', '1') } else { $remoteCmdCore.Replace('$DO_RESTART', '0') }
|
||||
$remoteCmdCore = ($remoteCmdCore -replace "`r", "")
|
||||
$remoteCmd = "sh -lc '$remoteCmdCore'"
|
||||
if ($Quiet) { $remoteCmd = "$remoteCmd >/dev/null 2>&1" }
|
||||
if ($plink) {
|
||||
$plinkArgs = @('-batch', '-ssh', '-pw', $Pass, "$User@$HostName", $remoteCmd)
|
||||
Invoke-Ext -Exe $plink.Path -Args $plinkArgs -Label 'ssh'
|
||||
}
|
||||
else {
|
||||
$sshArgs = @()
|
||||
if ($Quiet) { $sshArgs += '-q' }
|
||||
$sshArgs += @("$User@$HostName", $remoteCmd)
|
||||
Invoke-Ext -Exe 'ssh' -Args $sshArgs -Label 'ssh'
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Warning "pscp.exe not found. Falling back to scp (you may be prompted for a password)."
|
||||
$scpArgs = @('-O')
|
||||
if ($Quiet) { $scpArgs += '-q' }
|
||||
$scpArgs += @($local, $destTmp)
|
||||
Invoke-Ext -Exe 'scp' -Args $scpArgs -Label 'push'
|
||||
if (Test-Path $localDeploy) {
|
||||
$scpArgsD = @('-O')
|
||||
if ($Quiet) { $scpArgsD += '-q' }
|
||||
$scpArgsD += @($localDeploy, $destDeployTmp)
|
||||
Invoke-Ext -Exe 'scp' -Args $scpArgsD -Label 'push-deploy'
|
||||
}
|
||||
$remoteCmdCore = @'
|
||||
DEPLOY=$DEPLOY_PREFERRED
|
||||
if [ ! -x "$DEPLOY" ] && [ -f $DEPLOY_TMP ]; then
|
||||
sed -i "s/\r$//" $DEPLOY_TMP 2>/dev/null || true
|
||||
chmod +x $DEPLOY_TMP; DEPLOY=$DEPLOY_TMP
|
||||
fi
|
||||
sh "$DEPLOY" $REMOTE_TMP $REMOTE_PATH $DO_RESTART
|
||||
'@
|
||||
$remoteCmdCore = $remoteCmdCore.Replace('$DEPLOY_PREFERRED', $deployPreferred).Replace('$DEPLOY_TMP', $deployTmp).Replace('$REMOTE_TMP', $remoteTmp).Replace('$REMOTE_PATH', $RemotePath)
|
||||
$remoteCmdCore = if ($Restart) { $remoteCmdCore.Replace('$DO_RESTART', '1') } else { $remoteCmdCore.Replace('$DO_RESTART', '0') }
|
||||
$remoteCmdCore = ($remoteCmdCore -replace "`r", "")
|
||||
$remoteCmd = "sh -lc '$remoteCmdCore'"
|
||||
if ($Quiet) { $remoteCmd = "$remoteCmd >/dev/null 2>&1" }
|
||||
$sshArgs = @()
|
||||
if ($Quiet) { $sshArgs += '-q' }
|
||||
$sshArgs += @("$User@$HostName", $remoteCmd)
|
||||
Invoke-Ext -Exe 'ssh' -Args $sshArgs -Label 'ssh'
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scpArgs = @('-O')
|
||||
if ($Quiet) { $scpArgs += '-q' }
|
||||
$scpArgs += @($local, $destTmp)
|
||||
Invoke-Ext -Exe 'scp' -Args $scpArgs -Label 'push'
|
||||
if (Test-Path $localDeploy) {
|
||||
$scpArgsD = @('-O')
|
||||
if ($Quiet) { $scpArgsD += '-q' }
|
||||
$scpArgsD += @($localDeploy, $destDeployTmp)
|
||||
Invoke-Ext -Exe 'scp' -Args $scpArgsD -Label 'push-deploy'
|
||||
}
|
||||
$remoteCmdCore = @'
|
||||
DEPLOY=$DEPLOY_PREFERRED
|
||||
if [ ! -x "$DEPLOY" ] && [ -f $DEPLOY_TMP ]; then sed -i "s/\r$//" $DEPLOY_TMP 2>/dev/null || true; chmod +x $DEPLOY_TMP; DEPLOY=$DEPLOY_TMP; fi
|
||||
sh "$DEPLOY" $REMOTE_TMP $REMOTE_PATH $DO_RESTART
|
||||
'@
|
||||
$remoteCmdCore = $remoteCmdCore.Replace('$DEPLOY_PREFERRED', $deployPreferred).Replace('$DEPLOY_TMP', $deployTmp).Replace('$REMOTE_TMP', $remoteTmp).Replace('$REMOTE_PATH', $RemotePath)
|
||||
$remoteCmdCore = if ($Restart) { $remoteCmdCore.Replace('$DO_RESTART', '1') } else { $remoteCmdCore.Replace('$DO_RESTART', '0') }
|
||||
$remoteCmdCore = ($remoteCmdCore -replace "`r", "")
|
||||
$remoteCmd = "sh -lc '$remoteCmdCore'"
|
||||
if ($Quiet) { $remoteCmd = "$remoteCmd >/dev/null 2>&1" }
|
||||
$sshArgs = @()
|
||||
if ($Quiet) { $sshArgs += '-q' }
|
||||
$sshArgs += @("$User@$HostName", $remoteCmd)
|
||||
Invoke-Ext -Exe 'ssh' -Args $sshArgs -Label 'ssh'
|
||||
# Push deploy helper if exists
|
||||
if (Test-Path $localDeploy) {
|
||||
Invoke-Scp -Local $localDeploy -Dest "$User@${HostName}:$deployTmp" -Pass $Pass -HostKey $HostKey -Quiet:$Quiet
|
||||
}
|
||||
|
||||
# Build and run remote deploy command
|
||||
$restartFlag = $(if ($Restart) { '1' } else { '0' })
|
||||
$script = Get-DeployScript $deployPreferred $deployTmp $remoteTmp $RemotePath $restartFlag
|
||||
$remoteCmd = "sh -lc '$($script -replace "`r",'')'"
|
||||
if ($Quiet) { $remoteCmd += " >/dev/null 2>&1" }
|
||||
|
||||
Invoke-Ssh -Cmd $remoteCmd -User $User -Remote $HostName -Pass $Pass -Quiet:$Quiet
|
||||
|
||||
Write-Host "done ✔" -ForegroundColor Green
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=66 # Run after the resolvconf swap
|
||||
START=66
|
||||
USE_PROCD=1
|
||||
|
||||
FLAG=/var/wakey_updated.flag
|
||||
|
||||
start_service() {
|
||||
[ -f "$FLAG" ] && return
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command /etc/ldlda_help/update_wakey.sh
|
||||
procd_set_param respawn 0 0 0
|
||||
@@ -13,11 +16,9 @@ start_service() {
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
: # one-shot
|
||||
: # no-op
|
||||
}
|
||||
|
||||
# Test manually:
|
||||
# chmod +x /etc/init.d/update_wakey
|
||||
# /etc/init.d/update_wakey start
|
||||
# Or enable on boot:
|
||||
# /etc/init.d/update_wakey enable
|
||||
post_service() {
|
||||
touch "$FLAG"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"thanks chatgpt"
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
root = Path(__file__).parent.parent
|
||||
static = root / "static" # change "assets" to your folder
|
||||
out_rs = root / "src" / "assets.rs"
|
||||
|
||||
|
||||
def sanitize(name: str) -> str:
|
||||
# Valid Rust identifiers: letters, digits, underscores; no starting digit
|
||||
out = []
|
||||
for c in name:
|
||||
if c.isalnum() or c == "_":
|
||||
out.append(c)
|
||||
else:
|
||||
out.append("_")
|
||||
s = "".join(out)
|
||||
if s and s[0].isdigit():
|
||||
s = "_" + s
|
||||
return s
|
||||
|
||||
|
||||
def indent(text: str, n: int) -> str:
|
||||
pad = " " * n
|
||||
return "\n".join(pad + line if line.strip() else line for line in text.splitlines())
|
||||
|
||||
|
||||
class RsAssetFile:
|
||||
def __init__(self, path: Path):
|
||||
self.path = path
|
||||
|
||||
def __str__(self):
|
||||
const_name = sanitize(self.path.name).upper()
|
||||
return (
|
||||
f"pub const {const_name}: &str = "
|
||||
f'include_str!("{self.path.relative_to(out_rs.parent, walk_up=True).as_posix()}");'
|
||||
)
|
||||
# specify walk_up to have .. in yo path
|
||||
|
||||
|
||||
class RsAssetModule:
|
||||
def __init__(self, folder: Path, body_only: bool = False):
|
||||
self.folder = folder
|
||||
self.full = not body_only
|
||||
|
||||
def __str__(self):
|
||||
files = [str(RsAssetFile(s)) for s in self.folder.iterdir() if s.is_file()]
|
||||
subs = [str(RsAssetModule(s)) for s in self.folder.iterdir() if s.is_dir()]
|
||||
|
||||
body = "\n".join(files + subs)
|
||||
return (
|
||||
f"pub mod {sanitize(self.folder.name).lower()} {{" * self.full
|
||||
+ f"\n{indent(body, 4*self.full)}\n"
|
||||
+ self.full * "}"
|
||||
)
|
||||
|
||||
|
||||
# generate
|
||||
rs_code = "// generated with ./scripts/map_static.py\n" + str(
|
||||
RsAssetModule(static, True)
|
||||
)
|
||||
out_rs.write_text(rs_code, encoding="utf-8")
|
||||
print(f"written to {out_rs}")
|
||||
@@ -45,6 +45,8 @@ if ($Publish) {
|
||||
$pubArgs = @('publish')
|
||||
if ($Registry) { $pubArgs += @('--registry', $Registry) }
|
||||
cargo @pubArgs
|
||||
|
||||
Write-Host ("published. ran cargo {0}" -f ($pubArgs -join " "))
|
||||
}
|
||||
catch {
|
||||
Write-Warning ("cargo publish failed: {0}" -f $_)
|
||||
@@ -63,4 +65,6 @@ if ($Tag -and $Version) {
|
||||
}
|
||||
git tag -f "v$Version"
|
||||
git push -f origin "v$Version"
|
||||
|
||||
Write-Host "Pushed tag: $Version."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user